From patchwork Mon Feb 2 07:55:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 5759661 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2BD26BF440 for ; Mon, 2 Feb 2015 07:55:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 534302012E for ; Mon, 2 Feb 2015 07:55:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4071200E1 for ; Mon, 2 Feb 2015 07:55:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932659AbbBBHzH (ORCPT ); Mon, 2 Feb 2015 02:55:07 -0500 Received: from mail-pa0-f43.google.com ([209.85.220.43]:58587 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932245AbbBBHzG (ORCPT ); Mon, 2 Feb 2015 02:55:06 -0500 Received: by mail-pa0-f43.google.com with SMTP id eu11so79214879pac.2 for ; Sun, 01 Feb 2015 23:55:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=wBE0FeF/Sf5DsdddB60obvzemiydyHZAvRCFdZXC/KM=; b=RtD/CBbUP89M9XeLKZlArj5FQxnR3gnTS2Yo3JLvAb3cdblfYgYOcXRtQbd5ZyjP3V zVCS2ll2j4+OXz4Gyv2SHSms0WfcBhanN6Eq4s9x733Cnurp/zvUkrjw1P/poIiTRkeK h1cgwWZC/0DuX5VC/avgC91CfCtHsxR1+4i1z+uxNLrzb7RJUB7PG6fcIiWyCpBM8o8V fmNeFrWcku7j/PAVkcJ6xyAMZJczXgi5haRZT6pPmrsaJG/LOP+07BM7RjwtPsQtcr/X wp+ThpkR8350vcwKGS3ivbj0sMTDGd+Ml0J4eVpYZOJM/YwbCp1ov4jCq/n5pPCc+218 IWfQ== X-Gm-Message-State: ALoCoQnWRdHskZ2QeW3F/0fTDG25UXXG740NJTX4tpPpb/goA63YmelYWNF8Wa8vVcoNOaskU+TA X-Received: by 10.70.102.100 with SMTP id fn4mr26774011pdb.163.1422863704713; Sun, 01 Feb 2015 23:55:04 -0800 (PST) Received: from mew (c-76-104-211-44.hsd1.wa.comcast.net. [76.104.211.44]) by mx.google.com with ESMTPSA id z4sm13305745pdp.93.2015.02.01.23.55.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Feb 2015 23:55:04 -0800 (PST) Date: Sun, 1 Feb 2015 23:55:02 -0800 From: Omar Sandoval To: Christoph Hellwig Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] posix_acl: fix reference leaks in posix_acl_create Message-ID: <20150202075502.GA24678@mew> References: <0d8672e771b8fc1fef94db4b40b418afc8763c2b.1422338890.git.osandov@osandov.com> <20150128170952.GB17528@lst.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150128170952.GB17528@lst.de> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Jan 28, 2015 at 06:09:52PM +0100, Christoph Hellwig wrote: > On Mon, Jan 26, 2015 at 10:16:53PM -0800, Omar Sandoval wrote: > > get_acl gets a reference which we must release in the error cases. > > > > Signed-off-by: Omar Sandoval > > Looks good, but at this point goto-based unwinding might be in order. Hi, Christoph, There are already a couple of return paths in posix_acl_create, and there are only these two error cases, so I think gotos might actually make the code more confusing. In any case, here's an idea: posix_acl: fix reference leaks in posix_acl_create get_acl gets a reference which we must release in the error cases. Signed-off-by: Omar Sandoval Reviewed-by: Christoph Hellwig diff --git a/fs/posix_acl.c b/fs/posix_acl.c index 0855f77..515d315 100644 --- a/fs/posix_acl.c +++ b/fs/posix_acl.c @@ -564,13 +564,11 @@ posix_acl_create(struct inode *dir, umode_t *mode, *acl = posix_acl_clone(p, GFP_NOFS); if (!*acl) - return -ENOMEM; + goto no_mem; ret = posix_acl_create_masq(*acl, mode); - if (ret < 0) { - posix_acl_release(*acl); - return -ENOMEM; - } + if (ret < 0) + goto no_mem_clone; if (ret == 0) { posix_acl_release(*acl); @@ -591,6 +589,12 @@ no_acl: *default_acl = NULL; *acl = NULL; return 0; + +no_mem_clone: + posix_acl_release(*acl); +no_mem: + posix_acl_release(p); + return -ENOMEM; } EXPORT_SYMBOL_GPL(posix_acl_create);