aboutsummaryrefslogtreecommitdiffstats
path: root/fs/kernfs/inode.c
diff options
context:
space:
mode:
authorOndrej Mosnacek <omosnace@redhat.com>2019-02-22 09:57:16 -0500
committerPaul Moore <paul@paul-moore.com>2019-03-20 22:01:02 -0400
commitb230d5aba2d1a7b0636408889a75bf9eae6b8bc7 (patch)
tree57bacbcb8d8114c376cef0d23110a236af5e985a /fs/kernfs/inode.c
parent0ac6075a32fc05bc7fa025965914e8dcd448a668 (diff)
LSM: add new hook for kernfs node initialization
This patch introduces a new security hook that is intended for initializing the security data for newly created kernfs nodes, which provide a way of storing a non-default security context, but need to operate independently from mounts (and therefore may not have an associated inode at the moment of creation). The main motivation is to allow kernfs nodes to inherit the context of the parent under SELinux, similar to the behavior of security_inode_init_security(). Other LSMs may implement their own logic for handling the creation of new nodes. This patch also adds helper functions to <linux/kernfs.h> for getting/setting security xattrs of a kernfs node so that LSMs hooks are able to do their job. Other important attributes should be accessible direcly in the kernfs_node fields (in case there is need for more, then new helpers should be added to kernfs.h along with the patch that needs them). Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Acked-by: Casey Schaufler <casey@schaufler-ca.com> [PM: more manual merge fixes] Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'fs/kernfs/inode.c')
-rw-r--r--fs/kernfs/inode.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index a365088caa3c..673ef598d97d 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -288,12 +288,11 @@ int kernfs_iop_permission(struct inode *inode, int mask)
288 return generic_permission(inode, mask); 288 return generic_permission(inode, mask);
289} 289}
290 290
291static int kernfs_xattr_get(const struct xattr_handler *handler, 291static int kernfs_node_xattr_get(const struct xattr_handler *handler,
292 struct dentry *unused, struct inode *inode, 292 struct kernfs_node *kn, const char *suffix,
293 const char *suffix, void *value, size_t size) 293 void *value, size_t size)
294{ 294{
295 const char *name = xattr_full_name(handler, suffix); 295 const char *name = xattr_full_name(handler, suffix);
296 struct kernfs_node *kn = inode->i_private;
297 struct kernfs_iattrs *attrs; 296 struct kernfs_iattrs *attrs;
298 297
299 attrs = kernfs_iattrs_noalloc(kn); 298 attrs = kernfs_iattrs_noalloc(kn);
@@ -303,13 +302,11 @@ static int kernfs_xattr_get(const struct xattr_handler *handler,
303 return simple_xattr_get(&attrs->xattrs, name, value, size); 302 return simple_xattr_get(&attrs->xattrs, name, value, size);
304} 303}
305 304
306static int kernfs_xattr_set(const struct xattr_handler *handler, 305static int kernfs_node_xattr_set(const struct xattr_handler *handler,
307 struct dentry *unused, struct inode *inode, 306 struct kernfs_node *kn, const char *suffix,
308 const char *suffix, const void *value, 307 const void *value, size_t size, int flags)
309 size_t size, int flags)
310{ 308{
311 const char *name = xattr_full_name(handler, suffix); 309 const char *name = xattr_full_name(handler, suffix);
312 struct kernfs_node *kn = inode->i_private;
313 struct kernfs_iattrs *attrs; 310 struct kernfs_iattrs *attrs;
314 311
315 attrs = kernfs_iattrs(kn); 312 attrs = kernfs_iattrs(kn);
@@ -319,6 +316,25 @@ static int kernfs_xattr_set(const struct xattr_handler *handler,
319 return simple_xattr_set(&attrs->xattrs, name, value, size, flags); 316 return simple_xattr_set(&attrs->xattrs, name, value, size, flags);
320} 317}
321 318
319static int kernfs_xattr_get(const struct xattr_handler *handler,
320 struct dentry *unused, struct inode *inode,
321 const char *suffix, void *value, size_t size)
322{
323 struct kernfs_node *kn = inode->i_private;
324
325 return kernfs_node_xattr_get(handler, kn, suffix, value, size);
326}
327
328static int kernfs_xattr_set(const struct xattr_handler *handler,
329 struct dentry *unused, struct inode *inode,
330 const char *suffix, const void *value,
331 size_t size, int flags)
332{
333 struct kernfs_node *kn = inode->i_private;
334
335 return kernfs_node_xattr_set(handler, kn, suffix, value, size, flags);
336}
337
322static const struct xattr_handler kernfs_trusted_xattr_handler = { 338static const struct xattr_handler kernfs_trusted_xattr_handler = {
323 .prefix = XATTR_TRUSTED_PREFIX, 339 .prefix = XATTR_TRUSTED_PREFIX,
324 .get = kernfs_xattr_get, 340 .get = kernfs_xattr_get,
@@ -336,3 +352,17 @@ const struct xattr_handler *kernfs_xattr_handlers[] = {
336 &kernfs_security_xattr_handler, 352 &kernfs_security_xattr_handler,
337 NULL 353 NULL
338}; 354};
355
356int kernfs_security_xattr_get(struct kernfs_node *kn, const char *suffix,
357 void *value, size_t size)
358{
359 return kernfs_node_xattr_get(&kernfs_security_xattr_handler,
360 kn, suffix, value, size);
361}
362
363int kernfs_security_xattr_set(struct kernfs_node *kn, const char *suffix,
364 void *value, size_t size, int flags)
365{
366 return kernfs_node_xattr_set(&kernfs_security_xattr_handler,
367 kn, suffix, value, size, flags);
368}