Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp706362ybi; Fri, 14 Jun 2019 01:56:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqywLnEB0pVUpqpzz3vhCULmqfqC4t3QFoCXcpCkNTGU2RbyLlqn37EqvowMqnM9zIUKUF5P X-Received: by 2002:a63:84c1:: with SMTP id k184mr32352269pgd.7.1560502567738; Fri, 14 Jun 2019 01:56:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560502567; cv=none; d=google.com; s=arc-20160816; b=nANdjVqVn+CPTaYjz9BWLLp5Ef1GNFb0i9ARbuFksNKFqtLAh5xMwHiOGXAy4uYHP4 Gyj1R9pLKlQxaNbiH/r/korHlw8emQ8K1/emN1xO8Qg+7kRrc6FMAAzWvg+XZH5SPKLL TEkEGYhOlfDoirx+Z6n5HBFCz2sZ06RnEolZ3ie5XGEp1pNskhje5I3zx+Xc6vCztEAI GgC/mL+g7F7vOH1XCDslqfA8jnA8VSqPYq3l50Nx3VfA38usGVrLDOSMppUjxjGoHyAk Tp+qIwaab/Ro9LlBI0yj4WFeTEF6E4eKvMsS8CP9/84xqVQd9RemDOfjo/VpyEk04QXp aLqg== 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; bh=jXOTx5y9lnXfzKhRHrCW/VDOH8f9Wpq0ulIqtIIgqGY=; b=UcF85OgTHmZBrrtIKYtVx432lNmnJ8usGWdeH0+xBIs23h+8EARgKL59osmvBRJlds vwH+b+EFBnbq83lLObCBksBe+qAd55VeVAdESbX/JaNDdbSywZC/15XRe0ctGoptgdX7 uY0PQHlHtAIcBER8VvIGGKFPQ+QnY2OTcnE653VxbNr0igcLKA9zlueUjNP8tiP4CAWG bTVFuCnVK41fTWhldAXoKaIXuMNGh+igLuLCoalEE6tHmv2vRaPCNsMaNKXdIAeoJuxM xJ11CCA0/sEnLx6r13lB42Y1oiImQA4a1ia9HOv5YHHhz2pHTYk2KqY0g4Ejo6rKt0/g xX/Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d11si1853937pfn.188.2019.06.14.01.55.51; Fri, 14 Jun 2019 01:56:07 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727038AbfFNIxt (ORCPT + 99 others); Fri, 14 Jun 2019 04:53:49 -0400 Received: from a.mx.secunet.com ([62.96.220.36]:58022 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbfFNIxt (ORCPT ); Fri, 14 Jun 2019 04:53:49 -0400 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id 7A72A201DA; Fri, 14 Jun 2019 10:53:47 +0200 (CEST) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uXX0zk-f0Pkv; Fri, 14 Jun 2019 10:53:47 +0200 (CEST) Received: from mail-essen-01.secunet.de (mail-essen-01.secunet.de [10.53.40.204]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 1539F200AC; Fri, 14 Jun 2019 10:53:47 +0200 (CEST) Received: from gauss2.secunet.de (10.182.7.193) by mail-essen-01.secunet.de (10.53.40.204) with Microsoft SMTP Server id 14.3.439.0; Fri, 14 Jun 2019 10:53:47 +0200 Received: by gauss2.secunet.de (Postfix, from userid 1000) id B08F33180B3C; Fri, 14 Jun 2019 10:53:46 +0200 (CEST) Date: Fri, 14 Jun 2019 10:53:46 +0200 From: Steffen Klassert To: Young Xiao <92siuyang@gmail.com> CC: , , , Subject: Re: [PATCH] af_key: Fix memory leak in key_notify_policy. Message-ID: <20190614085346.GN17989@gauss3.secunet.de> References: <1560500786-572-1-git-send-email-92siuyang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1560500786-572-1-git-send-email-92siuyang@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 14, 2019 at 04:26:26PM +0800, Young Xiao wrote: > We leak the allocated out_skb in case pfkey_xfrm_policy2msg() fails. > Fix this by freeing it on error. > > Signed-off-by: Young Xiao <92siuyang@gmail.com> > --- > 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 4af1e1d..ec414f6 100644 > --- a/net/key/af_key.c > +++ b/net/key/af_key.c > @@ -2443,6 +2443,7 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc > } > err = pfkey_xfrm_policy2msg(out_skb, xp, dir); > if (err < 0) > + kfree_skb(out_skb); > goto out; Did you test this? You need to add braces, otherwise 'goto out' will happen unconditionally. > > out_hdr = (struct sadb_msg *) out_skb->data; > @@ -2695,6 +2696,7 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr) > > err = pfkey_xfrm_policy2msg(out_skb, xp, dir); > if (err < 0) > + kfree_skb(out_skb); > return err; Same here.