Netdev Archive on
help / color / mirror / Atom feed
* [PATCH] smackfs: Fix use-after-free in netlbl_catmap_walk()
@ 2021-09-01 23:18 Pawan Gupta
  0 siblings, 0 replies; only message in thread
From: Pawan Gupta @ 2021-09-01 23:18 UTC (permalink / raw)
  To: Casey Schaufler
  Cc: James Morris, Serge E. Hallyn, linux-security-module,
	linux-kernel, davem, kuba, syzbot+3f91de0b813cc3d19a80, netdev

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 readers using those 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 is safe.


Signed-off-by: Pawan Gupta <>
 security/smack/smackfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 3a75d2a8f517..9d853c0e55b8 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -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];
@@ -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->;
+		old_cat = skp->;
 		skp-> =;
 		skp-> =;
+		synchronize_rcu();
+		netlbl_catmap_free(old_cat);
 		rc = count;
 		 * This mapping may have been cached, so clear the cache.

base-commit: 7d2a07b769330c34b4deabeed939325c77a7ec2f

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-01 23:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01 23:18 [PATCH] smackfs: Fix use-after-free in netlbl_catmap_walk() Pawan Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).