Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp497612ybi; Fri, 26 Jul 2019 13:30:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxiNw6siJgDUxqmogDjkoM6Db/03HcURBy7mUQNsJNJvVR7+6Njcd+Gj6Fr1FfKM3qLFNgq X-Received: by 2002:a65:6815:: with SMTP id l21mr4454738pgt.146.1564173002111; Fri, 26 Jul 2019 13:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564173002; cv=none; d=google.com; s=arc-20160816; b=QpT8Hmw84fEdWtCKuIkMXd3a1/WM+3fTefsjVfaxXEa7S3ssK1FmAzn9Xg2sUf+QAc 7iSzpU5nMqgJqSCWpUwn/QVxj37GnVGG61rhH5OM7vMyMzRK1knsCXSTLRGSiGbsd7b5 xGGMD5sz9tNk0+FIn9rerVdN4W40ddTd9GPmFQZlGu+JJZ3oXOf4cp4J+EPYVRvLnnYf 3XulpUJp8k5/2d7HoxLQ3sFEuASjPFXTIyqcZB/rrheqg2BETLEiqo88byKg+QRXeM8F JeXuao1vNcHIHxOk5kjRaLjiGz28Epqd3colZQgjIiKulQHFGGmT2b86b3EhR3+EwjGb 6P8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=++d9OzFu4bcaSfReguJO8laE0J8Mf9ha36t3Tu6yPwM=; b=SoUaFlVsNJXH5csNKPIkd8vz9PyOsNItFrW6+QDmryHozb//R/DU/Ud50Kd0gWi0DF U6NFw2qxYgLb1n6zzu+yHCX/Nd7GqXzTac9rmqmx6xQGyQlsFWK1WqLX+wXbAQFzIBcG p6C040suYffYei6MHBGTn7IEvthZDzkBDfQx0r46vgchQfT2AIGWfNUNlFfoA+tct5Fa ad4jhDVEAiphpkVJeWpUSWuutkmuNVQIMtJobo7RHJGfvEG2bARS1n/sfImoHIWqeCnr FB24OlUJbelv+DLCkEndiYUSCukKxSLOK/Ep0WFQGpLkmyWSZIF04cttSLXSE0PINuHw XR8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@azazel.net header.s=20190108 header.b=l2mWC2Zm; 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=fail (p=NONE sp=REJECT dis=NONE) header.from=azazel.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x139si20442163pgx.251.2019.07.26.13.29.47; Fri, 26 Jul 2019 13:30:02 -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=fail header.i=@azazel.net header.s=20190108 header.b=l2mWC2Zm; 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=fail (p=NONE sp=REJECT dis=NONE) header.from=azazel.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbfGZUQG (ORCPT + 99 others); Fri, 26 Jul 2019 16:16:06 -0400 Received: from kadath.azazel.net ([81.187.231.250]:43578 "EHLO kadath.azazel.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbfGZUQF (ORCPT ); Fri, 26 Jul 2019 16:16:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=azazel.net; s=20190108; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=++d9OzFu4bcaSfReguJO8laE0J8Mf9ha36t3Tu6yPwM=; b=l2mWC2ZmRCzgwBpeeafFPMuXKJ mzfLPy690HuloO9JpUVs1kfuRcK6NxVGqYCSlaC8T7Hz/SBAj0x31HjsHJQg07koOrFCIk+Rrhn8p 25C+hCLrwEO/UecYoUPj9ZRcSyr3TvDI8kf8HmqpBc7vdyWhdW/6zHWmgWcXyauek9r66ZyfXEnIn 2UhQkkDStW6PnxWloxSwvDikCxu4BgJedhBzdOEcx62Sv/y1QOHgpdLdI7WglVNPNzvB3IT+jmEEA dX00S/3r/dqSEsqSK/Bf1/JPYQFvPCJkK7W4kSXPPAPGwZ2fh32lZH8XcViw/Hxr/2ncYNcrlExjH OaFlDDVA==; Received: from celephais.dreamlands ([192.168.96.3] helo=azazel.net) by kadath.azazel.net with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hr6dA-000331-Tc; Fri, 26 Jul 2019 21:15:56 +0100 Date: Fri, 26 Jul 2019 21:15:55 +0100 From: Jeremy Sowden To: Steffen Klassert Cc: Jia-Ju Bai , herbert@gondor.apana.org.au, davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: key: af_key: Fix possible null-pointer dereferences in pfkey_send_policy_notify() Message-ID: <20190726201555.GA4745@azazel.net> References: <20190724093509.1676-1-baijiaju1990@gmail.com> <20190726094514.GD14601@gauss3.secunet.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="XsQoSWH+UP9D9v3l" Content-Disposition: inline In-Reply-To: <20190726094514.GD14601@gauss3.secunet.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 192.168.96.3 X-SA-Exim-Mail-From: jeremy@azazel.net X-SA-Exim-Scanned: No (on kadath.azazel.net); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On 2019-07-26, at 11:45:14 +0200, Steffen Klassert wrote: > On Wed, Jul 24, 2019 at 05:35:09PM +0800, Jia-Ju Bai wrote: > > In pfkey_send_policy_notify(), there is an if statement on line 3081 > > to check whether xp is NULL: > > if (xp && xp->type != XFRM_POLICY_TYPE_MAIN) > > > > When xp is NULL, it is used by key_notify_policy() on line 3090: > > key_notify_policy(xp, ...) > > pfkey_xfrm_policy2msg_prep(xp) -- line 2211 > > pfkey_xfrm_policy2msg_size(xp) -- line 2046 > > for (i=0; ixfrm_nr; i++) -- line 2026 > > t = xp->xfrm_vec + i; -- line 2027 > > key_notify_policy(xp, ...) > > xp_net(xp) -- line 2231 > > return read_pnet(&xp->xp_net); -- line 534 > > Please don't quote random code lines, explain the problem instead. > > > > > Thus, possible null-pointer dereferences may occur. > > > > To fix these bugs, xp is checked before calling key_notify_policy(). > > > > These bugs are found by a static analysis tool STCheck written by > > us. > > > > Signed-off-by: Jia-Ju Bai > > --- > > net/key/af_key.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/net/key/af_key.c b/net/key/af_key.c > > index b67ed3a8486c..ced54144d5fd 100644 > > --- a/net/key/af_key.c > > +++ b/net/key/af_key.c > > @@ -3087,6 +3087,8 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc > > case XFRM_MSG_DELPOLICY: > > case XFRM_MSG_NEWPOLICY: > > case XFRM_MSG_UPDPOLICY: > > + if (!xp) > > + break; > > I think this can not happen. Who sends one of these notifications > without a pointer to the policy? I had a quick grep and found two places where km_policy_notify is passed NULL as the policy: $ grep -rn '\