turn on force option for FUSE in builtin policies
Subsystems (6)
PATCH 1/2 fs/fuse: move SUPER_MAGIC definitions to linux/magic.h
In reply to Dongsu ParkTo be able to use FUSE_*SUPER_MAGIC macros in other subsystems like security/integrity/ima, we need to move the definitions from fs/fuse to include/uapi/linux/.
The FUSE_*SUPER_MAGIC macros are made available to userspace in the same way as other filesystems.
--- fs/fuse/control.c | 3 +-- fs/fuse/inode.c | 3 +-- include/uapi/linux/magic.h | 3 +++ 3 files changed, 5 insertions(+), 4 deletions(-)
fs/fuse/control.c +1 -2
@@ -10,8 +10,7 @@#include <linux/init.h> #include <linux/module.h> - -#define FUSE_CTL_SUPER_MAGIC 0x65735543 +#include <linux/magic.h> /* * This is non-NULL when the single instance of the control filesystem
fs/fuse/inode.c +1 -2
@@ -22,6 +22,7 @@#include <linux/exportfs.h> #include <linux/posix_acl.h> #include <linux/pid_namespace.h> +#include <linux/magic.h> MODULE_AUTHOR ("Miklos Szeredi <[email protected]>" );MODULE_DESCRIPTION ("Filesystem in Userspace" );
@@ -49,8 +50,6 @@ MODULE_PARM_DESC(max_user_congthresh,"Global limit for the maximum congestion threshold an " "unprivileged user can set"); -#define FUSE_SUPER_MAGIC 0x65735546 -#define FUSE_DEFAULT_BLKSIZE 512/** Maximum number of outstanding background requests */
include/uapi/linux/magic.h +3 -0
@@ -90,4 +90,7 @@#define BALLOON_KVM_MAGIC 0x13661366#define ZSMALLOC_MAGIC 0x58295829 +#define FUSE_CTL_SUPER_MAGIC 0x65735543 +#define FUSE_SUPER_MAGIC 0x65735546 +#endif /* __LINUX_MAGIC_H__ */
Signature · 1 line
2.13.6
PATCH 2/2 ima: turn on force option for FUSE in builtin policies
In reply to Dongsu ParkIn case of FUSE filesystem, cached integrity results in IMA could be reused, when the userspace FUSE process has changed the underlying files. To be able to avoid such cases, we need to turn on the force option in builtin policies, for actions of measure and appraise. Then integrity values become re-measured and re-appraised. In that way, cached integrity results won't be used.
This patch depends on the patch "ima: define a new policy option named force" by Mimi. [1]
How to test the force option written by Alban:
====
The test I did was using a patched version of the memfs FUSE driver [2][3] and two very simple "hello-world" programs [5] (prog1 prints "hello world: 1" and prog2 prints "hello world: 2").
I copy prog1 and prog2 in the fuse-memfs mount point, execute them and check the sha1 hash in "/sys/kernel/security/ima/ascii_runtime_measurements".
My patch on the memfs FUSE driver added a backdoor command to serve prog1 when the kernel asks for prog2 or vice-versa. In this way, I can exec prog1 and get it to print "hello world: 2" without ever replacing the file via the VFS, so the kernel is not aware of the change.
The test was done using the branch "dongsu/fuse-userns-v5-2" [4], including both this new force option and Sascha's patch ("ima: Use i_version only when filesystem supports it").
Step by step test procedure:
1. Mount the memfs FUSE using [3]:
rm -f /tmp/memfs-switch* ; memfs -L DEBUG /mnt/memfs
2. Copy prog1 and prog2 using [5]
cp prog1 /mnt/memfs/prog1
cp prog2 /mnt/memfs/prog2
3. Lookup the files and let the FUSE driver to keep the handles open:
dd if=/mnt/memfs/prog1 bs=1 | (read -n 1 x ; sleep 3600 ) & dd if=/mnt/memfs/prog2 bs=1 | (read -n 1 x ; sleep 3600 ) &
4. Check the 2 programs work correctly:
$ /mnt/memfs/prog1 hello world: 1 $ /mnt/memfs/prog2 hello world: 2
5. Check the measurements for prog1 and prog2:
$ sudo cat /sys/kernel/security/ima/ascii_runtime_measurements|grep /mnt/memfs/prog 10 7ac5aed52061cb09120e977c6d04ee5c7b11c371 ima-ng sha1:ac14c9268cd2811f7a5adea17b27d84f50e1122c /mnt/memfs/prog1 10 9acc17a9a32aec4a676b8f6558e17a3d6c9a78e6 ima-ng sha1:799cb5d1e06d5c37ae7a76ba25ecd1bd01476383 /mnt/memfs/prog2
6. Use the backdoor command in my patched memfs to redirect file operations on file handle 3 to file handle 2:
rm -f /tmp/memfs-switch* ; touch /tmp/memfs-switch-3-2
7. Check how the FUSE driver serves different content for the files:
$ /mnt/memfs/prog1 hello world: 2 $ /mnt/memfs/prog2 hello world: 2
8. Check the measurements:
sudo cat /sys/kernel/security/ima/ascii_runtime_measurements|grep /mnt/memfs/prog
Without the patches, on a vanilla kernel, there are no new measurements, despite the FUSE driver having served different executables.
However, with the "force" option enabled, I can see additional measurements for prog1 and prog2 with the hashes reversed when the FUSE driver served the alternative content.
====
[1] https://www.spinics.net/lists/linux-integrity/msg00948.html
[2] https://github.com/bbengfort/memfs
[3] https://github.com/kinvolk/memfs/commits/alban/switch-files
[4] https://github.com/kinvolk/linux/commits/dongsu/fuse-userns-v5-2
[5] https://github.com/kinvolk/fuse-userns-patches/commit/cf1f5750cab0
--- security/integrity/ima/ima_policy.c | 2 ++ 1 file changed, 2 insertions(+)
security/integrity/ima/ima_policy.c +2 -0
@@ -127,6 +127,7 @@ static struct ima_rule_entry default_measurement_rules[] __ro_after_init = { {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC}, {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC}, {.action = MEASURE, .func = POLICY_CHECK, .flags = IMA_FUNC}, + {.action = MEASURE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE}, }; static struct ima_rule_entry default_appraise_rules[] __ro_after_init = {
@@ -154,6 +155,7 @@ static struct ima_rule_entry default_appraise_rules[] __ro_after_init = { {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .fowner_op = &uid_eq, .flags = IMA_FOWNER | IMA_DIGSIG_REQUIRED}, #endif + {.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE}, }; static struct ima_rule_entry secure_boot_rules[] __ro_after_init = {
Signature · 1 line
2.13.6
cover turn on force option for FUSE in builtin policies
In case of FUSE filesystem, cached integrity results in IMA could be reused, when the userspace FUSE process has changed the underlying files. To be able to avoid such cases, we need to turn on the force option in builtin policies, for actions of measure and appraise. Then integrity values become re-measured and re-appraised. In that way, cached integrity results won't be used.
This patchset depends on the patch "ima: define a new policy option named force" by Mimi. [1] For details on testing the force option, please refer to the testing report by Alban. [2]
The first patch is for simply moving FUSE_*SUPER_MAGIC macros to include/uapi/linux, to be able to use those in other subsystems like security/integrity/ima.
The second patch is actually to turn on the force option for FUSE fs in IMA.
[1] https://www.spinics.net/lists/linux-integrity/msg00948.html
[2] https://marc.info/?l=linux-integrity&m=151559360514676&w=2
Dongsu Park (2):
fs/fuse: move SUPER_MAGIC definitions to linux/magic.h
ima: turn on force option for FUSE in builtin policies
fs/fuse/control.c | 3 +-- fs/fuse/inode.c | 3 +-- include/uapi/linux/magic.h | 3 +++ security/integrity/ima/ima_policy.c | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.13.6
Re: [PATCH 2/2] ima: turn on force option for FUSE in builtin policies
In reply to Dongsu Parksecurity/integrity/ima/ima_policy.c static struct ima_rule_entry default_measurement_rules[] __ro_after_init = { · line 131
Quoted 11 lines
security/integrity/ima/ima_policy.c +1
-0@@ -127,6 +127,7 @@ static struct ima_rule_entry default_measurement_rules[] __ro_after_init = { {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC}, {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC}, {.action = MEASURE, .func = POLICY_CHECK, .flags = IMA_FUNC}, + {.action = MEASURE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE}, };
Depending on the ordering of the policies and the number of "actions", this works. ?It also matches all hooks, not only those in the default_measurement_rule policy.
Although the rules are walked sequentially, there is an optimization in ima_match_rules(), which ends walking the list early, as soon as the last "action" rule is matched. ?Look at "actmask".
security/integrity/ima/ima_policy.c static struct ima_rule_entry default_appraise_rules[] __ro_after_init = { · line 161
Quoted 9 lines
security/integrity/ima/ima_policy.c +1
-0static struct ima_rule_entry default_appraise_rules[]__ro_after_init = {@@ -154,6 +155,7 @@ static struct ima_rule_entry default_appraise_rules[] __ro_after_init = { {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .fowner_op = &uid_eq, .flags = IMA_FOWNER | IMA_DIGSIG_REQUIRED}, #endif + {.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE}, }; static struct ima_rule_entry secure_boot_rules[] __ro_after_init = {
This rule applies to the secure-boot rules as well. ?(How likely is it to load a kernel module, kexec from a fuse filsystem?) ?However, after replacing the builtin policies with a custom policy, the custom policy might not contain the requirement to re-appraise fuse files.
With the "lockdown" patches, booting with secure-boot enabled, and after loading a custom policy, the "secure-boot" rules are still enabled. ?But now if the custom policy does not require fuse files to be re-appraised, the secure boot rules will not require fuse files to be re-appraised either.
This patch is simple and straight forward. ?It would be nice if it worked in all cases. ?Unfortunately, there are a number of situations, as described, that will not work.
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
kbuild test robot
build botRe: [PATCH 2/2] ima: turn on force option for FUSE in builtin policies
In reply to Dongsu ParkThank you for the patch! Yet something to improve:
Hi Dongsu,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.15-rc7 next-20180112]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Dongsu-Park/turn-on-force-option-for-FUSE-in-builtin-policies/20180115-015830
config: xtensa-allmodconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=xtensa
All errors (new ones prefixed by >>):
>> security/integrity/ima/ima_policy.c:130:74: error: 'IMA_FORCE' undeclared here (not in a function); did you mean 'IMA_FUNC'?
{.action = MEASURE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE},
^~~~~~~~~
IMA_FUNC
security/integrity/ima/ima_policy.c:158:73: error: invalid operands to binary | (have 'int' and 'struct ima_rule_entry *')
{.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE},
^
security/integrity/ima/ima_policy.c:29:21: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
#define IMA_FSMAGIC 0x0004
^
security/integrity/ima/ima_policy.c:158:61: note: in expansion of macro 'IMA_FSMAGIC'
{.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE},
^~~~~~~~~~~
security/integrity/ima/ima_policy.c:29:21: note: (near initialization for 'default_appraise_rules[14].flags')
#define IMA_FSMAGIC 0x0004
^
security/integrity/ima/ima_policy.c:158:61: note: in expansion of macro 'IMA_FSMAGIC'
{.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE},
^~~~~~~~~~~
security/integrity/ima/ima_policy.c:29:21: error: initializer element is not constant
#define IMA_FSMAGIC 0x0004
^
security/integrity/ima/ima_policy.c:158:61: note: in expansion of macro 'IMA_FSMAGIC'
{.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE},
^~~~~~~~~~~
security/integrity/ima/ima_policy.c:29:21: note: (near initialization for 'default_appraise_rules[14].flags')
#define IMA_FSMAGIC 0x0004
^ security/integrity/ima/ima_policy.c:158:61: note: in expansion of macro 'IMA_FSMAGIC'
{.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE},
^~~~~~~~~~~
vim +130 security/integrity/ima/ima_policy.c
115
116 static struct ima_rule_entry default_measurement_rules[] __ro_after_init = {
117 {.action = MEASURE, .func = MMAP_CHECK, .mask = MAY_EXEC,
118 .flags = IMA_FUNC | IMA_MASK},
119 {.action = MEASURE, .func = BPRM_CHECK, .mask = MAY_EXEC,
120 .flags = IMA_FUNC | IMA_MASK},
121 {.action = MEASURE, .func = FILE_CHECK, .mask = MAY_READ,
122 .uid = GLOBAL_ROOT_UID, .uid_op = &uid_eq,
123 .flags = IMA_FUNC | IMA_INMASK | IMA_EUID},
124 {.action = MEASURE, .func = FILE_CHECK, .mask = MAY_READ,
125 .uid = GLOBAL_ROOT_UID, .uid_op = &uid_eq,
126 .flags = IMA_FUNC | IMA_INMASK | IMA_UID},
127 {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC},
128 {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC},
129 {.action = MEASURE, .func = POLICY_CHECK, .flags = IMA_FUNC},
> 130 {.action = MEASURE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE}, 131 };
132
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 6 lines · Dongsu Park
In case of FUSE filesystem, cached integrity results in IMA could be reused, when the userspace FUSE process has changed the underlying files. To be able to avoid such cases, we need to turn on the force option in builtin policies, for actions of measure and appraise. Then integrity values become re-measured and re-appraised. In that way, cached integrity results won't be used.
The same is true for any distributed file system. Checking for magic numbers is always the wrong thing. You'll need flags for specific behavior in struct file_system_type instead.
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Dongsu Park
In case of FUSE filesystem, cached integrity results in IMA could be reused, when the userspace FUSE process has changed the underlying files. To be able to avoid such cases, we need to turn on the force option in builtin policies, for actions of measure and appraise. Then integrity values become re-measured and re-appraised. In that way, cached integrity results won't be used.
The same is true for any distributed file system. Checking for magic numbers is always the wrong thing. You'll need flags for specific behavior in struct
file_system_typeinstead.
For XFS, which considers fsmagic numbers private to the filesystem, *always* using the fsmagic number is wrong. As to whether this is true for other filesystems is unclear. IMA policies have been defined in terms of fsmagic numbers for a long time. fsmagic numbers were moved from the filesystems to magic.h for this purpose. Someone would have complained earlier if it is always wrong.
I just posted a patch titled "ima: define new policy condition based on the filesystem name" to allow policies to be defined in terms of the i_sb->s_type->name.
Mimi
Quoted 10 lines · Mimi Zohar
For XFS, which considers fsmagic numbers private to the filesystem, *always* using the fsmagic number is wrong. As to whether this is true for other filesystems is unclear. IMA policies have been defined in terms of fsmagic numbers for a long time. fsmagic numbers were moved from the filesystems to
magic.hfor this purpose. Someone would have complained earlier if it is always wrong.I just posted a patch titled "ima: define new policy condition based on the filesystem name" to allow policies to be defined in terms of the
i_sb->s_type->name.
ima has no business looking at either the name _or_ the magic number.
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Mimi Zohar
For XFS, which considers fsmagic numbers private to the filesystem, *always* using the fsmagic number is wrong. As to whether this is true for other filesystems is unclear. IMA policies have been defined in terms of fsmagic numbers for a long time. fsmagic numbers were moved from the filesystems to
magic.hfor this purpose. Someone would have complained earlier if it is always wrong.
Quoted 5 lines
Quoted 3 lines
I just posted a patch titled "ima: define new policy condition based on the filesystem name" to allow policies to be defined in terms of the
i_sb->s_type->name.ima has no business looking at either the name _or_ the magic number.
There are a couple of reasons to define policies in terms of the filesystem name or magic numbers.
One example is pseudo filesystems (eg. pseudo filesystems - sysfs, securitys, cgroups, selinuxfs, etc). These should never be measured or appraised.
The current example is fuse and remote file systems. These should always be re-evaluated and not rely on cached file info.
If not based on IMA policy, what do you propose? Define new SB_ flags
to indicate IMA disabled/enabled (eg. SB_IMA) and nocaching (eg.SB_IMA_NOCACHE)?
Mimi
PATCH 1/1 ima,fuse: introduce new fs flag FS_NO_IMA_CACHE
In reply to Christoph HellwigFrom: Alban Crequy <[email protected]>
This patch forces files to be re-measured, re-appraised and re-audited on file systems with the feature flag FS_NO_IMA_CACHE. In that way, cached integrity results won't be used.
For now, only FUSE filesystems use this flag. This is because the userspace FUSE process can change the underlying files at any times.
This patch is based on the patch "ima: define a new policy option named force" by Mimi. [1]
How to test this:
====
The test I did was using a patched version of the memfs FUSE driver [2][3] and two very simple "hello-world" programs [5] (prog1 prints "hello world: 1" and prog2 prints "hello world: 2").
I copy prog1 and prog2 in the fuse-memfs mount point, execute them and check the sha1 hash in "/sys/kernel/security/ima/ascii_runtime_measurements".
My patch on the memfs FUSE driver added a backdoor command to serve prog1 when the kernel asks for prog2 or vice-versa. In this way, I can exec prog1 and get it to print "hello world: 2" without ever replacing the file via the VFS, so the kernel is not aware of the change.
The test was done using the branch "alban/fuse-flag-ima-nocache" [4].
Step by step test procedure:
1. Mount the memfs FUSE using [3]:
rm -f /tmp/memfs-switch* ; memfs -L DEBUG /mnt/memfs
2. Copy prog1 and prog2 using [5]
cp prog1 /mnt/memfs/prog1
cp prog2 /mnt/memfs/prog2
3. Lookup the files and let the FUSE driver to keep the handles open:
dd if=/mnt/memfs/prog1 bs=1 | (read -n 1 x ; sleep 3600 ) & dd if=/mnt/memfs/prog2 bs=1 | (read -n 1 x ; sleep 3600 ) &
4. Check the 2 programs work correctly:
$ /mnt/memfs/prog1 hello world: 1 $ /mnt/memfs/prog2 hello world: 2
5. Check the measurements for prog1 and prog2:
$ sudo cat /sys/kernel/security/ima/ascii_runtime_measurements|grep /mnt/memfs/prog 10 7ac5aed52061cb09120e977c6d04ee5c7b11c371 ima-ng sha1:ac14c9268cd2811f7a5adea17b27d84f50e1122c /mnt/memfs/prog1 10 9acc17a9a32aec4a676b8f6558e17a3d6c9a78e6 ima-ng sha1:799cb5d1e06d5c37ae7a76ba25ecd1bd01476383 /mnt/memfs/prog2
6. Use the backdoor command in my patched memfs to redirect file operations on file handle 3 to file handle 2:
rm -f /tmp/memfs-switch* ; touch /tmp/memfs-switch-3-2
7. Check how the FUSE driver serves different content for the files:
$ /mnt/memfs/prog1 hello world: 2 $ /mnt/memfs/prog2 hello world: 2
8. Check the measurements:
sudo cat /sys/kernel/security/ima/ascii_runtime_measurements|grep /mnt/memfs/prog
Without the patch, there are no new measurements, despite the FUSE driver having served different executables.
With the patch, I can see additional measurements for prog1 and prog2 with the hashes reversed when the FUSE driver served the alternative content.
====
[1] https://www.spinics.net/lists/linux-integrity/msg00948.html
[2] https://github.com/bbengfort/memfs
[3] https://github.com/kinvolk/memfs/commits/alban/switch-files
[4] https://github.com/kinvolk/linux/commits/alban/fuse-flag-ima-nocache
[5] https://github.com/kinvolk/fuse-userns-patches/commit/cf1f5750cab0
--- fs/fuse/inode.c | 2 +- include/linux/fs.h | 1 + security/integrity/ima/ima_main.c | 11 +++++++---- 3 files changed, 9 insertions(+), 5 deletions(-)
fs/fuse/inode.c +1 -1
@@ -1212,7 +1212,7 @@ static void fuse_kill_sb_anon(struct super_block *sb)static struct file_system_type fuse_fs_type = { .owner =THIS_MODULE , .name ="fuse" , - .fs_flags =FS_HAS_SUBTYPE |FS_USERNS_MOUNT , + .fs_flags =FS_HAS_SUBTYPE |FS_USERNS_MOUNT |FS_NO_IMA_CACHE , .mount = fuse_mount, .kill_sb = fuse_kill_sb_anon, };
include/linux/fs.h +1 -0
@@ -2075,6 +2075,7 @@ struct file_system_type {#define FS_BINARY_MOUNTDATA 2#define FS_HAS_SUBTYPE 4#define FS_USERNS_MOUNT 8/* Can be mounted by userns root */ +#define FS_NO_IMA_CACHE 16/* Force IMA to re-measure, re-appraise, re-audit files */ #define FS_RENAME_DOES_D_MOVE 32768/* FS will handle d_move() during rename() internally. */ struct dentry *(*mount) (struct file_system_type *,int ,const char *,void *);
security/integrity/ima/ima_main.c +7 -4
@@ -24,6 +24,7 @@#include <linux/slab.h> #include <linux/xattr.h> #include <linux/ima.h> +#include <linux/fs.h> #include "ima.h"
@@ -229,13 +230,15 @@ static int process_measurement(struct file *file, char *buf, loff_t size, IMA_ACTION_FLAGS);/* -* Reset the measure, appraise and audit cached flags either if -* ima_inode_setxattr was called or based on policy, forcing -* the file to be re-evaluated. +* Reset the measure, appraise and audit cached flags either if: +* - ima_inode_setxattr was called, or +* - based on policy ("force"), or +* - based on filesystem feature flag +* forcing the file to be re-evaluated. */ if (test_and_clear_bit (IMA_CHANGE_XATTR , &iint->atomic_flags)) { iint->flags &= ~IMA_DONE_MASK ; - }else if (action &IMA_FORCE ) { + }else if (action &IMA_FORCE || inode->i_sb->s_type->fs_flags &FS_NO_IMA_CACHE ) {if (action &IMA_MEASURE ) { iint->measured_pcrs =0 ; iint->flags &=
Signature · 6 lines
2.13.6 -- 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 2/2] ima: turn on force option for FUSE in builtin policies
In reply to kbuild test robotHi,
Quoted 3 lines · kbuild test robot
[auto build test ERROR on linus/master]
[also build test ERROR on v4.15-rc7 next-20180112]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
As already mentioned in the commit message, this patch depends on patches that are not yet in the mainline, or not even in next-integrity. So please make it excluded from kbuild.
Thanks,
Dongsu
Quoted 64 lines
url: https://github.com/0day-ci/linux/commits/Dongsu-Park/turn-on-force-option-for-FUSE-in-builtin-policies/20180115-015830
config: xtensa-allmodconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=xtensaAll errors (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
security/integrity/ima/ima_policy.c:130:74: error: 'IMA_FORCE' undeclared here (not in a function); did you mean 'IMA_FUNC'?{.action = MEASURE, .fsmagic =
FUSE_SUPER_MAGIC, .flags =IMA_FSMAGIC|IMA_FORCE},
^~~~~~~~~
IMA_FUNC
security/integrity/ima/ima_policy.c:158:73: error: invalid operands to binary | (have 'int' and 'structima_rule_entry*')
{.action = APPRAISE, .fsmagic =FUSE_SUPER_MAGIC, .flags =IMA_FSMAGIC|IMA_FORCE},
^
security/integrity/ima/ima_policy.c:29:21: warning: initialization makes integer from pointer without a cast [-Wint-conversion]#define IMA_FSMAGIC 0x0004 ^ security/integrity/ima/ima_policy.c:158:61: note: in expansion of macro 'IMA_FSMAGIC' {.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE}, ^~~~~~~~~~~ security/integrity/ima/ima_policy.c:29:21: note: (near initialization for 'default_appraise_rules[14].flags') #define IMA_FSMAGIC 0x0004 ^ security/integrity/ima/ima_policy.c:158:61: note: in expansion of macro 'IMA_FSMAGIC' {.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE}, ^~~~~~~~~~~ security/integrity/ima/ima_policy.c:29:21: error: initializer element is not constant #define IMA_FSMAGIC 0x0004 ^ security/integrity/ima/ima_policy.c:158:61: note: in expansion of macro 'IMA_FSMAGIC' {.action = APPRAISE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE}, ^~~~~~~~~~~ security/integrity/ima/ima_policy.c:29:21: note: (near initialization for 'default_appraise_rules[14].flags') #define IMA_FSMAGIC 0x0004 ^
security/integrity/ima/ima_policy.c:158:61: note: in expansion of macro 'IMA_FSMAGIC'
{.action = APPRAISE, .fsmagic =FUSE_SUPER_MAGIC, .flags =IMA_FSMAGIC|IMA_FORCE},
^~~~~~~~~~~vim +130
security/integrity/ima/ima_policy.c115
116 static structima_rule_entrydefault_measurement_rules[]__ro_after_init= {
117 {.action = MEASURE, .func =MMAP_CHECK, .mask =MAY_EXEC,
118 .flags =IMA_FUNC|IMA_MASK},
119 {.action = MEASURE, .func =BPRM_CHECK, .mask =MAY_EXEC,
120 .flags =IMA_FUNC|IMA_MASK},
121 {.action = MEASURE, .func =FILE_CHECK, .mask =MAY_READ,
122 .uid =GLOBAL_ROOT_UID, .uid_op =&uid_eq,
123 .flags =IMA_FUNC|IMA_INMASK|IMA_EUID},
124 {.action = MEASURE, .func =FILE_CHECK, .mask =MAY_READ,
125 .uid =GLOBAL_ROOT_UID, .uid_op =&uid_eq,
126 .flags =IMA_FUNC|IMA_INMASK|IMA_UID},127 {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC}, 128 {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC}, 129 {.action = MEASURE, .func = POLICY_CHECK, .flags = IMA_FUNC}, > 130 {.action = MEASURE, .fsmagic = FUSE_SUPER_MAGIC, .flags = IMA_FSMAGIC | IMA_FORCE}, 131 }; 132
Quoted 3 lines
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
--
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
Hi,
Quoted 6 lines · Dongsu Park
In case of FUSE filesystem, cached integrity results in IMA could be reused, when the userspace FUSE process has changed the underlying files. To be able to avoid such cases, we need to turn on the force option in builtin policies, for actions of measure and appraise. Then integrity values become re-measured and re-appraised. In that way, cached integrity results won't be used.
Since yesterday Alban and I have been working on a different approach that does not depend on IMA rules, nor fsmagic. Please see:
https://www.mail-archive.com/[email protected]/msg1587390.html
If that's ok, I'm ready to discard this patchset.
Thanks,
Dongsu
Quoted 28 lines
This patchset depends on the patch "ima: define a new policy option named force" by Mimi. [1] For details on testing the force option, please refer to the testing report by Alban. [2]
The first patch is for simply moving FUSE_*SUPER_MAGIC macros to
include/uapi/linux, to be able to use those in other subsystems likesecurity/integrity/ima.The second patch is actually to turn on the force option for FUSE fs in IMA.
[1] https://www.spinics.net/lists/linux-integrity/msg00948.html
[2] https://marc.info/?l=linux-integrity&m=151559360514676&w=2Dongsu Park (2):
fs/fuse: moveSUPER_MAGICdefinitions tolinux/magic.h
ima: turn on force option for FUSE in builtin policiesfs/fuse/control.c | 3 +-- fs/fuse/inode.c | 3 +-- include/uapi/linux/magic.h | 3 +++ security/integrity/ima/ima_policy.c | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-)--
2.13.6
Quoted 10 lines · Dongsu Park
Hi,
Quoted 6 lines · Dongsu Park
In case of FUSE filesystem, cached integrity results in IMA could be reused, when the userspace FUSE process has changed the underlying files. To be able to avoid such cases, we need to turn on the force option in builtin policies, for actions of measure and appraise. Then integrity values become re-measured and re-appraised. In that way, cached integrity results won't be used.
Quoted 5 lines
Since yesterday Alban and I have been working on a different approach that does not depend on IMA rules, nor fsmagic. Please see:
https://www.mail-archive.com/[email protected]/msg1587390.htmlIf that's ok, I'm ready to discard this patchset.
You dropped a number of people involved in this discussion and mailing lists. Please post the proposed patch inline as an RFC, cc'ing the same people, those involved in the discussion, and previous mailing lists, including LSM, integrity, and fsdevel.
thanks,
Mimi
Re: [PATCH] ima,fuse: introduce new fs flag FS_NO_IMA_CACHE
In reply to Alban CrequyQuoted 107 lines · Alban Crequy
From: Alban Crequy <[email protected]>
This patch forces files to be re-measured, re-appraised and re-audited on file systems with the feature flag
FS_NO_IMA_CACHE. In that way, cached integrity results won't be used.For now, only FUSE filesystems use this flag. This is because the userspace FUSE process can change the underlying files at any times.
This patch is based on the patch "ima: define a new policy option named force" by Mimi. [1]
How to test this:
====
The test I did was using a patched version of the memfs FUSE driver [2][3] and two very simple "hello-world" programs [5] (prog1 prints "hello world: 1" and prog2 prints "hello world: 2").
I copy prog1 and prog2 in the fuse-memfs mount point, execute them and check the sha1 hash in "
/sys/kernel/security/ima/ascii_runtime_measurements".My patch on the memfs FUSE driver added a backdoor command to serve prog1 when the kernel asks for prog2 or vice-versa. In this way, I can exec prog1 and get it to print "hello world: 2" without ever replacing the file via the VFS, so the kernel is not aware of the change.
The test was done using the branch "alban/fuse-flag-ima-nocache" [4].
Step by step test procedure:
1. Mount the memfs FUSE using [3]:
rm -f/tmp/memfs-switch*; memfs -L DEBUG/mnt/memfs2. Copy prog1 and prog2 using [5]
cp prog1/mnt/memfs/prog1
cp prog2/mnt/memfs/prog23. Lookup the files and let the FUSE driver to keep the handles open:
dd if=/mnt/memfs/prog1 bs=1 | (read -n 1 x ; sleep 3600 ) & dd if=/mnt/memfs/prog2 bs=1 | (read -n 1 x ; sleep 3600 ) &4. Check the 2 programs work correctly:
$ /mnt/memfs/prog1 hello world: 1 $ /mnt/memfs/prog2 hello world: 25. Check the measurements for prog1 and prog2:
$ sudo cat /sys/kernel/security/ima/ascii_runtime_measurements|grep /mnt/memfs/prog 10 7ac5aed52061cb09120e977c6d04ee5c7b11c371 ima-ng sha1:ac14c9268cd2811f7a5adea17b27d84f50e1122c /mnt/memfs/prog1 10 9acc17a9a32aec4a676b8f6558e17a3d6c9a78e6 ima-ng sha1:799cb5d1e06d5c37ae7a76ba25ecd1bd01476383 /mnt/memfs/prog26. Use the backdoor command in my patched memfs to redirect file operations on file handle 3 to file handle 2:
rm -f/tmp/memfs-switch*; touch/tmp/memfs-switch-3-27. Check how the FUSE driver serves different content for the files:
$ /mnt/memfs/prog1 hello world: 2 $ /mnt/memfs/prog2 hello world: 28. Check the measurements:
sudo cat /sys/kernel/security/ima/ascii_runtime_measurements|grep/mnt/memfs/progWithout the patch, there are no new measurements, despite the FUSE driver having served different executables.
With the patch, I can see additional measurements for prog1 and prog2 with the hashes reversed when the FUSE driver served the alternative content.
====
[1] https://www.spinics.net/lists/linux-integrity/msg00948.html
[2] https://github.com/bbengfort/memfs
[3] https://github.com/kinvolk/memfs/commits/alban/switch-files
[4] https://github.com/kinvolk/linux/commits/alban/fuse-flag-ima-nocache
[5] https://github.com/kinvolk/fuse-userns-patches/commit/cf1f5750cab0Cc linux-integrity at vger.kernel.orgCc linux-security-module at vger.kernel.orgCc linux-kernel at vger.kernel.orgCc Miklos Szeredi <[email protected]>Cc Mimi Zohar <[email protected]>Cc Seth Forshee <[email protected]>Cc Christoph Hellwig <[email protected]>Tested-by Dongsu Park <[email protected]>Signed-off-by Alban Crequy <[email protected]>--- fs/fuse/inode.c | 2 +- include/linux/fs.h | 1 + security/integrity/ima/ima_main.c | 11 +++++++---- 3 files changed, 9 insertions(+), 5 deletions(-)fs/fuse/inode.c +0
-0
fs/fuse/inode.c static void fuse_kill_sb_anon(struct super_block *sb) · line 1215
Quoted 5 lines
fs/fuse/inode.c +1
-1@@ -1212,7 +1212,7 @@ static void fuse_kill_sb_anon(struct super_block *sb)static struct file_system_type fuse_fs_type = { .owner =THIS_MODULE , .name ="fuse" , - .fs_flags =FS_HAS_SUBTYPE |FS_USERNS_MOUNT , + .fs_flags =FS_HAS_SUBTYPE |FS_USERNS_MOUNT |FS_NO_IMA_CACHE ,
I just realised I should not have submitted this patch based on the branch I am on because FS_USERNS_MOUNT is not there now, so this patch does not apply cleanly on next-integrity at the moment. Sorry about that.
Quoted 30 lines
fs/fuse/inode.c +0
-0.mount = fuse_mount, .kill_sb = fuse_kill_sb_anon, };include/linux/fs.h +1
-0@@ -2075,6 +2075,7 @@ struct file_system_type {#define FS_BINARY_MOUNTDATA 2#define FS_HAS_SUBTYPE 4#define FS_USERNS_MOUNT 8/* Can be mounted by userns root */ +#define FS_NO_IMA_CACHE 16/* Force IMA to re-measure, re-appraise, re-audit files */ #define FS_RENAME_DOES_D_MOVE 32768/* FS will handle d_move() during rename() internally. */ struct dentry *(*mount) (struct file_system_type *,int ,const char *,void *);security/integrity/ima/ima_main.c +1
-0@@ -24,6 +24,7 @@#include <linux/slab.h> #include <linux/xattr.h> #include <linux/ima.h> +#include <linux/fs.h> #include "ima.h" @@ -229,13 +230,15 @@ static int process_measurement(struct file *file, char *buf, loff_t size, IMA_ACTION_FLAGS);
security/integrity/ima/ima_main.c static int process_measurement(struct file *file, char *buf, loff_t size, · line 238
Quoted 10 lines
security/integrity/ima/ima_main.c +5
-3/* -* Reset the measure, appraise and audit cached flags either if -* ima_inode_setxattr was called or based on policy, forcing -* the file to be re-evaluated. +* Reset the measure, appraise and audit cached flags either if: +* - ima_inode_setxattr was called, or +* - based on policy ("force"), or +* - based on filesystem feature flag +* forcing the file to be re-evaluated. */
Now that I think about it, it's also possible to write this patch without basing it on Mimi's patch "ima: define a new policy option named force", which is not in next-integrity yet. Should I try that?
Quoted 10 lines
security/integrity/ima/ima_main.c +1
-2if (test_and_clear_bit (IMA_CHANGE_XATTR , &iint->atomic_flags)) { iint->flags &= ~IMA_DONE_MASK ; - }else if (action &IMA_FORCE ) { + }else if (action &IMA_FORCE || inode->i_sb->s_type->fs_flags &FS_NO_IMA_CACHE ) {if (action &IMA_MEASURE ) { iint->measured_pcrs =0 ; iint->flags &= --2.13.6
--
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] ima,fuse: introduce new fs flag FS_NO_IMA_CACHE
Quoted 12 lines
security/integrity/ima/ima_main.c static int process_measurement(struct file *file, char *buf, loff_t size, · line 238
Quoted 11 lines
/*security/integrity/ima/ima_main.c +5
-3-* Reset the measure, appraise and audit cached flags either if -* ima_inode_setxattr was called or based on policy, forcing -* the file to be re-evaluated. +* Reset the measure, appraise and audit cached flags either if: +* - ima_inode_setxattr was called, or +* - based on policy ("force"), or +* - based on filesystem feature flag +* forcing the file to be re-evaluated. */
Quoted 3 lines
Now that I think about it, it's also possible to write this patch without basing it on Mimi's patch "ima: define a new policy option named force", which is not in next-integrity yet. Should I try that?
Yes, thank you. ?As you're proposing a new flag, please remember to Cc the fsdevel mailing list as well.
Mimi
Quoted 12 lines
Quoted 11 lines
if (test_and_clear_bit(IMA_CHANGE_XATTR, &iint->atomic_flags)) { iint->flags &= ~IMA_DONE_MASK;security/integrity/ima/ima_main.c +1
-2- }else if (action &IMA_FORCE ) { + }else if (action &IMA_FORCE || inode->i_sb->s_type->fs_flags &FS_NO_IMA_CACHE ) {if (action &IMA_MEASURE ) { iint->measured_pcrs =0 ; iint->flags &= --2.13.6
--
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
Hi Mimi,
Quoted 11 lines · Mimi Zohar
Quoted 5 lines · Dongsu Park
Since yesterday Alban and I have been working on a different approach that does not depend on IMA rules, nor fsmagic. Please see:
https://www.mail-archive.com/[email protected]/msg1587390.htmlIf that's ok, I'm ready to discard this patchset.
You dropped a number of people involved in this discussion and mailing lists. Please post the proposed patch inline as an RFC, cc'ing the same people, those involved in the discussion, and previous mailing lists, including LSM, integrity, and fsdevel.
Sorry about that. Starting from the patchset v2, we will add Cc correctly. Thank you also for the detailed review.
Dongsu
Quoted 4 lines
thanks,
Mimi