ima: only call integrity_kernel_read to calc file hash
Subsystems (18)
cover ima: only call integrity_kernel_read to calc file hash
The integrity_kernel_read() function was originally introduced to read a file and calculate the file hash by-passing any security checks. Support subsequently was added allowing the kernel to read a file containing a signed x509 certificate and load it onto either the IMA or EVM keyring.
This patch set replaces the call to integrity_kernel_read() with the common kernel_read_file_from_path() function, for reading and loading an x509 certificate onto either the IMA or EVM keyring. The remaining calls to integrity_kernel_read() calculate a file hash, by calling the new integrity_read file operation method.
Mimi
Christoph Hellwig (2):
integrity: replace call to integrity_read_file with kernel version
ima: use fs method to read integrity data
Mimi Zohar (1):
vfs: constify path argument to kernel_read_file_from_path
fs/btrfs/file.c | 1 + fs/efivarfs/file.c | 1 + fs/exec.c | 2 +- fs/ext2/file.c | 17 ++++++++++ fs/ext4/file.c | 20 ++++++++++++ fs/f2fs/file.c | 1 + fs/jffs2/file.c | 1 + fs/jfs/file.c | 1 + fs/nilfs2/file.c | 1 + fs/ramfs/file-mmu.c | 1 + fs/ramfs/file-nommu.c | 1 + fs/ubifs/file.c | 1 + fs/xfs/xfs_file.c | 21 ++++++++++++ include/linux/fs.h | 4 ++- mm/shmem.c | 1 + security/integrity/digsig.c | 14 +++++--- security/integrity/iint.c | 69 ++++++++------------------------------- security/integrity/ima/ima_main.c | 4 +++ security/integrity/integrity.h | 2 -- sound/oss/sound_firmware.h | 2 +- 20 files changed, 100 insertions(+), 65 deletions(-)
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/3 vfs: constify path argument to kernel_read_file_from_path
This patch constifies the path argument to kernel_read_file_from_path.
--- fs/exec.c | 2 +- include/linux/fs.h | 2 +- sound/oss/sound_firmware.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/exec.c +1 -1
@@ -974,7 +974,7 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size, }EXPORT_SYMBOL_GPL (kernel_read_file); -int kernel_read_file_from_path (char *path,void **buf,loff_t *size, +int kernel_read_file_from_path (const char *path,void **buf,loff_t *size,loff_t max_size,enum kernel_read_file_id id) {struct file *file;
include/linux/fs.h +1 -1
@@ -2775,7 +2775,7 @@ static inline const char *kernel_read_file_id_str(enum kernel_read_file_id id)extern int kernel_read (struct file *,loff_t ,char *,unsigned long );extern int kernel_read_file (struct file *,void **,loff_t *,loff_t ,enum kernel_read_file_id ); -extern int kernel_read_file_from_path (char *,void **,loff_t *,loff_t , +extern int kernel_read_file_from_path (const char *,void **,loff_t *,loff_t ,enum kernel_read_file_id );extern int kernel_read_file_from_fd (int ,void **,loff_t *,loff_t ,enum kernel_read_file_id );
sound/oss/sound_firmware.h +1 -1
@@ -21,7 +21,7 @@ static inline int mod_firmware_load(const char *fn, char **fp)loff_t size;int err; - err =kernel_read_file_from_path ((char *)fn, (void **)fp, &size, + err =kernel_read_file_from_path (fn, (void **)fp, &size,131072 ,READING_FIRMWARE );if (err <0 )return 0 ;
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info@ http://vger.kernel.org/majordomo-info.html
PATCH 2/3 integrity: replace call to integrity_read_file with kernel version
In reply to Mimi ZoharFrom: Christoph Hellwig <[email protected]>
The CONFIG_IMA_LOAD_X509 and CONFIG_EVM_LOAD_X509 options permit loading x509 signed certificates onto the trusted keyrings without verifying the x509 certificate file's signature.
This patch replaces the call to the integrity_read_file() specific function with the common kernel_read_file_from_path() function. To avoid verifying the file signature, this patch defines READING_X509_CERTFICATE.
---
Changelog:
- rewrote patch description
- fixed parameters to kernel_read_file_from_path() and key_create_or_update()
- defined READING_X509_CERTIFICATE, a new __kernel_read_file enumeration
- removed constify change
--- include/linux/fs.h | 1 + security/integrity/digsig.c | 14 +++++++---- security/integrity/iint.c | 49 --------------------------------------- security/integrity/ima/ima_main.c | 4 ++++ security/integrity/integrity.h | 2 -- 5 files changed, 14 insertions(+), 56 deletions(-)
include/linux/fs.h +1 -0
@@ -2751,6 +2751,7 @@ extern int do_pipe_flags(int *, int); id(KEXEC_IMAGE, kexec-image) \ id(KEXEC_INITRAMFS, kexec-initramfs) \ id(POLICY, security-policy) \ + id(X509_CERTIFICATE, x509-certificate) \ id(MAX_ID, ) #define __fid_enumify(ENUM, dummy) READING_ ## ENUM,
security/integrity/digsig.c +9 -5
@@ -112,21 +112,25 @@ int __init integrity_init_keyring(const unsigned int id)int __init integrity_load_x509 (const unsigned int id,const char *path) {key_ref_t key; -char *data; +void *data; +loff_t size;int rc;if (!keyring[id])return -EINVAL ; - rc =integrity_read_file (path, &data); -if (rc <0 ) + rc =kernel_read_file_from_path (path, &data, &size,0 , +READING_X509_CERTIFICATE ); +if (rc <0 ) { +pr_err ("Unable to open file: %s (%d)" , path, rc);return rc; + } key =key_create_or_update (make_key_ref (keyring[id],1 ),"asymmetric" ,NULL , data, - rc, + size, ((KEY_POS_ALL & ~KEY_POS_SETATTR ) |KEY_USR_VIEW |KEY_USR_READ ),KEY_ALLOC_NOT_IN_QUOTA );
@@ -139,6 +143,6 @@ int __init integrity_load_x509(const unsigned int id, const char *path) key_ref_to_ptr(key)->description, path);key_ref_put (key); } -kfree (data); +vfree (data);return 0 ; }
security/integrity/iint.c +0 -49
55 lines not on this page · raw message
security/integrity/ima/ima_main.c +4 -0
@@ -413,6 +413,10 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size,if (!file && read_id ==READING_MODULE )/* MODULE_SIG_FORCE enabled */ return 0 ; +/* permit signed certs */ +if (!file && read_id ==READING_X509_CERTIFICATE ) +return 0 ; +if (!file || !buf || size ==0 ) {/* should never happen */ if (ima_appraise &IMA_APPRAISE_ENFORCE )return -EACCES ;
security/integrity/integrity.h +0 -2
@@ -120,8 +120,6 @@ struct integrity_iint_cache *integrity_iint_find(struct inode *inode);int integrity_kernel_read (struct file *file,loff_t offset,void *addr,unsigned long count); -int __init integrity_read_file (const char *path,char **data); -#define INTEGRITY_KEYRING_EVM 0#define INTEGRITY_KEYRING_IMA 1#define INTEGRITY_KEYRING_MODULE 2
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 ima: use fs method to read integrity data
In reply to Mimi ZoharFrom: Christoph Hellwig <[email protected]>
Add a new ->integrity_read file operation to read data for integrity hash collection. This is defined to be equivalent to ->read_iter, except that it will be called with the i_rwsem held exclusively.
(Based on Christoph's original patch.)
--- fs/btrfs/file.c | 1 + fs/efivarfs/file.c | 1 + fs/ext2/file.c | 17 +++++++++++++++++ fs/ext4/file.c | 20 ++++++++++++++++++++ fs/f2fs/file.c | 1 + fs/jffs2/file.c | 1 + fs/jfs/file.c | 1 + fs/nilfs2/file.c | 1 + fs/ramfs/file-mmu.c | 1 + fs/ramfs/file-nommu.c | 1 + fs/ubifs/file.c | 1 + fs/xfs/xfs_file.c | 21 +++++++++++++++++++++ include/linux/fs.h | 1 + mm/shmem.c | 1 + security/integrity/iint.c | 20 ++++++++++++++------ 15 files changed, 83 insertions(+), 6 deletions(-)
fs/btrfs/file.c +1 -0
@@ -3125,6 +3125,7 @@ const struct file_operations btrfs_file_operations = {#endif .clone_file_range = btrfs_clone_file_range, .dedupe_file_range = btrfs_dedupe_file_range, + .integrity_read = generic_file_read_iter, };void btrfs_auto_defrag_exit (void )
fs/efivarfs/file.c +1 -0
@@ -179,4 +179,5 @@ const struct file_operations efivarfs_file_operations = { .write = efivarfs_file_write, .llseek = no_llseek, .unlocked_ioctl = efivarfs_file_ioctl, + .integrity_read = efivarfs_file_read_iter, };
fs/ext2/file.c +17 -0
@@ -192,6 +192,22 @@ static ssize_t ext2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return generic_file_read_iter (iocb, to); } +static ssize_t ext2_file_integrity_read_iter (struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +lockdep_assert_held (&inode->i_rwsem); +#ifdef CONFIG_FS_DAX +if (!iov_iter_count (to)) +return 0 ;/* skip atime */ + +if (IS_DAX (iocb->ki_filp->f_mapping->host)) +return dax_iomap_rw (iocb, to, &ext2_iomap_ops); +#endif +return generic_file_read_iter (iocb, to); +} +static ssize_t ext2_file_write_iter (struct kiocb *iocb,struct iov_iter *from) {#ifdef CONFIG_FS_DAX
@@ -216,6 +232,7 @@ const struct file_operations ext2_file_operations = { .get_unmapped_area = thp_get_unmapped_area, .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, + .integrity_read = ext2_file_integrity_read_iter, };const struct inode_operations ext2_file_inode_operations = {
fs/ext4/file.c +20 -0
@@ -74,6 +74,25 @@ static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return generic_file_read_iter (iocb, to); } +static ssize_t ext4_file_integrity_read_iter (struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +lockdep_assert_held (&inode->i_rwsem); +if (unlikely (ext4_forced_shutdown (EXT4_SB (inode->i_sb)))) +return -EIO ; + +if (!iov_iter_count (to)) +return 0 ;/* skip atime */ + +#ifdef CONFIG_FS_DAX +if (IS_DAX (inode)) +return dax_iomap_rw (iocb, to, &ext4_iomap_ops); +#endif +return generic_file_read_iter (iocb, to); +} +/* * Called when an inode is released. Note that this is different * from ext4_file_open: open gets called at every open, but release
@@ -747,6 +766,7 @@ const struct file_operations ext4_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ext4_fallocate, + .integrity_read = ext4_file_integrity_read_iter, };const struct inode_operations ext4_file_inode_operations = {
fs/f2fs/file.c +1 -0
@@ -2514,4 +2514,5 @@ const struct file_operations f2fs_file_operations = {#endif .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, + .integrity_read = generic_file_read_iter, };
fs/jffs2/file.c +1 -0
@@ -57,6 +57,7 @@ const struct file_operations jffs2_file_operations = .mmap = generic_file_readonly_mmap, .fsync = jffs2_fsync, .splice_read = generic_file_splice_read, + .integrity_read = generic_file_read_iter, };/* jffs2_file_inode_operations */
fs/jfs/file.c +1 -0
@@ -162,4 +162,5 @@ const struct file_operations jfs_file_operations = {#ifdef CONFIG_COMPAT .compat_ioctl = jfs_compat_ioctl, #endif + .integrity_read = generic_file_read_iter, };
fs/nilfs2/file.c +1 -0
@@ -150,6 +150,7 @@ const struct file_operations nilfs_file_operations = {/* .release = nilfs_release_file, */ .fsync = nilfs_sync_file, .splice_read = generic_file_splice_read, + .integrity_read = generic_file_read_iter, };const struct inode_operations nilfs_file_inode_operations = {
fs/ramfs/file-mmu.c +1 -0
@@ -47,6 +47,7 @@ const struct file_operations ramfs_file_operations = { .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, .get_unmapped_area = ramfs_mmu_get_unmapped_area, + .integrity_read = generic_file_read_iter, };const struct inode_operations ramfs_file_inode_operations = {
fs/ramfs/file-nommu.c +1 -0
@@ -50,6 +50,7 @@ const struct file_operations ramfs_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, + .integrity_read = generic_file_read_iter, };const struct inode_operations ramfs_file_inode_operations = {
fs/ubifs/file.c +1 -0
@@ -1747,4 +1747,5 @@ const struct file_operations ubifs_file_operations = {#ifdef CONFIG_COMPAT .compat_ioctl = ubifs_compat_ioctl, #endif + .integrity_read = generic_file_read_iter, };
fs/xfs/xfs_file.c +21 -0
@@ -292,6 +292,26 @@ xfs_file_read_iter(return ret; } +static ssize_t +xfs_integrity_read ( +struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +struct xfs_mount *mp =XFS_I (inode)->i_mount; + +lockdep_assert_held (&inode->i_rwsem); + +XFS_STATS_INC (mp, xs_read_calls); + +if (XFS_FORCED_SHUTDOWN (mp)) +return -EIO ; + +if (IS_DAX (inode)) +return dax_iomap_rw (iocb, to, &xfs_iomap_ops); +return generic_file_read_iter (iocb, to); +} +/* * Zero any on disk space between the current EOF and the new, larger EOF. *
@@ -1175,6 +1195,7 @@ const struct file_operations xfs_file_operations = { .fallocate = xfs_file_fallocate, .clone_file_range = xfs_file_clone_range, .dedupe_file_range = xfs_file_dedupe_range, + .integrity_read = xfs_integrity_read, };const struct file_operations xfs_dir_file_operations = {
include/linux/fs.h +1 -0
@@ -1699,6 +1699,7 @@ struct file_operations { u64);ssize_t (*dedupe_file_range)(struct file *,u64 ,u64 ,struct file *,u64 ); +ssize_t (*integrity_read)(struct kiocb *,struct iov_iter *); } __randomize_layout;struct inode_operations {
mm/shmem.c +1 -0
@@ -3849,6 +3849,7 @@ static const struct file_operations shmem_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = shmem_fallocate, + .integrity_read = shmem_file_read_iter,#endif };
security/integrity/iint.c +14 -6
@@ -21,6 +21,7 @@#include <linux/rbtree.h> #include <linux/file.h> #include <linux/uaccess.h> +#include <linux/uio.h> #include "integrity.h" static struct rb_root integrity_iint_tree =RB_ROOT ;
@@ -184,18 +185,25 @@ security_initcall(integrity_iintcache_init);int integrity_kernel_read (struct file *file,loff_t offset,void *addr,unsigned long count) { -mm_segment_t old_fs; -char __user *buf = (char __user *)addr; +struct inode *inode =file_inode (file); +struct kvec iov = { .iov_base = addr, .iov_len = count }; +struct kiocb kiocb; +struct iov_iter iter;ssize_t ret; +lockdep_assert_held (&inode->i_rwsem); +if (!(file->f_mode &FMODE_READ ))return -EBADF ; +if (!file->f_op->integrity_read) +return -EBADF ; - old_fs =get_fs (); -set_fs (get_ds ()); - ret =__vfs_read (file, buf, count, &offset); -set_fs (old_fs); +init_sync_kiocb (&kiocb, file); + kiocb.ki_pos = offset; +iov_iter_kvec (&iter,READ |ITER_KVEC , &iov,1 , count); + ret = file->f_op->integrity_read (&kiocb, &iter); +BUG_ON (ret == -EIOCBQUEUED );return ret; }
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data
In reply to a message not in the archiveQuoted 6 lines · Linus Torvalds
This is still wrong.
(a) there is no explanation for why we need that exclusive lock in the first place
Why should a read need exclusive access? You'd think shared is sufficient.
True, reading a file shouldn't require an exclusive lock. ?The exclusive lock is taken to prevent the file from changing while the file hash is being calculated.
Quoted 1 line
But regardless, it needs *explanation*.
Agreed. ?A fuller explanation was included in the cover letter that should have also been included in the patch description. ?The following is taken from the cover letter:
With the introduction of IMA-appraisal and the need to write file hashes as security xattrs, IMA needed to take the global i_mutex lock.??process_measurement() took the iint->mutex first and then the i_mutex, while setxattr, chmod and chown took the locks in reverse order.??To resolve this potential deadlock, the iint->mutex was removed.
Some filesystems have recently replaced their filesystem dependent lock with the global i_rwsem (formerly the i_mutex) to read a file. As a result, when IMA attempts to calculate the file hash, reading the file attempts to take the i_rwsem again.
To resolve this locking problem, this patch set defines a new ->integrity_read file operation method.
(Fixes: Commit 6552321831dc "xfs: remove i_iolock and use i_rwsem in the VFS inode instead")
Mimi
Quoted 346 lines
(b) the lockdep test isn't for the exclusive lock that the code comment says it is
So no, this needs more work.
?
?????Linus
?Quoted 335 lines · Mimi Zohar
From: Christoph Hellwig <[email protected]>
Add a new ->integrity_read file operation to read data for integrity hash collection. This is defined to be equivalent to ->read_iter, except that it will be called with the
i_rwsemheld exclusively.(Based on Christoph's original patch.)
Signed-off-by Christoph Hellwig <[email protected]>Cc Matthew Garrett <[email protected]>Cc Jan Kara <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Andreas Dilger <[email protected]>Cc Jaegeuk Kim <[email protected]>Cc Chao Yu <[email protected]>Cc Steven Whitehouse <[email protected]>Cc Bob Peterson <[email protected]>Cc David Woodhouse <[email protected]>Cc Dave Kleikamp <[email protected]>Cc Ryusuke Konishi <[email protected]>Cc Mark Fasheh <[email protected]>Cc Joel Becker <[email protected]>Cc Richard Weinberger <[email protected]>Cc "Darrick J. Wong" <[email protected]>Cc Hugh Dickins <[email protected]>Cc Chris Mason <[email protected]>Signed-off-by Mimi Zohar <[email protected]>Reviewed-by Jan Kara <[email protected]>Reviewed-by Dmitry Kasatkin <[email protected]>--- fs/btrfs/file.c | 1 + fs/efivarfs/file.c | 1 + fs/ext2/file.c | 17 +++++++++++++++++ fs/ext4/file.c | 20 ++++++++++++++++++++ fs/f2fs/file.c | 1 + fs/jffs2/file.c | 1 + fs/jfs/file.c | 1 + fs/nilfs2/file.c | 1 + fs/ramfs/file-mmu.c | 1 + fs/ramfs/file-nommu.c | 1 + fs/ubifs/file.c | 1 + fs/xfs/xfs_file.c | 21 +++++++++++++++++++++ include/linux/fs.h | 1 + mm/shmem.c | 1 + security/integrity/iint.c | 20 ++++++++++++++------ 15 files changed, 83 insertions(+), 6 deletions(-)fs/btrfs/file.c +1
-0@@ -3125,6 +3125,7 @@ const struct file_operations btrfs_file_operations = {#endif .clone_file_range = btrfs_clone_file_range, .dedupe_file_range = btrfs_dedupe_file_range, + .integrity_read = generic_file_read_iter, };void
btrfs_auto_defrag_exit(void)fs/efivarfs/file.c +1
-0@@ -179,4 +179,5 @@ const struct file_operations efivarfs_file_operations = { .write = efivarfs_file_write, .llseek = no_llseek, .unlocked_ioctl = efivarfs_file_ioctl, + .integrity_read = efivarfs_file_read_iter,};
fs/ext2/file.c +16
-0@@ -192,6 +192,22 @@ static ssize_t ext2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return generic_file_read_iter (iocb, to); } +static ssize_t ext2_file_integrity_read_iter (struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +lockdep_assert_held (&inode->i_rwsem); +#ifdef CONFIG_FS_DAX +if (!iov_iter_count (to)) +return 0 ;/* skip atime */ + +if (IS_DAX (iocb->ki_filp->f_mapping->host)) +return dax_iomap_rw (iocb, to, &ext2_iomap_ops); +#endif +return generic_file_read_iter (iocb, to); +} +static ssize_t ext2_file_write_iter (struct kiocb *iocb,struct iov_iter *from){
#ifdefCONFIG_FS_DAXfs/ext2/file.c +1
-0@@ -216,6 +232,7 @@ const struct file_operations ext2_file_operations = { .get_unmapped_area = thp_get_unmapped_area, .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, + .integrity_read = ext2_file_integrity_read_iter, };const struct inode_operations ext2_file_inode_operations = {fs/ext4/file.c +19
-0@@ -74,6 +74,25 @@ static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return generic_file_read_iter (iocb, to); } +static ssize_t ext4_file_integrity_read_iter (struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +lockdep_assert_held (&inode->i_rwsem); +if (unlikely (ext4_forced_shutdown (EXT4_SB (inode->i_sb)))) +return -EIO ; + +if (!iov_iter_count (to)) +return 0 ;/* skip atime */ + +#ifdef CONFIG_FS_DAX +if (IS_DAX (inode)) +return dax_iomap_rw (iocb, to, &ext4_iomap_ops); +#endif +return generic_file_read_iter (iocb, to); +} +/* * Called when an inode is released. Note that this is different * from
ext4_file_open: open gets called at every open, but releasefs/ext4/file.c +1
-0@@ -747,6 +766,7 @@ const struct file_operations ext4_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ext4_fallocate, + .integrity_read = ext4_file_integrity_read_iter, };const struct inode_operations ext4_file_inode_operations = {fs/f2fs/file.c +1
-0@@ -2514,4 +2514,5 @@ const struct file_operations f2fs_file_operations = {#endif .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, + .integrity_read = generic_file_read_iter, };fs/jffs2/file.c +1
-0@@ -57,6 +57,7 @@ const struct file_operations jffs2_file_operations = .mmap = generic_file_readonly_mmap, .fsync = jffs2_fsync, .splice_read = generic_file_splice_read, + .integrity_read = generic_file_read_iter, };/* jffs2_file_inode_operations */ fs/jfs/file.c +1
-0@@ -162,4 +162,5 @@ const struct file_operations jfs_file_operations = {#ifdef CONFIG_COMPAT .compat_ioctl = jfs_compat_ioctl, #endif + .integrity_read = generic_file_read_iter, };fs/nilfs2/file.c +1
-0@@ -150,6 +150,7 @@ const struct file_operations nilfs_file_operations = {/* .release = nilfs_release_file, */ .fsync = nilfs_sync_file, .splice_read = generic_file_splice_read, + .integrity_read = generic_file_read_iter, };const struct inode_operations nilfs_file_inode_operations = {fs/ramfs/file-mmu.c +1
-0@@ -47,6 +47,7 @@ const struct file_operations ramfs_file_operations = { .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, .get_unmapped_area = ramfs_mmu_get_unmapped_area, + .integrity_read = generic_file_read_iter, };const struct inode_operations ramfs_file_inode_operations = {fs/ramfs/file-nommu.c +1
-0@@ -50,6 +50,7 @@ const struct file_operations ramfs_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, + .integrity_read = generic_file_read_iter, };const struct inode_operations ramfs_file_inode_operations = {fs/ubifs/file.c +1
-0@@ -1747,4 +1747,5 @@ const struct file_operations ubifs_file_operations = { #ifdef CONFIG_COMPAT .compat_ioctl = ubifs_compat_ioctl, #endif + .integrity_read = generic_file_read_iter,};
fs/xfs/xfs_file.c +21
-0@@ -292,6 +292,26 @@ xfs_file_read_iter(return ret; } +static ssize_t +xfs_integrity_read ( +struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +struct xfs_mount *mp =XFS_I (inode)->i_mount; + +lockdep_assert_held (&inode->i_rwsem); + +XFS_STATS_INC (mp, xs_read_calls); + +if (XFS_FORCED_SHUTDOWN (mp)) +return -EIO ; + +if (IS_DAX (inode)) +return dax_iomap_rw (iocb, to, &xfs_iomap_ops); +return generic_file_read_iter (iocb, to); +} +/* * Zero any on disk space between the current EOF and the new, larger EOF. * @@ -1175,6 +1195,7 @@ const struct file_operations xfs_file_operations = { .fallocate = xfs_file_fallocate, .clone_file_range = xfs_file_clone_range, .dedupe_file_range = xfs_file_dedupe_range, + .integrity_read = xfs_integrity_read, };const struct file_operations xfs_dir_file_operations = {include/linux/fs.h +1
-0@@ -1699,6 +1699,7 @@ struct file_operations { u64);ssize_t (*dedupe_file_range)(struct file *,u64 ,u64 ,struct file *,u64 ); +ssize_t (*integrity_read)(struct kiocb *,struct iov_iter *); } __randomize_layout;struct
inode_operations{mm/shmem.c +1
-0@@ -3849,6 +3849,7 @@ static const struct file_operations shmem_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = shmem_fallocate, + .integrity_read = shmem_file_read_iter, #endif };security/integrity/iint.c +14
-6@@ -21,6 +21,7 @@#include <linux/rbtree.h> #include <linux/file.h> #include <linux/uaccess.h> +#include <linux/uio.h> #include "integrity.h" static struct rb_root integrity_iint_tree =RB_ROOT ;@@ -184,18 +185,25 @@ security_initcall(integrity_iintcache_init);int integrity_kernel_read (struct file *file,loff_t offset,void *addr,unsigned long count) { -mm_segment_t old_fs; -char __user *buf = (char __user *)addr; +struct inode *inode =file_inode (file); +struct kvec iov = { .iov_base = addr, .iov_len = count }; +struct kiocb kiocb; +struct iov_iter iter;ssize_t ret; +lockdep_assert_held (&inode->i_rwsem); +if (!(file->f_mode &FMODE_READ ))return -EBADF ; +if (!file->f_op->integrity_read) +return -EBADF ; - old_fs =get_fs (); -set_fs (get_ds ()); - ret =__vfs_read (file, buf, count, &offset); -set_fs (old_fs); +init_sync_kiocb (&kiocb, file); + kiocb.ki_pos = offset; +iov_iter_kvec (&iter,READ |ITER_KVEC , &iov,1 , count); + ret = file->f_op->integrity_read (&kiocb, &iter); +BUG_ON (ret == -EIOCBQUEUED );return ret; }
Quoted 4 lines
Quoted 4 lines
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data
Quoted 11 lines · Mimi Zohar
Quoted 6 lines · Linus Torvalds
This is still wrong.
(a) there is no explanation for why we need that exclusive lock in the first place
Why should a read need exclusive access? You'd think shared is sufficient.
True, reading a file shouldn't require an exclusive lock. ?The exclusive lock is taken to prevent the file from changing while the file hash is being calculated.
And also to prevent the file hash from being calculated multiple times.
Quoted 373 lines
Quoted 2 lines
But regardless, it needs *explanation*.
Agreed. ?A fuller explanation was included in the cover letter that should have also been included in the patch description. ?The following is taken from the cover letter:
With the introduction of IMA-appraisal and the need to write file hashes as security xattrs, IMA needed to take the global
i_mutexlock.??process_measurement() took theiint->mutexfirst and then thei_mutex, while setxattr, chmod and chown took the locks in reverse order.??To resolve this potential deadlock, theiint->mutexwas removed.Some filesystems have recently replaced their filesystem dependent lock with the global
i_rwsem(formerly thei_mutex) to read a file. As a result, when IMA attempts to calculate the file hash, reading the file attempts to take thei_rwsemagain.To resolve this locking problem, this patch set defines a new ->integrity_read file operation method.
(Fixes: Commit
6552321831dc"xfs: removei_iolockand usei_rwsemin the VFS inode instead")Mimi
Quoted 346 lines
(b) the lockdep test isn't for the exclusive lock that the code comment says it is
So no, this needs more work.
?
?????Linus
?Quoted 335 lines · Mimi Zohar
From: Christoph Hellwig <[email protected]>
Add a new ->integrity_read file operation to read data for integrity hash collection. This is defined to be equivalent to ->read_iter, except that it will be called with the
i_rwsemheld exclusively.(Based on Christoph's original patch.)
Signed-off-by Christoph Hellwig <[email protected]>Cc Matthew Garrett <[email protected]>Cc Jan Kara <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Andreas Dilger <[email protected]>Cc Jaegeuk Kim <[email protected]>Cc Chao Yu <[email protected]>Cc Steven Whitehouse <[email protected]>Cc Bob Peterson <[email protected]>Cc David Woodhouse <[email protected]>Cc Dave Kleikamp <[email protected]>Cc Ryusuke Konishi <[email protected]>Cc Mark Fasheh <[email protected]>Cc Joel Becker <[email protected]>Cc Richard Weinberger <[email protected]>Cc "Darrick J. Wong" <[email protected]>Cc Hugh Dickins <[email protected]>Cc Chris Mason <[email protected]>Signed-off-by Mimi Zohar <[email protected]>Reviewed-by Jan Kara <[email protected]>Reviewed-by Dmitry Kasatkin <[email protected]>--- fs/btrfs/file.c | 1 + fs/efivarfs/file.c | 1 + fs/ext2/file.c | 17 +++++++++++++++++ fs/ext4/file.c | 20 ++++++++++++++++++++ fs/f2fs/file.c | 1 + fs/jffs2/file.c | 1 + fs/jfs/file.c | 1 + fs/nilfs2/file.c | 1 + fs/ramfs/file-mmu.c | 1 + fs/ramfs/file-nommu.c | 1 + fs/ubifs/file.c | 1 + fs/xfs/xfs_file.c | 21 +++++++++++++++++++++ include/linux/fs.h | 1 + mm/shmem.c | 1 + security/integrity/iint.c | 20 ++++++++++++++------ 15 files changed, 83 insertions(+), 6 deletions(-)fs/btrfs/file.c +1
-0@@ -3125,6 +3125,7 @@ const struct file_operations btrfs_file_operations = {#endif .clone_file_range = btrfs_clone_file_range, .dedupe_file_range = btrfs_dedupe_file_range, + .integrity_read = generic_file_read_iter, };void
btrfs_auto_defrag_exit(void)fs/efivarfs/file.c +1
-0@@ -179,4 +179,5 @@ const struct file_operations efivarfs_file_operations = { .write = efivarfs_file_write, .llseek = no_llseek, .unlocked_ioctl = efivarfs_file_ioctl, + .integrity_read = efivarfs_file_read_iter,};
fs/ext2/file.c +16
-0@@ -192,6 +192,22 @@ static ssize_t ext2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return generic_file_read_iter (iocb, to); } +static ssize_t ext2_file_integrity_read_iter (struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +lockdep_assert_held (&inode->i_rwsem); +#ifdef CONFIG_FS_DAX +if (!iov_iter_count (to)) +return 0 ;/* skip atime */ + +if (IS_DAX (iocb->ki_filp->f_mapping->host)) +return dax_iomap_rw (iocb, to, &ext2_iomap_ops); +#endif +return generic_file_read_iter (iocb, to); +} +static ssize_t ext2_file_write_iter (struct kiocb *iocb,struct iov_iter *from){
#ifdefCONFIG_FS_DAXfs/ext2/file.c +1
-0@@ -216,6 +232,7 @@ const struct file_operations ext2_file_operations = { .get_unmapped_area = thp_get_unmapped_area, .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, + .integrity_read = ext2_file_integrity_read_iter, };const struct inode_operations ext2_file_inode_operations = {fs/ext4/file.c +19
-0@@ -74,6 +74,25 @@ static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return generic_file_read_iter (iocb, to); } +static ssize_t ext4_file_integrity_read_iter (struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +lockdep_assert_held (&inode->i_rwsem); +if (unlikely (ext4_forced_shutdown (EXT4_SB (inode->i_sb)))) +return -EIO ; + +if (!iov_iter_count (to)) +return 0 ;/* skip atime */ + +#ifdef CONFIG_FS_DAX +if (IS_DAX (inode)) +return dax_iomap_rw (iocb, to, &ext4_iomap_ops); +#endif +return generic_file_read_iter (iocb, to); +} +/* * Called when an inode is released. Note that this is different * from
ext4_file_open: open gets called at every open, but releasefs/ext4/file.c +1
-0@@ -747,6 +766,7 @@ const struct file_operations ext4_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ext4_fallocate, + .integrity_read = ext4_file_integrity_read_iter, };const struct inode_operations ext4_file_inode_operations = {fs/f2fs/file.c +1
-0@@ -2514,4 +2514,5 @@ const struct file_operations f2fs_file_operations = {#endif .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, + .integrity_read = generic_file_read_iter, };fs/jffs2/file.c +1
-0@@ -57,6 +57,7 @@ const struct file_operations jffs2_file_operations = .mmap = generic_file_readonly_mmap, .fsync = jffs2_fsync, .splice_read = generic_file_splice_read, + .integrity_read = generic_file_read_iter, };/* jffs2_file_inode_operations */ fs/jfs/file.c +1
-0@@ -162,4 +162,5 @@ const struct file_operations jfs_file_operations = {#ifdef CONFIG_COMPAT .compat_ioctl = jfs_compat_ioctl, #endif + .integrity_read = generic_file_read_iter, };fs/nilfs2/file.c +1
-0@@ -150,6 +150,7 @@ const struct file_operations nilfs_file_operations = {/* .release = nilfs_release_file, */ .fsync = nilfs_sync_file, .splice_read = generic_file_splice_read, + .integrity_read = generic_file_read_iter, };const struct inode_operations nilfs_file_inode_operations = {fs/ramfs/file-mmu.c +1
-0@@ -47,6 +47,7 @@ const struct file_operations ramfs_file_operations = { .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, .get_unmapped_area = ramfs_mmu_get_unmapped_area, + .integrity_read = generic_file_read_iter, };const struct inode_operations ramfs_file_inode_operations = {fs/ramfs/file-nommu.c +1
-0@@ -50,6 +50,7 @@ const struct file_operations ramfs_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, + .integrity_read = generic_file_read_iter, };const struct inode_operations ramfs_file_inode_operations = {fs/ubifs/file.c +1
-0@@ -1747,4 +1747,5 @@ const struct file_operations ubifs_file_operations = { #ifdef CONFIG_COMPAT .compat_ioctl = ubifs_compat_ioctl, #endif + .integrity_read = generic_file_read_iter,};
fs/xfs/xfs_file.c +21
-0@@ -292,6 +292,26 @@ xfs_file_read_iter(return ret; } +static ssize_t +xfs_integrity_read ( +struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +struct xfs_mount *mp =XFS_I (inode)->i_mount; + +lockdep_assert_held (&inode->i_rwsem); + +XFS_STATS_INC (mp, xs_read_calls); + +if (XFS_FORCED_SHUTDOWN (mp)) +return -EIO ; + +if (IS_DAX (inode)) +return dax_iomap_rw (iocb, to, &xfs_iomap_ops); +return generic_file_read_iter (iocb, to); +} +/* * Zero any on disk space between the current EOF and the new, larger EOF. * @@ -1175,6 +1195,7 @@ const struct file_operations xfs_file_operations = { .fallocate = xfs_file_fallocate, .clone_file_range = xfs_file_clone_range, .dedupe_file_range = xfs_file_dedupe_range, + .integrity_read = xfs_integrity_read, };const struct file_operations xfs_dir_file_operations = {include/linux/fs.h +1
-0@@ -1699,6 +1699,7 @@ struct file_operations { u64);ssize_t (*dedupe_file_range)(struct file *,u64 ,u64 ,struct file *,u64 ); +ssize_t (*integrity_read)(struct kiocb *,struct iov_iter *); } __randomize_layout;struct
inode_operations{mm/shmem.c +1
-0@@ -3849,6 +3849,7 @@ static const struct file_operations shmem_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = shmem_fallocate, + .integrity_read = shmem_file_read_iter, #endif };security/integrity/iint.c +14
-6@@ -21,6 +21,7 @@#include <linux/rbtree.h> #include <linux/file.h> #include <linux/uaccess.h> +#include <linux/uio.h> #include "integrity.h" static struct rb_root integrity_iint_tree =RB_ROOT ;@@ -184,18 +185,25 @@ security_initcall(integrity_iintcache_init);int integrity_kernel_read (struct file *file,loff_t offset,void *addr,unsigned long count) { -mm_segment_t old_fs; -char __user *buf = (char __user *)addr; +struct inode *inode =file_inode (file); +struct kvec iov = { .iov_base = addr, .iov_len = count }; +struct kiocb kiocb; +struct iov_iter iter;ssize_t ret; +lockdep_assert_held (&inode->i_rwsem); +if (!(file->f_mode &FMODE_READ ))return -EBADF ; +if (!file->f_op->integrity_read) +return -EBADF ; - old_fs =get_fs (); -set_fs (get_ds ()); - ret =__vfs_read (file, buf, count, &offset); -set_fs (old_fs); +init_sync_kiocb (&kiocb, file); + kiocb.ki_pos = offset; +iov_iter_kvec (&iter,READ |ITER_KVEC , &iov,1 , count); + ret = file->f_op->integrity_read (&kiocb, &iter); +BUG_ON (ret == -EIOCBQUEUED );return ret; }
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
--
2.7.4--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data
In reply to a message not in the archiveQuoted 7 lines · Linus Torvalds
This is still wrong.
(a) there is no explanation for why we need that exclusive lock in the first place
Why should a read need exclusive access? You'd think shared is sufficient. But regardless, it needs *explanation*.
Shared is sufficient, and nothing in the patch (except for the description) actually requires an exclusive lock. It just happens that ima holds it exclusive for other internal reasons.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Linus Torvalds
This is still wrong.
(a) there is no explanation for why we need that exclusive lock in the first place
Quoted 6 lines
Quoted 2 lines
Why should a read need exclusive access? You'd think shared is sufficient. But regardless, it needs *explanation*.
Shared is sufficient, and nothing in the patch (except for the description) actually requires an exclusive lock. It just happens that ima holds it exclusive for other internal reasons.
Although reading the file to calculate the file hash doesn't require taking the lock exclusively, in either "fix" mode or called from __fput, immediately after calculating the file hash, the file hash is written out as an xattr. ?Writing the xattr requires taking the lock exclusively.
Mimi
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data
In reply to Mimi ZoharQuoted 11 lines · Mimi Zohar
Quoted 6 lines · Linus Torvalds
This is still wrong.
(a) there is no explanation for why we need that exclusive lock in the first place
Why should a read need exclusive access? You'd think shared is sufficient.
True, reading a file shouldn't require an exclusive lock. The exclusive lock is taken to prevent the file from changing while the file hash is being calculated.
That really shouldn't need an exclusive lock either. The whole point is that you're just reading the file, so a shared lock should be fine.
There may be other *higher* level reasons why the caller then might want an exclusive lock for other reasons, but that should have nothing to do with the reading part.
So this is the thing I want explained. Right now there are no explanations, and the few comments there are about exclusive locking don't make sense, and don't match the lockdep tests.
So the patch itself may be fine, but the commentary and explanations are broken and/or missing.
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/3] vfs: constify path argument to kernel_read_file_from_path
In reply to Mimi ZoharQuoted 1 line · Mimi Zohar
This patch constifies the path argument to
kernel_read_file_from_path.
I've applied this upstream independently of everything else, because it's obviously the right thing to do (as the sound_firmware.h part of the patch shows, never mind the whole "we're just passing the pathname to filp_open() which takes a const char" thing).
lINUS
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
In reply to Mimi ZoharFrom: Christoph Hellwig <[email protected]>
Writing extended attributes requires exclusively taking the i_rwsem lock. To synchronize the file hash calculation and writing the file hash as security.ima xattr, IMA-appraisal takes the i_rwsem lock exclusively before calculating the file hash. (Once the file hash is calculated, the result is cached. Taking the lock exclusively prevents calculating the file hash multiple times.)
Some filesystems have recently replaced their filesystem dependent lock with the global i_rwsem to read a file. As a result, when IMA attempts to calculate the file hash, reading the file attempts to take the i_rwsem again.
To resolve this locking problem, this patch defines a new ->integrity_read file operation method, which is equivalent to ->read_iter, except that it will not take the i_rwsem lock, but will be called with the i_rwsem held exclusively.
Since taking the i_rwsem exclusively is not required for reading the file in order to calculate the file hash, the code only verifies that the lock has been taken.
(Based on Christoph's original patch.)
Fixes: Commit 6552321831dc "xfs: remove i_iolock and use i_rwsem in the VFS inode instead"
---
Changelog:
- Updated patch description
--- fs/btrfs/file.c | 1 + fs/efivarfs/file.c | 1 + fs/ext2/file.c | 17 +++++++++++++++++ fs/ext4/file.c | 20 ++++++++++++++++++++ fs/f2fs/file.c | 1 + fs/jffs2/file.c | 1 + fs/jfs/file.c | 1 + fs/nilfs2/file.c | 1 + fs/ramfs/file-mmu.c | 1 + fs/ramfs/file-nommu.c | 1 + fs/ubifs/file.c | 1 + fs/xfs/xfs_file.c | 21 +++++++++++++++++++++ include/linux/fs.h | 1 + mm/shmem.c | 1 + security/integrity/iint.c | 20 ++++++++++++++------ 15 files changed, 83 insertions(+), 6 deletions(-)
fs/btrfs/file.c +1 -0
@@ -3125,6 +3125,7 @@ const struct file_operations btrfs_file_operations = {#endif .clone_file_range = btrfs_clone_file_range, .dedupe_file_range = btrfs_dedupe_file_range, + .integrity_read = generic_file_read_iter, };void btrfs_auto_defrag_exit (void )
fs/efivarfs/file.c +1 -0
@@ -179,4 +179,5 @@ const struct file_operations efivarfs_file_operations = { .write = efivarfs_file_write, .llseek = no_llseek, .unlocked_ioctl = efivarfs_file_ioctl, + .integrity_read = efivarfs_file_read_iter, };
fs/ext2/file.c +17 -0
@@ -192,6 +192,22 @@ static ssize_t ext2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return generic_file_read_iter (iocb, to); } +static ssize_t ext2_file_integrity_read_iter (struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +lockdep_assert_held (&inode->i_rwsem); +#ifdef CONFIG_FS_DAX +if (!iov_iter_count (to)) +return 0 ;/* skip atime */ + +if (IS_DAX (iocb->ki_filp->f_mapping->host)) +return dax_iomap_rw (iocb, to, &ext2_iomap_ops); +#endif +return generic_file_read_iter (iocb, to); +} +static ssize_t ext2_file_write_iter (struct kiocb *iocb,struct iov_iter *from) {#ifdef CONFIG_FS_DAX
@@ -216,6 +232,7 @@ const struct file_operations ext2_file_operations = { .get_unmapped_area = thp_get_unmapped_area, .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, + .integrity_read = ext2_file_integrity_read_iter, };const struct inode_operations ext2_file_inode_operations = {
fs/ext4/file.c +20 -0
@@ -74,6 +74,25 @@ static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return generic_file_read_iter (iocb, to); } +static ssize_t ext4_file_integrity_read_iter (struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); + +lockdep_assert_held (&inode->i_rwsem); +if (unlikely (ext4_forced_shutdown (EXT4_SB (inode->i_sb)))) +return -EIO ; + +if (!iov_iter_count (to)) +return 0 ;/* skip atime */ + +#ifdef CONFIG_FS_DAX +if (IS_DAX (inode)) +return dax_iomap_rw (iocb, to, &ext4_iomap_ops); +#endif +return generic_file_read_iter (iocb, to); +} +/* * Called when an inode is released. Note that this is different * from ext4_file_open: open gets called at every open, but release
@@ -747,6 +766,7 @@ const struct file_operations ext4_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ext4_fallocate, + .integrity_read = ext4_file_integrity_read_iter, };const struct inode_operations ext4_file_inode_operations = {
fs/f2fs/file.c +1 -0
@@ -2514,4 +2514,5 @@ const struct file_operations f2fs_file_operations = {#endif .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, + .integrity_read = generic_file_read_iter, };
fs/jffs2/file.c +1 -0
@@ -57,6 +57,7 @@ const struct file_operations jffs2_file_operations = .mmap = generic_file_readonly_mmap, .fsync = jffs2_fsync, .splice_read = generic_file_splice_read, + .integrity_read = generic_file_read_iter, };/* jffs2_file_inode_operations */
fs/jfs/file.c +1 -0
@@ -162,4 +162,5 @@ const struct file_operations jfs_file_operations = {#ifdef CONFIG_COMPAT .compat_ioctl = jfs_compat_ioctl, #endif + .integrity_read = generic_file_read_iter, };
fs/nilfs2/file.c +1 -0
@@ -150,6 +150,7 @@ const struct file_operations nilfs_file_operations = {/* .release = nilfs_release_file, */ .fsync = nilfs_sync_file, .splice_read = generic_file_splice_read, + .integrity_read = generic_file_read_iter, };const struct inode_operations nilfs_file_inode_operations = {
fs/ramfs/file-mmu.c +1 -0
@@ -47,6 +47,7 @@ const struct file_operations ramfs_file_operations = { .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, .get_unmapped_area = ramfs_mmu_get_unmapped_area, + .integrity_read = generic_file_read_iter, };const struct inode_operations ramfs_file_inode_operations = {
fs/ramfs/file-nommu.c +1 -0
@@ -50,6 +50,7 @@ const struct file_operations ramfs_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .llseek = generic_file_llseek, + .integrity_read = generic_file_read_iter, };const struct inode_operations ramfs_file_inode_operations = {
fs/ubifs/file.c +1 -0
@@ -1747,4 +1747,5 @@ const struct file_operations ubifs_file_operations = {#ifdef CONFIG_COMPAT .compat_ioctl = ubifs_compat_ioctl, #endif + .integrity_read = generic_file_read_iter, };
fs/xfs/xfs_file.c +21 -0
@@ -292,6 +292,26 @@ xfs_file_read_iter(return ret; } +static ssize_t +xfs_integrity_read ( +struct kiocb *iocb, +struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +struct xfs_mount *mp =XFS_I (inode)->i_mount; + +lockdep_assert_held (&inode->i_rwsem); + +XFS_STATS_INC (mp, xs_read_calls); + +if (XFS_FORCED_SHUTDOWN (mp)) +return -EIO ; + +if (IS_DAX (inode)) +return dax_iomap_rw (iocb, to, &xfs_iomap_ops); +return generic_file_read_iter (iocb, to); +} +/* * Zero any on disk space between the current EOF and the new, larger EOF. *
@@ -1175,6 +1195,7 @@ const struct file_operations xfs_file_operations = { .fallocate = xfs_file_fallocate, .clone_file_range = xfs_file_clone_range, .dedupe_file_range = xfs_file_dedupe_range, + .integrity_read = xfs_integrity_read, };const struct file_operations xfs_dir_file_operations = {
include/linux/fs.h +1 -0
@@ -1699,6 +1699,7 @@ struct file_operations { u64);ssize_t (*dedupe_file_range)(struct file *,u64 ,u64 ,struct file *,u64 ); +ssize_t (*integrity_read)(struct kiocb *,struct iov_iter *); } __randomize_layout;struct inode_operations {
mm/shmem.c +1 -0
@@ -3849,6 +3849,7 @@ static const struct file_operations shmem_file_operations = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = shmem_fallocate, + .integrity_read = shmem_file_read_iter,#endif };
security/integrity/iint.c +14 -6
@@ -21,6 +21,7 @@#include <linux/rbtree.h> #include <linux/file.h> #include <linux/uaccess.h> +#include <linux/uio.h> #include "integrity.h" static struct rb_root integrity_iint_tree =RB_ROOT ;
@@ -184,18 +185,25 @@ security_initcall(integrity_iintcache_init);int integrity_kernel_read (struct file *file,loff_t offset,void *addr,unsigned long count) { -mm_segment_t old_fs; -char __user *buf = (char __user *)addr; +struct inode *inode =file_inode (file); +struct kvec iov = { .iov_base = addr, .iov_len = count }; +struct kiocb kiocb; +struct iov_iter iter;ssize_t ret; +lockdep_assert_held (&inode->i_rwsem); +if (!(file->f_mode &FMODE_READ ))return -EBADF ; +if (!file->f_op->integrity_read) +return -EBADF ; - old_fs =get_fs (); -set_fs (get_ds ()); - ret =__vfs_read (file, buf, count, &offset); -set_fs (old_fs); +init_sync_kiocb (&kiocb, file); + kiocb.ki_pos = offset; +iov_iter_kvec (&iter,READ |ITER_KVEC , &iov,1 , count); + ret = file->f_op->integrity_read (&kiocb, &iter); +BUG_ON (ret == -EIOCBQUEUED );return ret; }
Signature · 6 lines
2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Quoted 9 lines · Mimi Zohar
To resolve this locking problem, this patch defines a new ->integrity_read file operation method, which is equivalent to ->read_iter, except that it will not take the
i_rwsemlock, but will be called with thei_rwsemheld exclusively.Since taking the
i_rwsemexclusively is not required for reading the file in order to calculate the file hash, the code only verifies that the lock has been taken.
Ok, so I'm onboard with the commit message now, but realized that I'm not actually convinced that i_rwsem is even meaningful.
Sure, generic_file_write_iter() does take that lock exclusively, but not everybody uses generic_file_write_iter() at all for writing.
For example, xfs still uses that i_rwsem, but for block-aligned writes it will only get it shared. And I'm not convinced some other filesystem might not end up using some other lock entirely.
So I'm basically not entirely convinced that these i_rwsem games make any sense at all.
The filesystem can do its own locking, and I'm starting to think that it would be better to just pass this "this is an integrity read" down to the filesystem, and expect the filesystem to do the locking based on that.
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Quoted 21 lines · Linus Torvalds
Quoted 9 lines · Mimi Zohar
To resolve this locking problem, this patch defines a new ->integrity_read file operation method, which is equivalent to ->read_iter, except that it will not take the
i_rwsemlock, but will be called with thei_rwsemheld exclusively.Since taking the
i_rwsemexclusively is not required for reading the file in order to calculate the file hash, the code only verifies that the lock has been taken.Ok, so I'm onboard with the commit message now, but realized that I'm not actually convinced that
i_rwsemis even meaningful.Sure,
generic_file_write_iter()does take that lock exclusively, but not everybody usesgeneric_file_write_iter()at all for writing.For example, xfs still uses that
i_rwsem, but for block-aligned writes it will only get it shared. And I'm not convinced some other filesystem might not end up using some other lock entirely.
Quoted 7 lines
So I'm basically not entirely convinced that these
i_rwsemgames make any sense at all.The filesystem can do its own locking, and I'm starting to think that it would be better to just pass this "this is an integrity read" down to the filesystem, and expect the filesystem to do the locking based on that.
IMA would still need to take the i_rwsem to write the xattr. ?Unless the i_rwsem was taken before calling the integrity_read, calculating the file hash would be serialized, but would not prevent the file hash from being calculated multiple times.
(Introducing a new lock would result in the locks being taken in reverse order for setxattr, chown, chmod syscalls.)
Mimi
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
In reply to Linus TorvaldsQuoted 6 lines · Linus Torvalds
Sure,
generic_file_write_iter()does take that lock exclusively, but not everybody usesgeneric_file_write_iter()at all for writing.For example, xfs still uses that
i_rwsem, but for block-aligned writes it will only get it shared. And I'm not convinced some other filesystem might not end up using some other lock entirely.
Only for direct I/O, and IMA and direct I/O don't work together.
Quoted 1 line
From
ima_collect_measurement:
if (file->f_flags & O_DIRECT) {
audit_cause = "failed(directio)";
result = -EACCES;
goto out;
}(and yes, it should be checking for IOCB_DIRECT to avoid racy f_flags manipulations, but that's another issue)
Quoted 4 lines
The filesystem can do its own locking, and I'm starting to think that it would be better to just pass this "this is an integrity read" down to the filesystem, and expect the filesystem to do the locking based on that.
Well, that's exactly the point of the new ->integrity_read routine
I proposed and prototype. The important thing is that it is called with i_rwsem held because code mugh higher in the chain already acquired it, but except for that it's entirely up to the file system. --
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Quoted 9 lines · Christoph Hellwig
Only for direct I/O, and IMA and direct I/O don't work together. From
ima_collect_measurement:if (file->f_flags & O_DIRECT) { audit_cause = "failed(directio)"; result = -EACCES; goto out; }
That's not the issue.
The issue is that somebody else can come in - using direct IO - at the same time as the first person is collecting measurements, and thus race with the collector.
So now the measurements are not trustworthy any more.
Quoted 4 lines
Well, that's exactly the point of the new ->integrity_read routine I proposed and prototype. The important thing is that it is called with
i_rwsemheld because code mugh higher in the chain already acquired it, but except for that it's entirely up to the file system.
.. and *my* point is that it's the wrong lock for actually checking integrity (it doesn't actually guarantee exclusion, even though in practice it's almost always the case), and so we're adding a nasty callback that in 99% of all cases is the same as the normal read, and we *could* have just added it with a RWF flag instead.
Is there some reason why integrity has to use that particular lock that is so inconvenient for the filesystems it wants to check?
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Quoted 5 lines · Linus Torvalds
The issue is that somebody else can come in - using direct IO - at the same time as the first person is collecting measurements, and thus race with the collector.
So now the measurements are not trustworthy any more.
Yes. And it's always been that way with IMA.
Quoted 8 lines
.. and *my* point is that it's the wrong lock for actually checking integrity (it doesn't actually guarantee exclusion, even though in practice it's almost always the case), and so we're adding a nasty callback that in 99% of all cases is the same as the normal read, and we *could* have just added it with a RWF flag instead.
Is there some reason why integrity has to use that particular lock that is so inconvenient for the filesystems it wants to check?
I'll have to defer that to Mimi - I just jumped into this whole mess to help fixing the deadlocks we saw on XFS and NFS.
Unfortunately the whole security code is a giant mess that doesn't document assumptions, threat models or gets any sort of verification of those through automated testing.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
In reply to Linus TorvaldsQuoted 11 lines · Linus Torvalds
Quoted 9 lines · Christoph Hellwig
Only for direct I/O, and IMA and direct I/O don't work together. From
ima_collect_measurement:if (file->f_flags & O_DIRECT) { audit_cause = "failed(directio)"; result = -EACCES; goto out; }
Quoted 7 lines
That's not the issue.
The issue is that somebody else can come in - using direct IO - at the same time as the first person is collecting measurements, and thus race with the collector.
So now the measurements are not trustworthy any more.
Unless I'm missing something, that would only be possible with an IMA policy rule that permits direct IO (eg. permit_directio). ?Otherwise the direct IO is denied.
Quoted 5 lines
Quoted 4 lines
Well, that's exactly the point of the new ->integrity_read routine I proposed and prototype. The important thing is that it is called with
i_rwsemheld because code mugh higher in the chain already acquired it, but except for that it's entirely up to the file system.
Quoted 8 lines
.. and *my* point is that it's the wrong lock for actually checking integrity (it doesn't actually guarantee exclusion, even though in practice it's almost always the case), and so we're adding a nasty callback that in 99% of all cases is the same as the normal read, and we *could* have just added it with a RWF flag instead.
Is there some reason why integrity has to use that particular lock that is so inconvenient for the filesystems it wants to check?
Originally IMA had its own lock (iint->mutex), prior to IMA-appraisal being upstreamed. ?With a separate lock, the iint->mutex and i_rwsem would be taken in reverse order in process_measurements() and in the setxattr, chown, chmod syscalls.
I'm at the airport on my way back home.
Mimi
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Quoted 4 lines · Mimi Zohar
Unless I'm missing something, that would only be possible with an IMA policy rule that permits direct IO (eg.
permit_directio). Otherwise the direct IO is denied.
Note that the "XFS and directio" was only an example.
There is absolutely nothing that says that a filesystem has to use i_rwsem for IO serialization at all. Even for the regular write path.
Now, I suspect most (all?) do, but that's a historical artifact rather than "design". In particular, the VFS layer used to do the locking for the filesystems, to guarantee the POSIX requirements (POSIX requires that writes be seen atomically).
But that lock was pushed down into the filesystems, since some filesystems really wanted to have parallel writes (particularly for direct IO, where that POSIX serialization requirement doesn't exist).
That's all many years ago, though. New filesystems are likely to have copied the pattern from old ones, but even then..
Also, it's worth noting that "inode->i_rwlock" isn't even well-defined as a lock. You can have the question of *which* inode gets talked about when you have things like eoverlayfs etc. Normally it would be obvious, but sometimes you'd use "file->f_mapping->host" (which is the same thing in the simple cases), and sometimes it really wouldn't be obvious at all..
So... I'm really not at all convinced that i_rwsem is sensible. It's one of those things that are "mostly right for the simple cases", but...
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Al Viro
maintainerRe: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Quoted 19 lines · Linus Torvalds
Now, I suspect most (all?) do, but that's a historical artifact rather than "design". In particular, the VFS layer used to do the locking for the filesystems, to guarantee the POSIX requirements (POSIX requires that writes be seen atomically).
But that lock was pushed down into the filesystems, since some filesystems really wanted to have parallel writes (particularly for direct IO, where that POSIX serialization requirement doesn't exist).
That's all many years ago, though. New filesystems are likely to have copied the pattern from old ones, but even then..
Also, it's worth noting that "
inode->i_rwlock" isn't even well-defined as a lock. You can have the question of *which* inode gets talked about when you have things like eoverlayfs etc. Normally it would be obvious, but sometimes you'd use "file->f_mapping->host" (which is the same thing in the simple cases), and sometimes it really wouldn't be obvious at all..
Quoted 3 lines
So... I'm really not at all convinced that
i_rwsemis sensible. It's one of those things that are "mostly right for the simple cases", but...
The thing pretty much common to all of them is that write() might need to modify permissions (suid removal), which brings ->i_rwsem in one way or another - notify_change() needs that held...
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Hi,
Quoted 20 lines · Al Viro
Quoted 19 lines · Linus Torvalds
Now, I suspect most (all?) do, but that's a historical artifact rather than "design". In particular, the VFS layer used to do the locking for the filesystems, to guarantee the POSIX requirements (POSIX requires that writes be seen atomically).
But that lock was pushed down into the filesystems, since some filesystems really wanted to have parallel writes (particularly for direct IO, where that POSIX serialization requirement doesn't exist).
That's all many years ago, though. New filesystems are likely to have copied the pattern from old ones, but even then..
Also, it's worth noting that "
inode->i_rwlock" isn't even well-defined as a lock. You can have the question of *which* inode gets talked about when you have things like eoverlayfs etc. Normally it would be obvious, but sometimes you'd use "file->f_mapping->host" (which is the same thing in the simple cases), and sometimes it really wouldn't be obvious at all..
Quoted 6 lines
Quoted 3 lines
So... I'm really not at all convinced that
i_rwsemis sensible. It's one of those things that are "mostly right for the simple cases", but...The thing pretty much common to all of them is that
write()might need to modify permissions (suid removal), which brings ->i_rwsem in one way or another -notify_change()needs that held...
For GFS2, if we are to hold the inode info constant while it is checked, we would need to take a glock (read lock in this case) across the relevant operations. The glock will be happy under i_rwlock, since we have a lock ordering that takes local locks ahead of cluster locks. I've not dug into this enough to figure out whether the current proposal will allow this to work with GFS2 though. Does IMA cache the results from the ->read_integrity() operation?
Steve.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Jan Kara
reviewerRe: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Quoted 28 lines · Steven Whitehouse
Quoted 20 lines · Al Viro
Quoted 19 lines · Linus Torvalds
Now, I suspect most (all?) do, but that's a historical artifact rather than "design". In particular, the VFS layer used to do the locking for the filesystems, to guarantee the POSIX requirements (POSIX requires that writes be seen atomically).
But that lock was pushed down into the filesystems, since some filesystems really wanted to have parallel writes (particularly for direct IO, where that POSIX serialization requirement doesn't exist).
That's all many years ago, though. New filesystems are likely to have copied the pattern from old ones, but even then..
Also, it's worth noting that "
inode->i_rwlock" isn't even well-defined as a lock. You can have the question of *which* inode gets talked about when you have things like eoverlayfs etc. Normally it would be obvious, but sometimes you'd use "file->f_mapping->host" (which is the same thing in the simple cases), and sometimes it really wouldn't be obvious at all..Quoted 6 lines
Quoted 3 lines
So... I'm really not at all convinced that
i_rwsemis sensible. It's one of those things that are "mostly right for the simple cases", but...The thing pretty much common to all of them is that
write()might need to modify permissions (suid removal), which brings ->i_rwsem in one way or another -notify_change()needs that held...
Quoted 7 lines
For GFS2, if we are to hold the inode info constant while it is checked, we would need to take a glock (read lock in this case) across the relevant operations. The glock will be happy under
i_rwlock, since we have a lock ordering that takes local locks ahead of cluster locks. I've not dug into this enough to figure out whether the current proposal will allow this to work with GFS2 though. Does IMA cache the results from the ->read_integrity() operation?
So I have asked Mimi about clustered filesystems before. And for now the answer was that IMA for clustered filesystems is not supported (it will return some error since ->integrity_read is NULL). If we would ever want to support those it would require larger overhaul of the IMA architecture to give filesystem more control over the locking (which is essentially what Linus wants).
Honza
Signature · 6 lines
Jan Kara <[email protected]> SUSE Labs, CR -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Quoted 29 lines · Jan Kara
Quoted 28 lines · Steven Whitehouse
Quoted 26 lines · Al Viro
Quoted 19 lines · Linus Torvalds
Now, I suspect most (all?) do, but that's a historical artifact rather than "design". In particular, the VFS layer used to do the locking for the filesystems, to guarantee the POSIX requirements (POSIX requires that writes be seen atomically).
But that lock was pushed down into the filesystems, since some filesystems really wanted to have parallel writes (particularly for direct IO, where that POSIX serialization requirement doesn't exist).
That's all many years ago, though. New filesystems are likely to have copied the pattern from old ones, but even then..
Also, it's worth noting that "
inode->i_rwlock" isn't even well-defined as a lock. You can have the question of *which* inode gets talked about when you have things like eoverlayfs etc. Normally it would be obvious, but sometimes you'd use "file->f_mapping->host" (which is the same thing in the simple cases), and sometimes it really wouldn't be obvious at all..Quoted 3 lines
So... I'm really not at all convinced that
i_rwsemis sensible. It's one of those things that are "mostly right for the simple cases", but...The thing pretty much common to all of them is that
write()might need to modify permissions (suid removal), which brings ->i_rwsem in one way or another -notify_change()needs that held...
Quoted 7 lines
Quoted 7 lines
For GFS2, if we are to hold the inode info constant while it is checked, we would need to take a glock (read lock in this case) across the relevant operations. The glock will be happy under
i_rwlock, since we have a lock ordering that takes local locks ahead of cluster locks. I've not dug into this enough to figure out whether the current proposal will allow this to work with GFS2 though. Does IMA cache the results from the ->read_integrity() operation?
Up to now, the hash calculation was stored in the iint structure, which is then used to extend the TPM, verify the file's integrity compared to the value stored in the xattr, and included in an audit message.
A new patch set by Thiago Bauermann will add appended signature support, re-using the kernel module signature appended method, which might require re-calculating the file hash based on a different hash algorithm.
Quoted 6 lines
So I have asked Mimi about clustered filesystems before. And for now the answer was that IMA for clustered filesystems is not supported (it will return some error since ->integrity_read is NULL). If we would ever want to support those it would require larger overhaul of the IMA architecture to give filesystem more control over the locking (which is essentially what Linus wants).
For performance reasons, IMA is not on a write hook, but detects file change on the last __fput() opened for write. ?At that point, the cached info is reset. ?The file hash is re-calculated and written out as an xattr. ?On the next file access (in policy), the file hash is re-calculated and stored in the iint.
In terms of remote/clustered/fuse filesystems, we wouldn't be on the __fput() path. ?Support for remote/clustered/fuse filesystems, would be similar to filesystems that do not support i_version. ?Meaning only the first file access (in policy) would be measured/appraised, but not subsequent ones. ?Even if we could detect file change, we would be dependent on the remote/clustered/fuse filesystem to inform us of the change. ?What type of integrity guarantees would that provide?
Mimi
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ima: use fs method to read integrity data (updated patch description)
Quoted 62 lines · Mimi Zohar
Quoted 30 lines · Jan Kara
Quoted 27 lines · Steven Whitehouse
Quoted 26 lines · Al Viro
Quoted 19 lines · Linus Torvalds
Now, I suspect most (all?) do, but that's a historical artifact rather than "design". In particular, the VFS layer used to do the locking for the filesystems, to guarantee the POSIX requirements (POSIX requires that writes be seen atomically).
But that lock was pushed down into the filesystems, since some filesystems really wanted to have parallel writes (particularly for direct IO, where that POSIX serialization requirement doesn't exist).
That's all many years ago, though. New filesystems are likely to have copied the pattern from old ones, but even then..
Also, it's worth noting that "
inode->i_rwlock" isn't even well-defined as a lock. You can have the question of *which* inode gets talked about when you have things like eoverlayfs etc. Normally it would be obvious, but sometimes you'd use "file->f_mapping->host" (which is the same thing in the simple cases), and sometimes it really wouldn't be obvious at all..Quoted 3 lines
So... I'm really not at all convinced that
i_rwsemis sensible. It's one of those things that are "mostly right for the simple cases", but...The thing pretty much common to all of them is that
write()might need to modify permissions (suid removal), which brings ->i_rwsem in one way or another -notify_change()needs that held...Quoted 7 lines
Quoted 7 lines
For GFS2, if we are to hold the inode info constant while it is checked, we would need to take a glock (read lock in this case) across the relevant operations. The glock will be happy under
i_rwlock, since we have a lock ordering that takes local locks ahead of cluster locks. I've not dug into this enough to figure out whether the current proposal will allow this to work with GFS2 though. Does IMA cache the results from the ->read_integrity() operation?Up to now, the hash calculation was stored in the iint structure, which is then used to extend the TPM, verify the file's integrity compared to the value stored in the xattr, and included in an audit message.
A new patch set by Thiago Bauermann will add appended signature support, re-using the kernel module signature appended method, which might require re-calculating the file hash based on a different hash algorithm.
Quoted 6 lines
So I have asked Mimi about clustered filesystems before. And for now the answer was that IMA for clustered filesystems is not supported (it will return some error since ->integrity_read is NULL). If we would ever want to support those it would require larger overhaul of the IMA architecture to give filesystem more control over the locking (which is essentially what Linus wants).
For performance reasons, IMA is not on a write hook, but detects file change on the last
__fput()opened for write. ?At that point, the cached info is reset. ?The file hash is re-calculated and written out as an xattr. ?On the next file access (in policy), the file hash is re-calculated and stored in the iint.
Quoted 7 lines
In terms of remote/clustered/fuse filesystems, we wouldn't be on the
__fput()path. ?Support for remote/clustered/fuse filesystems, would be similar to filesystems that do not supporti_version. ?Meaning only the first file access (in policy) would be measured/appraised, but not subsequent ones. ?Even if we could detect file change, we would be dependent on the remote/clustered/fuse filesystem to inform us of the change. ?What type of integrity guarantees would that provide?
After thinking this over a bit, perhaps we shouldn't cache the file integrity results for these filesystems, since we can't rely on them to notify us of a change (eg. malicious fs), but simply re-measure/re- validate files each time.
Mimi
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html