From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C129C4360C for ; Sun, 29 Sep 2019 17:38:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C66E21925 for ; Sun, 29 Sep 2019 17:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569778680; bh=b1pw3I7anKjMaltyEWcE2OML/koA6Q4UK/0WEWlOycg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ga7Aa2RCROS6gHw+POTQxbBJikDgyZacyxtwm7jEJ03JdAD9GtyNT5cDdkG1RCOjD A8kCaWT0CLY0pczN3Dd3GwYFgVIRE+3VFzQu40a5PYqb9V6V+ZEa8CiDzgiFxqY1pn 5BzJkZfH11dzbAGQnK19LXa45nOOvphUCCS7HyEk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729740AbfI2Rh7 (ORCPT ); Sun, 29 Sep 2019 13:37:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:49416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730898AbfI2Rgn (ORCPT ); Sun, 29 Sep 2019 13:36:43 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A3D3721A4A; Sun, 29 Sep 2019 17:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569778602; bh=b1pw3I7anKjMaltyEWcE2OML/koA6Q4UK/0WEWlOycg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=clnhs5PJqyYhH6hIRV2Q7qwJAKMZacUsHlunyezk06Ko2jESMRv2FCVoT8A7HLyYF W2u59s19TSOKXYJP1j/YsrrSMT2DtILfvZGg7x2ONiwgh7y0Z35JNaCXVOJ+5BueXJ 2iGAdzQyt4KJVr8x8Fy31+KovnACok+7R/QAjAOI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jia-Ju Bai , Casey Schaufler , Sasha Levin , linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 08/13] security: smack: Fix possible null-pointer dereferences in smack_socket_sock_rcv_skb() Date: Sun, 29 Sep 2019 13:36:18 -0400 Message-Id: <20190929173625.10003-8-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190929173625.10003-1-sashal@kernel.org> References: <20190929173625.10003-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: From: Jia-Ju Bai [ Upstream commit 3f4287e7d98a2954f20bf96c567fdffcd2b63eb9 ] In smack_socket_sock_rcv_skb(), there is an if statement on line 3920 to check whether skb is NULL: if (skb && skb->secmark != 0) This check indicates skb can be NULL in some cases. But on lines 3931 and 3932, skb is used: ad.a.u.net->netif = skb->skb_iif; ipv6_skb_to_auditdata(skb, &ad.a, NULL); Thus, possible null-pointer dereferences may occur when skb is NULL. To fix these possible bugs, an if statement is added to check skb. These bugs are found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai Signed-off-by: Casey Schaufler Signed-off-by: Sasha Levin --- security/smack/smack_lsm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index aeb3ba70f9077..19d1702aa9856 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4037,6 +4037,8 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) skp = smack_ipv6host_label(&sadd); if (skp == NULL) skp = smack_net_ambient; + if (skb == NULL) + break; #ifdef CONFIG_AUDIT smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net); ad.a.u.net->family = family; -- 2.20.1