Received: by 10.213.65.68 with SMTP id h4csp2117149imn; Sun, 8 Apr 2018 20:08:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/lXdKxRPlxk/a2caNryQ9AwAiNzIxxY1Ezr4rMtaei2lSGRCE5QirFocv44I3b6NFyYTY5 X-Received: by 10.99.5.137 with SMTP id 131mr23217912pgf.99.1523243289731; Sun, 08 Apr 2018 20:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243289; cv=none; d=google.com; s=arc-20160816; b=YfSBBeyd1ED96FrSTKcxO+lXVM+zm+R8cbol887kNIuA3/yglh5or85DnfNF6+IFs+ A8GwQjAjapyDtE+0G0ZdbVahKDRcpd0jJ3oCa6ZIt6sryrCHsWNyPPbi82hbmW0k94Yn iOagBY+DJCfFGcpqX8VuHd3ZyGb3SxTYnkPicNmwI49rBaXaswuse7T5/ug/wejnQCN+ v2uAMX/sH3vyO/emJHQu2cVY90M3DIHr6LlauFBfxDobrFZNsqiRs1U4rAn0UL3ESKNr M/27/4kQ1K575rNWs6h0qJm0XjXxlIi3ZsxSFXW6NfJcPH9Pz6KgOWTu7lDhi9NC21mM yF9A== 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=Kz0MN6+5OSMr/ZgGj2YV0iroZ5ga3SDRXB7gTzaDOIE=; b=cKEfeo7m3o3+fQs4cUoGNTjhLLtGoHJLAcHb/K7mPPJKv0mic0KOvE/Tmr3IDUdM+t TRZcJQSncyvC3nNczJjfBT7p7zd2Goz9/cM4zORhho50Yd4NDa1D8Ede+QQ/Dyqn5DqK 1DD3kbUfj3Bqv/dGjn9FVyxnpHs44h8iAE5u/axzDwcJTZVOppIAgN78OzBmZH33Izxp GcDHdo8BHCuVgIABYzGu12+UUATkqmWAgD2QzTYbcp5ndUroevXB+7OHWZLxYoYIm2cB f4YCbnGDdNImAtLoYcEr9iHOyBU7icg3JpJ4my5WDQBS4hB1EPOjQ6PKWIkgF33g4moi Q0mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=i4Y16lDN; 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 p61-v6si13381116plb.633.2018.04.08.20.07.33; Sun, 08 Apr 2018 20:08:09 -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=i4Y16lDN; 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 S1756834AbeDIBuG (ORCPT + 99 others); Sun, 8 Apr 2018 21:50:06 -0400 Received: from mail-by2nam01on0130.outbound.protection.outlook.com ([104.47.34.130]:18358 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932370AbeDIAdz (ORCPT ); Sun, 8 Apr 2018 20:33:55 -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=Kz0MN6+5OSMr/ZgGj2YV0iroZ5ga3SDRXB7gTzaDOIE=; b=i4Y16lDNi/zUPM6GsdZqn5jK0oTMey1ii8q51YHxtdHzOK4yxAu7M+ny2kzZ/nbRusrvzxDHAW4PJ1gNrl1rlhPHxHHvbE+NsxYjgnksLqT6y7WIizUbZuULPIf3LnlGbrdMijISSObxK/aPYGj09hmgBG1zYZBZvdMh80/pM/0= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0806.namprd21.prod.outlook.com (10.167.107.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:33:50 +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:33:50 +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.9 255/293] ocfs2/acl: use 'ip_xattr_sem' to protect getting extended attribute Thread-Topic: [PATCH AUTOSEL for 4.9 255/293] ocfs2/acl: use 'ip_xattr_sem' to protect getting extended attribute Thread-Index: AQHTz5lc9RYsDcpPdkyg6+/RB74WNg== Date: Mon, 9 Apr 2018 00:26:11 +0000 Message-ID: <20180409002239.163177-255-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-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;DM5PR2101MB0806;7:NARwBpRCsTinAATVVTxWOmWSTiv9ybgAm36nzXKS8Vb4wr8zS6LzyNU9E0+W2x0OXqRnbDCOvLJqoudNkBBqC/BskzQDdJLkXF3+4gOdRxHJD4WMykurPMp4TiDAcMc6LNWwT0YyxT9ni86ySwOstiEoQGjaCN5Bg9l2XyzzqZYYNa94TNFCBI62+7YhtJ3x3K1wirwmtLTqkhFvauwXOAoqb+Ue3P2RFpSj81ETs43Eo2LpEqMmv2hGIvcf6C4t;20:DJkauzBT1jRCZDSDu12G9b931IwX5wUHHp6U5S2GZzDJvCo1lmbZY0aeZPIBrgTEY3HpJbyfzDaFAcGm28yD5HSb0XrZofXd/wqwRg5giahAwHR4GK21LiMtR8l5n5+iofjRLeeAUEf9eWWVq0Gyx+Pp8H+DzNlFPtRJHmSgtCc= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 7aad3ebe-d756-4ee8-31b7-08d59db190eb x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0806; x-ms-traffictypediagnostic: DM5PR2101MB0806: 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)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB0806;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0806; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(376002)(396003)(366004)(39380400002)(199004)(189003)(2906002)(25786009)(2501003)(10290500003)(476003)(11346002)(446003)(97736004)(5250100002)(68736007)(2616005)(102836004)(6506007)(59450400001)(3846002)(3660700001)(486006)(3280700002)(305945005)(6666003)(99286004)(5660300001)(76176011)(7416002)(1076002)(186003)(26005)(7736002)(6116002)(81156014)(81166006)(86612001)(4326008)(105586002)(10090500001)(2900100001)(54906003)(22452003)(316002)(36756003)(110136005)(107886003)(8676002)(39060400002)(6436002)(478600001)(53936002)(66066001)(6486002)(6512007)(6306002)(86362001)(966005)(14454004)(72206003)(8936002)(106356001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0806;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: Ro7HC19Iu+16nRLjb6/XAnsHc6PBt3ZTjZ5NrMzll8dGROAZEF7PaAJp/5N+j9eA4E63LuVjPhetpcnETac1lj5mM4+t31nntRPw7Il5X9ZYKrDhSWI0JcUxK/zJMMvFn+duOywSH52BhieldNCEs/UwdX90aBnxnDCO24aiu/vCyBNz2GcF3W58H97alNTFJeg5wtpXWpndeleZGJJn6d05KU3rAMHl6KTk6M3sC5MxO42ZLAHb8wRh3jIdpdwk7mHQIZ/+xpQKgGdSqr7BriKahIyoK3pAJyrpQBfHdcAmldrSxynHhc9JfIYE2rOuUg/Y0ElHgbhHLSt8zUPEtidgNxkm2QzZW1+u8W+ltl7nGWAX2xciAi3GwXWSNDngas9Nx7Fqb1FbyZq7yFVoGCvVjD4i4iVuFn4phH/xk3A= 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: 7aad3ebe-d756-4ee8-31b7-08d59db190eb X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:11.9100 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0806 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 bed1fcb63088..ee8dbbae78b6 100644 --- a/fs/ocfs2/acl.c +++ b/fs/ocfs2/acl.c @@ -314,7 +314,9 @@ struct posix_acl *ocfs2_iop_get_acl(struct inode *inode= , int type) return ERR_PTR(ret); } =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(inode, 0); brelse(di_bh); @@ -333,7 +335,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); @@ -364,8 +368,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 994e3bfaca7a..01932763b4d1 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