Received: by 10.213.65.68 with SMTP id h4csp300425imn; Fri, 30 Mar 2018 21:14:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Mz1PrVyh1XCdAHN/tzj23tRrpTp/fZdohiHPeQoHYN0SUhbJhPoQIvZPZCxmmkXoCujNd X-Received: by 10.99.149.21 with SMTP id p21mr1046202pgd.154.1522469689640; Fri, 30 Mar 2018 21:14:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522469689; cv=none; d=google.com; s=arc-20160816; b=DSH88I9YU8IDewQWATTXF64FgqcW+Wdt+Ya+5ASGqlybv4KQZq7emsibOP778+TION 0gUZS5viqxAm2lpBhYr4I2YDCceH99i99iTFZhpYwWbE2WzuQPr/25LxKJX4fsy3hw0C //61zb4OWxoxfBp9F/xDCZ+tOtNfAvCtM6ycPNlSRaMut6alpLgVXNAB26+r+Bx6rubQ lRo2rEo36AmBW3rkgvDjQxaxBsZdNxVMAecQrjdsPWckVyDD1LIGPRiRYodx8C06/YKG OEfe5TR/fl/ufpCww7/fjITjgav6/2bZ7cGHXGhuKihNMwpFj7ic2MoWPRXuTYKOsnEZ 4kMA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :arc-authentication-results; bh=s6fB87tlfEuWSXaXJiai7kI17Q5iipsEgI3mEibfs2o=; b=nd4CTUzWgJ6iIJhfiaOd774AQkkF86r/DskUqcakWwSFPzAz4eXJtqQi5jt56Mtm/a PgmJK3TEq3fuvaVfFoWmrFTpGHTpmgyHB9ic7rp/ULbV6zEzDvkRJZBau6yZk0QkJv6c 1MeZy1ePvoSdUjNHHSGZSEC5L3e38eSegsNViCMLDzmJaOT6igcYbpkB4Bh2CsvAkkd9 Yi3HddDeTVgjHFH712Dx3vfrpojX1N/wEXyNvogxpouTJrncEe3SiRY3oS/j5n2YE5hX 0gAt0QVWoEzbMiSJ20Amn81DGV1ygHfhZEqkgreeG+fEHRn1oWgqud2E08d6RjMvdyPH 2vsg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8-v6si1195020plt.6.2018.03.30.21.14.17; Fri, 30 Mar 2018 21:14:49 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752240AbeCaEMi (ORCPT + 99 others); Sat, 31 Mar 2018 00:12:38 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:43303 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752059AbeCaEMf (ORCPT ); Sat, 31 Mar 2018 00:12:35 -0400 Received: from static-50-53-54-67.bvtn.or.frontiernet.net ([50.53.54.67] helo=[192.168.192.153]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1f27sW-0003wZ-RR; Sat, 31 Mar 2018 04:12:33 +0000 Subject: Re: [PATCH][next] apparmor: fix memory leak on buffer on error exit path To: Colin King , James Morris , linux-security-module@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, "Serge E . Hallyn" , linux-kernel@vger.kernel.org References: <20180327133558.13072-1-colin.king@canonical.com> From: John Johansen Organization: Canonical Message-ID: <5ddbfd4d-12f3-1cde-c080-8fde508c664f@canonical.com> Date: Fri, 30 Mar 2018 21:12:30 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180327133558.13072-1-colin.king@canonical.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/27/2018 06:35 AM, Colin King wrote: > From: Colin Ian King > > Currently on the error exit path the allocated buffer is not free'd > causing a memory leak. Fix this by kfree'ing it. > > Detected by CoverityScan, CID#1466876 ("Resource leaks") > > Fixes: 1180b4c757aa ("apparmor: fix dangling symlinks to policy rawdata after replacement") > Signed-off-by: Colin Ian King thanks Colin I've pulled it into apparmor-next > --- > security/apparmor/apparmorfs.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c > index 96bb6b73af65..949dd8a48164 100644 > --- a/security/apparmor/apparmorfs.c > +++ b/security/apparmor/apparmorfs.c > @@ -1497,8 +1497,10 @@ static char *gen_symlink_name(int depth, const char *dirname, const char *fname) > } > > error = snprintf(s, size, "raw_data/%s/%s", dirname, fname); > - if (error >= size || error < 0) > + if (error >= size || error < 0) { > + kfree(buffer); > return ERR_PTR(-ENAMETOOLONG); > + } > > return buffer; > } >