Skip to content

Commit 0817534

Browse files
pa1guptacschaufler
authored andcommitted
smackfs: Fix use-after-free in netlbl_catmap_walk()
Syzkaller reported use-after-free bug as described in [1]. The bug is triggered when smk_set_cipso() tries to free stale category bitmaps while there are concurrent reader(s) using the same bitmaps. Wait for RCU grace period to finish before freeing the category bitmaps in smk_set_cipso(). This makes sure that there are no more readers using the stale bitmaps and freeing them should be safe. [1] https://lore.kernel.org/netdev/[email protected]/ Reported-by: [email protected] Signed-off-by: Pawan Gupta <[email protected]> Signed-off-by: Casey Schaufler <[email protected]>
1 parent 6880fa6 commit 0817534

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

security/smack/smackfs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ static int smk_open_cipso(struct inode *inode, struct file *file)
831831
static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
832832
size_t count, loff_t *ppos, int format)
833833
{
834+
struct netlbl_lsm_catmap *old_cat;
834835
struct smack_known *skp;
835836
struct netlbl_lsm_secattr ncats;
836837
char mapcatset[SMK_CIPSOLEN];
@@ -920,9 +921,11 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
920921

921922
rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
922923
if (rc >= 0) {
923-
netlbl_catmap_free(skp->smk_netlabel.attr.mls.cat);
924+
old_cat = skp->smk_netlabel.attr.mls.cat;
924925
skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;
925926
skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
927+
synchronize_rcu();
928+
netlbl_catmap_free(old_cat);
926929
rc = count;
927930
/*
928931
* This mapping may have been cached, so clear the cache.

0 commit comments

Comments
 (0)