Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBB43C433EF for ; Wed, 24 Nov 2021 12:22:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244313AbhKXMXQ (ORCPT ); Wed, 24 Nov 2021 07:23:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:36036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243522AbhKXMSS (ORCPT ); Wed, 24 Nov 2021 07:18:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 45A6C6115B; Wed, 24 Nov 2021 12:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637755890; bh=e2Jilp331rr99Ef88AIlDbGBjY/CT9vxaixomPDloSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GTDB8kryTJiSykfVcrLHgaPjtUBw+66mVTNAMe6crX0oqadNfcIQx5aAoLdoW8lIj EMdMfb+YBpFH1JzFZd4L+IAadNtf2eBM+U/tZDKnO/NUfvweJVJnslg6mCTt/88i+4 l+NklJGoOm5oEQe5rXEvWf/BIRW9LUR7B9+5g9Us= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+3f91de0b813cc3d19a80@syzkaller.appspotmail.com, Pawan Gupta , Casey Schaufler , Sasha Levin Subject: [PATCH 4.9 062/207] smackfs: Fix use-after-free in netlbl_catmap_walk() Date: Wed, 24 Nov 2021 12:55:33 +0100 Message-Id: <20211124115705.935793196@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124115703.941380739@linuxfoundation.org> References: <20211124115703.941380739@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pawan Gupta [ Upstream commit 0817534ff9ea809fac1322c5c8c574be8483ea57 ] 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/000000000000a814c505ca657a4e@google.com/ Reported-by: syzbot+3f91de0b813cc3d19a80@syzkaller.appspotmail.com Signed-off-by: Pawan Gupta Signed-off-by: Casey Schaufler Signed-off-by: Sasha Levin --- 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 966d30bf2e388..e26e7fbb89657 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -854,6 +854,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]; @@ -943,9 +944,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; } -- 2.33.0