null-ptr-deref in integrity_inode_free()
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): 20210414115055.mayc4aeonsklgwks@wittgenstein
Mimi Zohar
maintainerHi Christian,
Quoted 18 lines · Christian Brauner
Hey,
[Resending since the previous mail somehow hasn't made it onto the list.]
While working on a patch to port ecryptfs to use
clone_private_mount()I hit the splat in [1] with v5.12-rc6 (Without any of my changes.). To reproduce this you can use the config in [5]. Then run the scripts [2] and [3] in two terminals. The kernel command line was [4]:while true; do ./test.sh; done
while true; do ./test2.sh; doneand wait for [1] to appear.
The two test scripts aren't specifically designed to trigger this issue. They were stress tests for my ecryptfs
clone_private_mount()port. They just allow to trigger this issue.
Quoted 8 lines
From a very uninformed position it seemed that:
void
integrity_inode_free(struct inode *inode){ struct integrity_iint_cache *iint; if (!IS_IMA(inode)) return;
Thank you for all the details.
A builtin IMA policy wasn't specified on the boot command line. Unless a custom IMA policy is loaded, it shouldn't get beyond this
point. Before looking any farther, I would appreciate your confirming
that you've loaded a custom IMA policy. To see if a policy has been loaded, cat /sys/kernel/security/ima/policy.
thanks,
Mimi
Quoted 33 lines
write_lock(&integrity_iint_lock); iint = __integrity_iint_find(inode); ^^^^^Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
is somehow NULL?
rb_erase(&iint->rb_node, &integrity_iint_tree); write_unlock(&integrity_iint_lock); iint_free(iint); }So I've placed a
BUG_ON()in there:security/integrity/iint.c +1
-0@@ -152,6 +152,7 @@ void integrity_inode_free(struct inode *inode)write_lock (&integrity_iint_lock); iint =__integrity_iint_find (inode); +BUG_ON (!iint);rb_erase (&iint->rb_node, &integrity_iint_tree);write_unlock (&integrity_iint_lock);and indeed, I get:
[ 266.308227] ------------[ cut here ]------------ [ 266.308592] kernel BUG at security/integrity/iint.c:155! [ 266.312120] invalid opcode: 0000 [#1] PREEMPT SMP KASAN [ 266.313898] CPU: 0 PID: 5867 Comm: rm Tainted: G E 5.12.0-rc6-clone-private-mount-8a97af3f33b5 #380 [ 266.317651] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009)/LXD, BIOS 0.0.0 02/06/2015
Quoted 30 lines · Mimi Zohar
Hi Christian,
Quoted 18 lines · Christian Brauner
Hey,
[Resending since the previous mail somehow hasn't made it onto the list.]
While working on a patch to port ecryptfs to use
clone_private_mount()I hit the splat in [1] with v5.12-rc6 (Without any of my changes.). To reproduce this you can use the config in [5]. Then run the scripts [2] and [3] in two terminals. The kernel command line was [4]:while true; do ./test.sh; done
while true; do ./test2.sh; doneand wait for [1] to appear.
The two test scripts aren't specifically designed to trigger this issue. They were stress tests for my ecryptfs
clone_private_mount()port. They just allow to trigger this issue.Quoted 8 lines
From a very uninformed position it seemed that:
void
integrity_inode_free(struct inode *inode){ struct integrity_iint_cache *iint; if (!IS_IMA(inode)) return;
Quoted 7 lines
Thank you for all the details.
A builtin IMA policy wasn't specified on the boot command line. Unless a custom IMA policy is loaded, it shouldn't get beyond this
point. Before looking any farther, I would appreciate your confirming
that you've loaded a custom IMA policy. To see if a policy has been loaded, cat/sys/kernel/security/ima/policy.
Ah, interesting thank you. Here's the output:
sudo cat /sys/kernel/security/ima/policy
dont_measure fsmagic=0x9fa0
dont_measure fsmagic=0x62656572
dont_measure fsmagic=0x64626720
dont_measure fsmagic=0x1021994
dont_measure fsmagic=0x1cd1
dont_measure fsmagic=0x42494e4d
dont_measure fsmagic=0x73636673
dont_measure fsmagic=0xf97cff8c
dont_measure fsmagic=0x43415d53
dont_measure fsmagic=0x27e0eb
dont_measure fsmagic=0x63677270
dont_measure fsmagic=0x6e736673
dont_measure fsmagic=0xde5e81e4
measure func=MMAP_CHECK mask=MAY_EXEC
measure func=BPRM_CHECK mask=MAY_EXEC
measure func=FILE_CHECK mask=^MAY_READ euid=0
measure func=FILE_CHECK mask=^MAY_READ uid=0
measure func=MODULE_CHECK
measure func=FIRMWARE_CHECK
measure func=POLICY_CHECK
Hm, note that ecryptfs is not in this list so I guess ecryptfs would be measured?
Thanks for the quick reply!
Christian
Mimi Zohar
maintainerQuoted 63 lines · Christian Brauner
Quoted 30 lines · Mimi Zohar
Hi Christian,
Quoted 18 lines · Christian Brauner
Hey,
[Resending since the previous mail somehow hasn't made it onto the list.]
While working on a patch to port ecryptfs to use
clone_private_mount()I hit the splat in [1] with v5.12-rc6 (Without any of my changes.). To reproduce this you can use the config in [5]. Then run the scripts [2] and [3] in two terminals. The kernel command line was [4]:while true; do ./test.sh; done
while true; do ./test2.sh; doneand wait for [1] to appear.
The two test scripts aren't specifically designed to trigger this issue. They were stress tests for my ecryptfs
clone_private_mount()port. They just allow to trigger this issue.Quoted 8 lines
From a very uninformed position it seemed that:
void
integrity_inode_free(struct inode *inode){ struct integrity_iint_cache *iint; if (!IS_IMA(inode)) return;Quoted 7 lines
Thank you for all the details.
A builtin IMA policy wasn't specified on the boot command line. Unless a custom IMA policy is loaded, it shouldn't get beyond this
point. Before looking any farther, I would appreciate your confirming
that you've loaded a custom IMA policy. To see if a policy has been loaded, cat/sys/kernel/security/ima/policy.Ah, interesting thank you. Here's the output:
sudo cat
/sys/kernel/security/ima/policy
dont_measurefsmagic=0x9fa0
dont_measurefsmagic=0x62656572
dont_measurefsmagic=0x64626720
dont_measurefsmagic=0x1021994
dont_measurefsmagic=0x1cd1
dont_measurefsmagic=0x42494e4d
dont_measurefsmagic=0x73636673
dont_measurefsmagic=0xf97cff8c
dont_measurefsmagic=0x43415d53
dont_measurefsmagic=0x27e0eb
dont_measurefsmagic=0x63677270
dont_measurefsmagic=0x6e736673
dont_measurefsmagic=0xde5e81e4
measure func=MMAP_CHECK mask=MAY_EXEC
measure func=BPRM_CHECK mask=MAY_EXEC
measure func=FILE_CHECK mask=^MAY_READ euid=0
measure func=FILE_CHECK mask=^MAY_READ uid=0
measure func=MODULE_CHECK
measure func=FIRMWARE_CHECK
measure func=POLICY_CHECK
Quoted 2 lines
Hm, note that ecryptfs is not in this list so I guess ecryptfs would be measured?
That's the "tcb" policy, which can be specified as "policy=tcb" on the boot command line. The builtin policy rules are generic and would normally be replaced with more specific policy rules based on LSM labels.
Right, ecryptfs files are being measured.
There's somehow a race freeing the inode. The fix is straight forward. Did you want to fix it or should I?
thanks,
Mimi
A message that is not in the archive (sent off-list or not yet received): CAHrFyr67SkruTdYnRYy+OkrEh6wqz1A=DGHZLKE2b0s-_=Cb8g@mail.gmail.com
Mimi Zohar
maintainerQuoted 75 lines · Christian Brauner
Quoted 64 lines · On Wed, Apr 14, 2021, 22:21 Mimi Zohar <[email protected]> wrote:
Quoted 63 lines · Christian Brauner
Quoted 30 lines · Mimi Zohar
Hi Christian,
Quoted 18 lines · Christian Brauner
Hey,
[Resending since the previous mail somehow hasn't made it onto the list.]
While working on a patch to port ecryptfs to use
clone_private_mount()I hit the splat in [1] with v5.12-rc6 (Without any of my changes.). To reproduce this you can use the config in [5]. Then run the scripts [2] and [3] in two terminals. The kernel command line was [4]:while true; do ./test.sh; done
while true; do ./test2.sh; doneand wait for [1] to appear.
The two test scripts aren't specifically designed to trigger this issue. They were stress tests for my ecryptfs
clone_private_mount()port. They just allow to trigger this issue.Quoted 8 lines
From a very uninformed position it seemed that:
void
integrity_inode_free(struct inode *inode){ struct integrity_iint_cache *iint; if (!IS_IMA(inode)) return;Quoted 7 lines
Thank you for all the details.
A builtin IMA policy wasn't specified on the boot command line. Unless a custom IMA policy is loaded, it shouldn't get beyond this
point. Before looking any farther, I would appreciate your confirming
that you've loaded a custom IMA policy. To see if a policy has been loaded, cat/sys/kernel/security/ima/policy.Ah, interesting thank you. Here's the output:
sudo cat
/sys/kernel/security/ima/policy
dont_measurefsmagic=0x9fa0
dont_measurefsmagic=0x62656572
dont_measurefsmagic=0x64626720
dont_measurefsmagic=0x1021994
dont_measurefsmagic=0x1cd1
dont_measurefsmagic=0x42494e4d
dont_measurefsmagic=0x73636673
dont_measurefsmagic=0xf97cff8c
dont_measurefsmagic=0x43415d53
dont_measurefsmagic=0x27e0eb
dont_measurefsmagic=0x63677270
dont_measurefsmagic=0x6e736673
dont_measurefsmagic=0xde5e81e4
measure func=MMAP_CHECK mask=MAY_EXEC
measure func=BPRM_CHECK mask=MAY_EXEC
measure func=FILE_CHECK mask=^MAY_READ euid=0
measure func=FILE_CHECK mask=^MAY_READ uid=0
measure func=MODULE_CHECK
measure func=FIRMWARE_CHECK
measure func=POLICY_CHECKQuoted 7 lines
Quoted 2 lines
Hm, note that ecryptfs is not in this list so I guess ecryptfs would be measured?
That's the "tcb" policy, which can be specified as "policy=tcb" on the boot command line. The builtin policy rules are generic and would normally be replaced with more specific policy rules based on LSM labels.
Ah, thank you.
Quoted 7 lines
Quoted 4 lines
Right, ecryptfs files are being measured.
There's somehow a race freeing the inode. The fix is straight forward. Did you want to fix it or should I?
Please do fix it. I've reach eod over here. :)
You're simply going to handle the NULL case when freeing the iint?
Yes, but it would be nice to understand the race and whether this is something or has been there from the beginning.
Mimi