Skip to content

Commit

Permalink
smackfs: Fix use-after-free in netlbl_catmap_walk()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pa1gupta authored and cschaufler committed Sep 15, 2021
1 parent 6880fa6 commit 0817534
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion security/smack/smackfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ static int smk_open_cipso(struct inode *inode, struct file *file)
static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
size_t count, loff_t *ppos, int format)
{
struct netlbl_lsm_catmap *old_cat;
struct smack_known *skp;
struct netlbl_lsm_secattr ncats;
char mapcatset[SMK_CIPSOLEN];
Expand Down Expand Up @@ -920,9 +921,11 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,

rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
if (rc >= 0) {
netlbl_catmap_free(skp->smk_netlabel.attr.mls.cat);
old_cat = skp->smk_netlabel.attr.mls.cat;
skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;
skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
synchronize_rcu();
netlbl_catmap_free(old_cat);
rc = count;
/*
* This mapping may have been cached, so clear the cache.
Expand Down

0 comments on commit 0817534

Please sign in to comment.