|
Takashi Iwai |
896711 |
From 8ed576395f6a9dbf8ce39351d00cc83e093b4598 Mon Sep 17 00:00:00 2001
|
|
Takashi Iwai |
896711 |
From: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
|
|
Takashi Iwai |
896711 |
Date: Sat, 28 Aug 2021 23:41:40 -0700
|
|
Takashi Iwai |
896711 |
Subject: [PATCH] smackfs: Fix use-after-free in netlbl_catmap_walk()
|
|
Takashi Iwai |
896711 |
Git-commit: 0817534ff9ea809fac1322c5c8c574be8483ea57
|
|
Takashi Iwai |
896711 |
Patch-mainline: v5.16-rc1
|
|
Takashi Iwai |
896711 |
References: stable-5.14.19
|
|
Takashi Iwai |
896711 |
|
|
Takashi Iwai |
896711 |
[ Upstream commit 0817534ff9ea809fac1322c5c8c574be8483ea57 ]
|
|
Takashi Iwai |
896711 |
|
|
Takashi Iwai |
896711 |
Syzkaller reported use-after-free bug as described in [1]. The bug is
|
|
Takashi Iwai |
896711 |
triggered when smk_set_cipso() tries to free stale category bitmaps
|
|
Takashi Iwai |
896711 |
while there are concurrent reader(s) using the same bitmaps.
|
|
Takashi Iwai |
896711 |
|
|
Takashi Iwai |
896711 |
Wait for RCU grace period to finish before freeing the category bitmaps
|
|
Takashi Iwai |
896711 |
in smk_set_cipso(). This makes sure that there are no more readers using
|
|
Takashi Iwai |
896711 |
the stale bitmaps and freeing them should be safe.
|
|
Takashi Iwai |
896711 |
|
|
Takashi Iwai |
896711 |
[1] https://lore.kernel.org/netdev/000000000000a814c505ca657a4e@google.com/
|
|
Takashi Iwai |
896711 |
|
|
Takashi Iwai |
896711 |
Reported-by: syzbot+3f91de0b813cc3d19a80@syzkaller.appspotmail.com
|
|
Takashi Iwai |
896711 |
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
|
|
Takashi Iwai |
896711 |
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
|
|
Takashi Iwai |
896711 |
Signed-off-by: Sasha Levin <sashal@kernel.org>
|
|
Takashi Iwai |
896711 |
Acked-by: Takashi Iwai <tiwai@suse.de>
|
|
Takashi Iwai |
896711 |
|
|
Takashi Iwai |
896711 |
---
|
|
Takashi Iwai |
896711 |
security/smack/smackfs.c | 5 ++++-
|
|
Takashi Iwai |
896711 |
1 file changed, 4 insertions(+), 1 deletion(-)
|
|
Takashi Iwai |
896711 |
|
|
Takashi Iwai |
896711 |
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
|
|
Takashi Iwai |
896711 |
index 3a75d2a8f517..9d853c0e55b8 100644
|
|
Takashi Iwai |
896711 |
--- a/security/smack/smackfs.c
|
|
Takashi Iwai |
896711 |
+++ b/security/smack/smackfs.c
|
|
Takashi Iwai |
896711 |
@@ -831,6 +831,7 @@ static int smk_open_cipso(struct inode *inode, struct file *file)
|
|
Takashi Iwai |
896711 |
static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
|
|
Takashi Iwai |
896711 |
size_t count, loff_t *ppos, int format)
|
|
Takashi Iwai |
896711 |
{
|
|
Takashi Iwai |
896711 |
+ struct netlbl_lsm_catmap *old_cat;
|
|
Takashi Iwai |
896711 |
struct smack_known *skp;
|
|
Takashi Iwai |
896711 |
struct netlbl_lsm_secattr ncats;
|
|
Takashi Iwai |
896711 |
char mapcatset[SMK_CIPSOLEN];
|
|
Takashi Iwai |
896711 |
@@ -920,9 +921,11 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
|
|
Takashi Iwai |
896711 |
|
|
Takashi Iwai |
896711 |
rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
|
|
Takashi Iwai |
896711 |
if (rc >= 0) {
|
|
Takashi Iwai |
896711 |
- netlbl_catmap_free(skp->smk_netlabel.attr.mls.cat);
|
|
Takashi Iwai |
896711 |
+ old_cat = skp->smk_netlabel.attr.mls.cat;
|
|
Takashi Iwai |
896711 |
skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;
|
|
Takashi Iwai |
896711 |
skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
|
|
Takashi Iwai |
896711 |
+ synchronize_rcu();
|
|
Takashi Iwai |
896711 |
+ netlbl_catmap_free(old_cat);
|
|
Takashi Iwai |
896711 |
rc = count;
|
|
Takashi Iwai |
896711 |
/*
|
|
Takashi Iwai |
896711 |
* This mapping may have been cached, so clear the cache.
|
|
Takashi Iwai |
896711 |
--
|
|
Takashi Iwai |
896711 |
2.26.2
|
|
Takashi Iwai |
896711 |
|