security: Add a new hook: inode_touch_atime
Subsystems (2)
PATCH 1/1 security: Add a new hook: inode_touch_atime
Add a new LSM hook named inode_touch_atime which is needed to deny indirect update of extended file attributes (i.e. access time) which are not catched by the inode_setattr hook. By creating a new hook instead of calling inode_setattr, we avoid to simulate a useless struct iattr.
This hook allows to create read-only environments as with read-only mount points. It can also take care of anonymous inodes.
--- fs/inode.c | 5 ++++- include/linux/lsm_hooks.h | 8 ++++++++ include/linux/security.h | 8 ++++++++ security/security.c | 9 +++++++++ 4 files changed, 29 insertions(+), 1 deletion(-)
fs/inode.c +4 -1
@@ -1706,6 +1706,10 @@ void touch_atime(const struct path *path)if (!__atime_needs_update (path, inode, false))return ; + now =current_time (inode); +if (security_inode_touch_atime (path, &now)) +return ; +if (!sb_start_write_trylock (inode->i_sb))return ;
@@ -1720,7 +1724,6 @@ void touch_atime(const struct path *path)* We may also fail on filesystems that have the ability to make parts * of the fs read only, e.g. subvolumes in Btrfs. */ - now =current_time (inode);update_time (inode, &now,S_ATIME );__mnt_drop_write (mnt); skip_update:
include/linux/lsm_hooks.h +8 -0
@@ -428,6 +428,11 @@* security module does not know about attribute or a negative error code * to abort the copy up. Note that the caller is responsible for reading * and writing the xattrs as this hook is merely a filter. +* @inode_touch_atime: +* Check permission before updating access time. +* @path contains the path structure for the file. +* @ts contains the current time. +* Return 0 if permission is granted. * * Security hooks for file operations *
@@ -1458,6 +1463,8 @@ union security_list_options {void (*inode_getsecid)(struct inode *inode,u32 *secid);int (*inode_copy_up)(struct dentry *src,struct cred **new);int (*inode_copy_up_xattr)(const char *name); +int (*inode_touch_atime)(const struct path *path, +const struct timespec *ts);int (*file_permission)(struct file *file,int mask);int (*file_alloc_security)(struct file *file);
@@ -1731,6 +1738,7 @@ struct security_hook_heads {struct list_head inode_getsecid;struct list_head inode_copy_up;struct list_head inode_copy_up_xattr; +struct list_head inode_touch_atime;struct list_head file_permission;struct list_head file_alloc_security;struct list_head file_free_security;
include/linux/security.h +8 -0
@@ -30,6 +30,7 @@#include <linux/string.h> #include <linux/mm.h> #include <linux/fs.h> +#include <linux/time.h> struct linux_binprm ;struct cred ;
@@ -288,6 +289,7 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffervoid security_inode_getsecid (struct inode *inode,u32 *secid);int security_inode_copy_up (struct dentry *src,struct cred **new);int security_inode_copy_up_xattr (const char *name); +int security_inode_touch_atime (const struct path *path,const struct timespec *ts);int security_file_permission (struct file *file,int mask);int security_file_alloc (struct file *file);void security_file_free (struct file *file);
@@ -781,6 +783,12 @@ static inline int security_inode_copy_up_xattr(const char *name)return -EOPNOTSUPP ; } +static inline int security_inode_touch_atime (const struct path *path,const +struct timespec *ts) +{ +return 0 ; +} +static inline int security_file_permission (struct file *file,int mask) {return 0 ;
security/security.c +9 -0
@@ -769,6 +769,13 @@ int security_inode_copy_up_xattr(const char *name) }EXPORT_SYMBOL (security_inode_copy_up_xattr); +int security_inode_touch_atime (const struct path *path, +const struct timespec *ts) +{ +return call_int_hook (inode_touch_atime,0 , path, ts); +} +EXPORT_SYMBOL (security_inode_touch_atime); +int security_file_permission (struct file *file,int mask) {int ret;
@@ -1711,6 +1718,8 @@ struct security_hook_heads security_hook_heads = { LIST_HEAD_INIT(security_hook_heads.inode_copy_up), .inode_copy_up_xattr = LIST_HEAD_INIT(security_hook_heads.inode_copy_up_xattr), + .inode_touch_atime = + LIST_HEAD_INIT(security_hook_heads.inode_touch_atime), .file_permission = LIST_HEAD_INIT(security_hook_heads.file_permission), .file_alloc_security =
Signature · 1 line
2.11.0
Quoted 7 lines · Mickaël Salaün
Add a new LSM hook named
inode_touch_atimewhich is needed to deny indirect update of extended file attributes (i.e. access time) which are not catched by theinode_setattrhook. By creating a new hook instead of callinginode_setattr, we avoid to simulate a useless struct iattr.This hook allows to create read-only environments as with read-only mount points. It can also take care of anonymous inodes.
What security module would use this?
Quoted 139 lines
Signed-off-by Mickaël Salaün <[email protected]>Cc Alexander Viro <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Casey Schaufler <[email protected]>Cc Dmitry Kasatkin <[email protected]>Cc Eric Paris <[email protected]>Cc James Morris <[email protected]>Cc John Johansen <[email protected]>Cc Kees Cook <[email protected]>Cc Kentaro Takeda <[email protected]>Cc Mimi Zohar <[email protected]>Cc Paul Moore <[email protected]>Cc Serge E. Hallyn <[email protected]>Cc Stephen Smalley <[email protected]>Cc Tetsuo Handa <[email protected]>--- fs/inode.c | 5 ++++- include/linux/lsm_hooks.h | 8 ++++++++ include/linux/security.h | 8 ++++++++ security/security.c | 9 +++++++++ 4 files changed, 29 insertions(+), 1 deletion(-)fs/inode.c +4
-1@@ -1706,6 +1706,10 @@ void touch_atime(const struct path *path)if (!__atime_needs_update (path, inode, false))return ; + now =current_time (inode); +if (security_inode_touch_atime (path, &now)) +return ; +if (!sb_start_write_trylock (inode->i_sb))return ;@@ -1720,7 +1724,6 @@ void touch_atime(const struct path *path)* We may also fail on filesystems that have the ability to make parts * of the fs read only, e.g. subvolumes in Btrfs. */ - now =current_time (inode);update_time (inode, &now,S_ATIME );__mnt_drop_write (mnt); skip_update:include/linux/lsm_hooks.h +8
-0@@ -428,6 +428,11 @@* security module does not know about attribute or a negative error code * to abort the copy up. Note that the caller is responsible for reading * and writing the xattrs as this hook is merely a filter. +* @inode_touch_atime: +* Check permission before updating access time. +* @path contains the path structure for the file. +* @ts contains the current time. +* Return 0 if permission is granted. * * Security hooks for file operations * @@ -1458,6 +1463,8 @@ union security_list_options {void (*inode_getsecid)(struct inode *inode,u32 *secid);int (*inode_copy_up)(struct dentry *src,struct cred **new);int (*inode_copy_up_xattr)(const char *name); +int (*inode_touch_atime)(const struct path *path, +const struct timespec *ts);int (*file_permission)(struct file *file,int mask);int (*file_alloc_security)(struct file *file);@@ -1731,6 +1738,7 @@ struct security_hook_heads {struct list_head inode_getsecid;struct list_head inode_copy_up;struct list_head inode_copy_up_xattr; +struct list_head inode_touch_atime;struct list_head file_permission;struct list_head file_alloc_security;struct list_head file_free_security;include/linux/security.h +8
-0@@ -30,6 +30,7 @@#include <linux/string.h> #include <linux/mm.h> #include <linux/fs.h> +#include <linux/time.h> struct linux_binprm ;struct cred ;@@ -288,6 +289,7 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffervoid security_inode_getsecid (struct inode *inode,u32 *secid);int security_inode_copy_up (struct dentry *src,struct cred **new);int security_inode_copy_up_xattr (const char *name); +int security_inode_touch_atime (const struct path *path,const struct timespec *ts);int security_file_permission (struct file *file,int mask);int security_file_alloc (struct file *file);void security_file_free (struct file *file);@@ -781,6 +783,12 @@ static inline int security_inode_copy_up_xattr(const char *name)return -EOPNOTSUPP ; } +static inline int security_inode_touch_atime (const struct path *path,const +struct timespec *ts) +{ +return 0 ; +} +static inline int security_file_permission (struct file *file,int mask) {return 0 ;security/security.c +9
-0@@ -769,6 +769,13 @@ int security_inode_copy_up_xattr(const char *name) }EXPORT_SYMBOL (security_inode_copy_up_xattr); +int security_inode_touch_atime (const struct path *path, +const struct timespec *ts) +{ +return call_int_hook (inode_touch_atime,0 , path, ts); +} +EXPORT_SYMBOL (security_inode_touch_atime); +int security_file_permission (struct file *file,int mask) {int ret;@@ -1711,6 +1718,8 @@ struct security_hook_heads security_hook_heads = { LIST_HEAD_INIT(security_hook_heads.inode_copy_up), .inode_copy_up_xattr = LIST_HEAD_INIT(security_hook_heads.inode_copy_up_xattr), + .inode_touch_atime = + LIST_HEAD_INIT(security_hook_heads.inode_touch_atime), .file_permission = LIST_HEAD_INIT(security_hook_heads.file_permission), .file_alloc_security =
Quoted 10 lines · Casey Schaufler
Quoted 7 lines · Mickaël Salaün
Add a new LSM hook named
inode_touch_atimewhich is needed to deny indirect update of extended file attributes (i.e. access time) which are not catched by theinode_setattrhook. By creating a new hook instead of callinginode_setattr, we avoid to simulate a useless struct iattr.This hook allows to create read-only environments as with read-only mount points. It can also take care of anonymous inodes.
What security module would use this?
SELinux should be interested. This is useful to create sandboxes so other LSM may be interested too
I'm working on a new LSM and I would like this kind of hook to create a real read-only environment.
Regards,
Mickaël
Quoted 7 lines · Mickaël Salaün
Quoted 6 lines · Casey Schaufler
Quoted 5 lines · Mickaël Salaün
Add a new LSM hook named
inode_touch_atimewhich is needed to deny indirect update of extended file attributes (i.e. access time) which are not catched by theinode_setattrhook. By creating a new hook instead of callinginode_setattr, we avoid to simulate a useless struct iattr.
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
This hook allows to create read-only environments as with read-only mount points. It can also take care of anonymous inodes.
What security module would use this?
SELinux should be interested. This is useful to create sandboxes so other LSM may be interested too
You'll have to provide more information than that. I don't see how this hook would help there.
Quoted 2 lines
I'm working on a new LSM and I would like this kind of hook to create a real read-only environment.
I'm curious about how this hook would be used to do that. And about your module. You probably want to propose the hook(s) you want to add at the same time you propose your module. I am looking forward to reviewing it.
Quoted 2 lines
Regards,
Mickaël
Al Viro
maintainerQuoted 5 lines · Micka�l Sala�n
SELinux should be interested. This is useful to create sandboxes so other LSM may be interested too
I'm working on a new LSM and I would like this kind of hook to create a real read-only environment.
What the...? Have you noticed
if (!sb_start_write_trylock(inode->i_sb))
return;
if (__mnt_want_write(mnt) != 0)
goto skip_update;in touch_atime()? Just mount them read-only in your sandbox (on either level - both per-mountpoint and per-fs r/o will do) and be done with that; why bother with LSM when regular tools would suffice?
Quoted 9 lines · Al Viro
Quoted 5 lines · Mickaël Salaün
SELinux should be interested. This is useful to create sandboxes so other LSM may be interested too
I'm working on a new LSM and I would like this kind of hook to create a real read-only environment.
What the...? Have you noticed
Quoted 9 lines
if (!sb_start_write_trylock(inode->i_sb)) return; if (__mnt_want_write(mnt) != 0) goto skip_update;in
touch_atime()? Just mount them read-only in your sandbox (on either level - both per-mountpoint and per-fs r/o will do) and be done with that; why bother with LSM when regular tools would suffice?
Of course a read-only mount point can do the trick (except for anonymous inodes). However, a security policy (e.g. for SELinux) should not (and can't always) rely on mount options. For example, a security policy can come from a distro but they may not want to tie mount options with this policy. We may also not want a sandbox to being able to change mount options (even with user namespaces).
Being able to write (meta-)data, whereas a security policy said that it's not allowed, seems like a flaw in this policy. Moreover, modifying access time is an easy way to create cover-channels without any LSM being able to notice it.
Quoted 11 lines · Micka�l Sala�n
Of course a read-only mount point can do the trick (except for anonymous inodes). However, a security policy (e.g. for SELinux) should not (and can't always) rely on mount options. For example, a security policy can come from a distro but they may not want to tie mount options with this policy. We may also not want a sandbox to being able to change mount options (even with user namespaces).
Being able to write (meta-)data, whereas a security policy said that it's not allowed, seems like a flaw in this policy. Moreover, modifying access time is an easy way to create cover-channels without any LSM being able to notice it.
A security policy must not mess with the readonly state of a file system or mount, period. You're overstepping your boundaries.
Quoted 7 lines · Micka�l Sala�n
Add a new LSM hook named
inode_touch_atimewhich is needed to deny indirect update of extended file attributes (i.e. access time) which are not catched by theinode_setattrhook. By creating a new hook instead of callinginode_setattr, we avoid to simulate a useless struct iattr.This hook allows to create read-only environments as with read-only mount points. It can also take care of anonymous inodes.
And LSM has absolutely no business doing that - that's what the mount code is for.