Received: by 10.213.65.68 with SMTP id h4csp2121863imn; Sun, 8 Apr 2018 20:14:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/Q4t3slLcEevq3Oc/MIEQlLIJ9/0cJXItRhuGo3ijGGZD0aT6GWsEa4aBy9JgXFuUPQAge X-Received: by 10.99.4.202 with SMTP id 193mr23780315pge.409.1523243668878; Sun, 08 Apr 2018 20:14:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243668; cv=none; d=google.com; s=arc-20160816; b=H7fWIhdxO5pxHrmgYKXj2gcX2ssYI3LNrT7kOASYGaxAgQ4+pHWWLBPssu1HHJNNa9 K9Hy2ip4IpafkeYr1QqHvgW06u38mD7DrESR8yzq/uiKLiKK8uoSEBMu+pSzrs4R8pOY YOf0T6nDl2SXy7ZFQJ6hVAotjMGMAPyb8oihUdz2Qliyw2YWfgyjz/wVgm4hjTKvq+cE S07uUox3le2hqL0AkkpRn9iBIoSAi5TqvbTBZv4+M7tY8e8ff2AZiNlJ+9Of7XcEvJCw wPpjozSNEk9wGP8WfVjacxn+WkfZGdtJ49Px5LHx6y5ZZ1rnpasl+4ofTciQsqdGhDQg MVbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=OT9E3LEGUidbqRABoXrCIhplwPWqQxaELiGIjstLk9Q=; b=X6UGGjzoA0MxnjrTFgGhS5PfsKd3hkoXet4AvVdasvFLjHjtWu3DFO0fxh4ehmlbqj R6skF9OYmHO0g+uMsG1eDPA5U/IpwBAep63TegCTsYIm/oCSjy3rzNeZxGTV2FOJbj2L +iBak4Zg/eyIbwwpbiOJO/GsYr/EtZCCVJlweGgNMfa34AkUA+7bo0SaP462sBxBIAnl edo6FdSXaAPO1Ar1Zy8EndjuaUtla7HcBADg2x5/ibT1nB4xU11k25E93m0aIF4ohqzT MpzntUtkTilqtq7GlBAmMRAO9kqMeTlfX1jn/ERL4CpS+Zu6k6eu4XEwqJHrb4UmDxJY Fttg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=JLJwe9R2; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7si1036163pgr.443.2018.04.08.20.13.51; Sun, 08 Apr 2018 20:14:28 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=JLJwe9R2; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753588AbeDIDGm (ORCPT + 99 others); Sun, 8 Apr 2018 23:06:42 -0400 Received: from mail-sn1nam02on0121.outbound.protection.outlook.com ([104.47.36.121]:44416 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754105AbeDIAYi (ORCPT ); Sun, 8 Apr 2018 20:24:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=OT9E3LEGUidbqRABoXrCIhplwPWqQxaELiGIjstLk9Q=; b=JLJwe9R2PrE3R8N+ZM/AK8lqTNjMz9G+J56dG8+MwkD4uMirVdhPtqr5m/Sgq/3Qx6SsBAcoRcyO54RA4cTKHbSaXfhqxSrLoXm9lapDFtZS/gSllnnykbKz7UYgVNyftJVkYkIkxzsysm49xq6P1XMIzI+8SUsCc590S7D4MPo= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0983.namprd21.prod.outlook.com (52.132.133.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:24:37 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:24:37 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: piaojun , Mark Fasheh , Joel Becker , Junxiao Bi , Joseph Qi , Changwei Ge , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 097/161] ocfs2/acl: use 'ip_xattr_sem' to protect getting extended attribute Thread-Topic: [PATCH AUTOSEL for 4.14 097/161] ocfs2/acl: use 'ip_xattr_sem' to protect getting extended attribute Thread-Index: AQHTz5ioNyOFIxBt80q0Z8r+m0QT6A== Date: Mon, 9 Apr 2018 00:21:08 +0000 Message-ID: <20180409001936.162706-97-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0983;7:Y2GOFJxqlqC9EP+wbG4odi75ale7IYna+XppRob6yX8Kxbk3IUgOfx2XZMa0fm6eDOnO4somjMUYFxVzSmkoTv/X1AXl3f1HmxwWSs0mjB40lzdmRRUHVg8jPKOlo4vduyJcjn7druKHYChwhtD9j/1wK6FBXI1jLDsvL5VgOEvdNkN4EJYpLN6+7cBxXRWpsUlZnJPdDcfhlXCeuBExjofRhdW77HQ7IGQDOcPTtC34n5JehhFZNl1uE6hT9+wG;20:1PsHXb5wbURELfmvq4hXym0Mh3AC8FAZjSVumTB37a7rEvFyG7JHom8yCPQ0KE4UdXngAgrnAmxMvnEl8oCcZ89/3e6NoXXyv9e+yXeeOcCDkEsLqfJ6iiSp3BSJs7LlLBoE3npyZzKaGq6l4lFogc3snzYWddgHc/K+bSWJhCI= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 227e61ee-3782-4b48-f20b-08d59db0470b x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0983; x-ms-traffictypediagnostic: DM5PR2101MB0983: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(50582790962513)(85827821059158)(42068640409301)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0983;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0983; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(346002)(376002)(39380400002)(366004)(199004)(189003)(478600001)(59450400001)(72206003)(10290500003)(3846002)(102836004)(6506007)(6116002)(25786009)(6436002)(66066001)(99286004)(54906003)(86612001)(6666003)(105586002)(53936002)(76176011)(316002)(486006)(7736002)(22452003)(3660700001)(86362001)(97736004)(106356001)(575784001)(8936002)(110136005)(5660300001)(11346002)(446003)(81166006)(81156014)(2906002)(8676002)(2900100001)(1076002)(39060400002)(476003)(2616005)(7416002)(10090500001)(6486002)(107886003)(36756003)(4326008)(966005)(2501003)(68736007)(186003)(305945005)(3280700002)(5250100002)(6306002)(6512007)(26005)(14454004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0983;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: lplCTfU+6gOKThZueE9GfMEhCxP54XK7vuiAOjpkwSPLRwPyB+/jMjGSlMkQeu1UBRb2VKysxxiDfgRZTpwlaWz4jHxE5f/qPYq8aPTa/sX3xZPmVNAFNdAqptow6au7eODQMk63PkjiWhYSOOnKhUQDlCA+WEbcm0/Uk5eh6aFkjb6k+dvIc/fvWc4dOLeRMQeouhSvxXiVbBqDaViEg1iDZ3qaTLrCSJhvMsMDClA45BmPPiwWc6QyhzO9PiGxOZMsJThOnT4xAdsvqfqi6dBNXy+FUdZH52yKOT0FpEzfEPoYtWFk1JUA9jxX7h5VaeK6wWrKT2hdMK67A+kDkLcZ8e8CDm3khle7D2JZgNTvwiPf+ESZHJmwFaw7vhOElaMNu9LRKSRTAYZnAXE7r8vDHvJ33V/gphhV5Gahwio= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 227e61ee-3782-4b48-f20b-08d59db0470b X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:21:08.7376 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0983 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: piaojun [ Upstream commit 16c8d569f5704a84164f30ff01b29879f3438065 ] The race between *set_acl and *get_acl will cause getting incomplete xattr data as below: processA processB ocfs2_set_acl ocfs2_xattr_set __ocfs2_xattr_set_handle ocfs2_get_acl_nolock ocfs2_xattr_get_nolock: processB may get incomplete xattr data if processA hasn't set_acl done. So we should use 'ip_xattr_sem' to protect getting extended attribute in ocfs2_get_acl_nolock(), as other processes could be changing it concurrently. Link: http://lkml.kernel.org/r/5A5DDCFF.7030001@huawei.com Signed-off-by: Jun Piao Reviewed-by: Alex Chen Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Joseph Qi Cc: Changwei Ge Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/ocfs2/acl.c | 6 ++++++ fs/ocfs2/xattr.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/fs/ocfs2/acl.c b/fs/ocfs2/acl.c index 40b5cc97f7b0..917fadca8a7b 100644 --- a/fs/ocfs2/acl.c +++ b/fs/ocfs2/acl.c @@ -311,7 +311,9 @@ struct posix_acl *ocfs2_iop_get_acl(struct inode *inode= , int type) if (had_lock < 0) return ERR_PTR(had_lock); =20 + down_read(&OCFS2_I(inode)->ip_xattr_sem); acl =3D ocfs2_get_acl_nolock(inode, type, di_bh); + up_read(&OCFS2_I(inode)->ip_xattr_sem); =20 ocfs2_inode_unlock_tracker(inode, 0, &oh, had_lock); brelse(di_bh); @@ -330,7 +332,9 @@ int ocfs2_acl_chmod(struct inode *inode, struct buffer_= head *bh) if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) return 0; =20 + down_read(&OCFS2_I(inode)->ip_xattr_sem); acl =3D ocfs2_get_acl_nolock(inode, ACL_TYPE_ACCESS, bh); + up_read(&OCFS2_I(inode)->ip_xattr_sem); if (IS_ERR(acl) || !acl) return PTR_ERR(acl); ret =3D __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode); @@ -361,8 +365,10 @@ int ocfs2_init_acl(handle_t *handle, =20 if (!S_ISLNK(inode->i_mode)) { if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) { + down_read(&OCFS2_I(dir)->ip_xattr_sem); acl =3D ocfs2_get_acl_nolock(dir, ACL_TYPE_DEFAULT, dir_bh); + up_read(&OCFS2_I(dir)->ip_xattr_sem); if (IS_ERR(acl)) return PTR_ERR(acl); } diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 5fdf269ba82e..fb0a4eec310c 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -638,9 +638,11 @@ int ocfs2_calc_xattr_init(struct inode *dir, si->value_len); =20 if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) { + down_read(&OCFS2_I(dir)->ip_xattr_sem); acl_len =3D ocfs2_xattr_get_nolock(dir, dir_bh, OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT, "", NULL, 0); + up_read(&OCFS2_I(dir)->ip_xattr_sem); if (acl_len > 0) { a_size =3D ocfs2_xattr_entry_real_size(0, acl_len); if (S_ISDIR(mode)) --=20 2.15.1