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=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 94B79C7618F for ; Fri, 26 Jul 2019 20:16:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6981522BE8 for ; Fri, 26 Jul 2019 20:16:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=azazel.net header.i=@azazel.net header.b="l2mWC2Zm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727067AbfGZUQG (ORCPT ); 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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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 '\