Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3004343yba; Mon, 22 Apr 2019 17:37:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjXDBFTGScYv5/dn0E2ghOnT1IToQR1BIHg/6lP+WfLqRTGvKKGrfjd3KTTxQJ4KhLVfoE X-Received: by 2002:a17:902:20cb:: with SMTP id v11mr23156976plg.324.1555979834007; Mon, 22 Apr 2019 17:37:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555979834; cv=none; d=google.com; s=arc-20160816; b=bL3vfWJ/q6iaNLdgbYY3ZWuupMeFrDvQCdy3RWVMJoW21ws8jQ5NltRoOS+4J9DlSd gRqdL+pBNuFeTNNPVN7uX6ZCt1Tibwp5PTHEpSJaS1W9cQmtgY11KqEqWRshdqZPXrZx PD7vJJUG5RrtYcQ3tTgpWG9HhmBVckfzPPHm865aqOWiePtUfI99Sxs3wkXWywFSyBoy ad0XNpljB53OPXLAswpsJanSkqul+4YXKSGNkdltTip+rb4jMT3Cc1pRtd4YhgAEhKIr Z5JNGicKFJRJgDE9hX2xHjgZ3vBm6hZ1VwGMChCbFV/FtOOaTRrnIjKH5WaLLxuju3vG nuVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3hwzODhR+vqR8sK1oP3mfdhzkFNj8iMJmAJ48Hspt6I=; b=t/OUIJX6/jAPjvSFMBZZmTmpbhYqXGtq1l9a5oD+IIjFiwWawTOi7Eln3Hdm5rU7c6 Q2J36Jo0m+uNUcGchCGl82hHgZJOD5DMuhVK1EOluSb0eF3yWM5cRlSQeKYXu119PU3C tibv08x63X79kKof/bXaxmHRQcBkuJ5DK/yXppic/Y7bY2kcxqdjnvRab3iOUs5irgMl 7T6rp/Dp2lsX4fszuTxTgj6lP0FHhuVfIMTpTksNAcXVgC2rzq3EAvSGCny3oBVu03Bl E0oIBrpsb6UAnYYNcoU9BdulEYXNAt5Mv+G3qwLJaStR117MloxDixw18SJ4YQz17KJU 87+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bRYqMi2p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u71si13478427pgd.147.2019.04.22.17.36.58; Mon, 22 Apr 2019 17:37:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bRYqMi2p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732594AbfDVUKm (ORCPT + 99 others); Mon, 22 Apr 2019 16:10:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:42870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728848AbfDVTm3 (ORCPT ); Mon, 22 Apr 2019 15:42:29 -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 C2AFA2075A; Mon, 22 Apr 2019 19:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962148; bh=szBkXxqiqCEEnOvkzWxbI2WmligjzE5ZDcccd/LXTqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bRYqMi2pdZAZBs8ZTX5C1LtDCOnYaIZtSac6rcPtyR4+0O6Mj1W9iymvPdIgekZdw SHKjpVUSw7WXQm7kUFKz68TpmmxVypNPEQ9+75woSgrH6ldjUQScxh3DmBgZy7JjV8 LS3rTphJnym355J+Kkt5ugv/eFJkHv9kznzt+vG0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kangjie Lu , Pablo Neira Ayuso , Sasha Levin , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 19/98] netfilter: ip6t_srh: fix NULL pointer dereferences Date: Mon, 22 Apr 2019 15:40:46 -0400 Message-Id: <20190422194205.10404-19-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kangjie Lu [ Upstream commit 6d65561f3d5ec933151939c543d006b79044e7a6 ] skb_header_pointer may return NULL. The current code dereference its return values without a NULL check. The fix inserts the checks to avoid NULL pointer dereferences. Fixes: 202a8ff545cc ("netfilter: add IPv6 segment routing header 'srh' match") Signed-off-by: Kangjie Lu Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin (Microsoft) --- net/ipv6/netfilter/ip6t_srh.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/ipv6/netfilter/ip6t_srh.c b/net/ipv6/netfilter/ip6t_srh.c index 1059894a6f4c..4cb83fb69844 100644 --- a/net/ipv6/netfilter/ip6t_srh.c +++ b/net/ipv6/netfilter/ip6t_srh.c @@ -210,6 +210,8 @@ static bool srh1_mt6(const struct sk_buff *skb, struct xt_action_param *par) psidoff = srhoff + sizeof(struct ipv6_sr_hdr) + ((srh->segments_left + 1) * sizeof(struct in6_addr)); psid = skb_header_pointer(skb, psidoff, sizeof(_psid), &_psid); + if (!psid) + return false; if (NF_SRH_INVF(srhinfo, IP6T_SRH_INV_PSID, ipv6_masked_addr_cmp(psid, &srhinfo->psid_msk, &srhinfo->psid_addr))) @@ -223,6 +225,8 @@ static bool srh1_mt6(const struct sk_buff *skb, struct xt_action_param *par) nsidoff = srhoff + sizeof(struct ipv6_sr_hdr) + ((srh->segments_left - 1) * sizeof(struct in6_addr)); nsid = skb_header_pointer(skb, nsidoff, sizeof(_nsid), &_nsid); + if (!nsid) + return false; if (NF_SRH_INVF(srhinfo, IP6T_SRH_INV_NSID, ipv6_masked_addr_cmp(nsid, &srhinfo->nsid_msk, &srhinfo->nsid_addr))) @@ -233,6 +237,8 @@ static bool srh1_mt6(const struct sk_buff *skb, struct xt_action_param *par) if (srhinfo->mt_flags & IP6T_SRH_LSID) { lsidoff = srhoff + sizeof(struct ipv6_sr_hdr); lsid = skb_header_pointer(skb, lsidoff, sizeof(_lsid), &_lsid); + if (!lsid) + return false; if (NF_SRH_INVF(srhinfo, IP6T_SRH_INV_LSID, ipv6_masked_addr_cmp(lsid, &srhinfo->lsid_msk, &srhinfo->lsid_addr))) -- 2.19.1