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=-3.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 7DE14C3815B for ; Mon, 20 Apr 2020 12:51:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E7C6206D4 for ; Mon, 20 Apr 2020 12:51:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HQwlnt3B" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbgDTMv5 (ORCPT ); Mon, 20 Apr 2020 08:51:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:28334 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726723AbgDTMvv (ORCPT ); Mon, 20 Apr 2020 08:51:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587387110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qI4LH96Te2D61UkMMiu56eI+whpozLCjxv2Sx2J1tLs=; b=HQwlnt3BGgNhDPFtbUWCR8ejXgm7dyvBoqwhR1Xord4cyNXZxG5fKz2CCeguBwCvf1w/zM krINWkyUau/uYUCNLLUYt/M2rupgZM3BSSI/Optp+8nSJIUlyAbvf2wCxtT6w85GJWqU8n 804i+h/GFowqaUiW7dHEPhW1TUqx0fs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-358-Ml-2KNMWM828K23lPn3ExQ-1; Mon, 20 Apr 2020 08:51:48 -0400 X-MC-Unique: Ml-2KNMWM828K23lPn3ExQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 162BF1005510; Mon, 20 Apr 2020 12:51:47 +0000 (UTC) Received: from max.home.com (ovpn-114-63.ams2.redhat.com [10.36.114.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5EB15DA7C; Mon, 20 Apr 2020 12:51:43 +0000 (UTC) From: Andreas Gruenbacher To: Trond Myklebust , "akpm@osdl.org" , "xiyuyang19@fudan.edu.cn" , "linux-nfs@vger.kernel.org" , "anna.schumaker@netapp.com" , "okir@suse.de" , "linux-kernel@vger.kernel.org" Cc: Andreas Gruenbacher , "tanxin.ctf@gmail.com" , "yuanxzhang@fudan.edu.cn" , "kjlu@umn.edu" Subject: Re: [PATCH] nfs: Fix potential posix_acl refcnt leak in nfs3_set_acl Date: Mon, 20 Apr 2020 14:51:41 +0200 Message-Id: <20200420125141.18002-1-agruenba@redhat.com> In-Reply-To: <7b95f2ac1e65635dcb160ca20e798d95b7503e49.camel@hammerspace.com> References: <1587361410-83560-1-git-send-email-xiyuyang19@fudan.edu.cn> <7b95f2ac1e65635dcb160ca20e798d95b7503e49.camel@hammerspace.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Mo., 20. Apr. 2020 um 14:15 Uhr schrieb Trond Myklebust : > I don't really see any alternative to adding a 'dfalloc' to track the > allocated dfacl separately. Something like the attached patch should work as well. Thanks, Andreas --- fs/nfs/nfs3acl.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c index c5c3fc6e6c60..f1581f11c220 100644 --- a/fs/nfs/nfs3acl.c +++ b/fs/nfs/nfs3acl.c @@ -253,37 +253,41 @@ int nfs3_proc_setacls(struct inode *inode, struct p= osix_acl *acl, =20 int nfs3_set_acl(struct inode *inode, struct posix_acl *acl, int type) { - struct posix_acl *alloc =3D NULL, *dfacl =3D NULL; + struct posix_acl *orig =3D acl, *dfacl =3D NULL; int status; =20 if (S_ISDIR(inode->i_mode)) { switch(type) { case ACL_TYPE_ACCESS: - alloc =3D dfacl =3D get_acl(inode, ACL_TYPE_DEFAULT); - if (IS_ERR(alloc)) - goto fail; + dfacl =3D get_acl(inode, ACL_TYPE_DEFAULT); + status =3D PTR_ERR(dfacl); + if (IS_ERR(dfacl)) + goto out; break; =20 case ACL_TYPE_DEFAULT: dfacl =3D acl; - alloc =3D acl =3D get_acl(inode, ACL_TYPE_ACCESS); - if (IS_ERR(alloc)) - goto fail; + acl =3D get_acl(inode, ACL_TYPE_ACCESS); + status =3D PTR_ERR(acl); + if (IS_ERR(acl)) + goto out; break; } } =20 if (acl =3D=3D NULL) { - alloc =3D acl =3D posix_acl_from_mode(inode->i_mode, GFP_KERNEL); - if (IS_ERR(alloc)) - goto fail; + acl =3D posix_acl_from_mode(inode->i_mode, GFP_KERNEL); + status =3D PTR_ERR(acl); + if (IS_ERR(acl)) + goto out; } status =3D __nfs3_proc_setacls(inode, acl, dfacl); - posix_acl_release(alloc); +out: + if (acl !=3D orig) + posix_acl_release(acl); + if (dfacl !=3D orig) + posix_acl_release(dfacl); return status; - -fail: - return PTR_ERR(alloc); } =20 const struct xattr_handler *nfs3_xattr_handlers[] =3D { base-commit: ae83d0b416db002fe95601e7f97f64b59514d936 --=20 2.25.3