Received: by 10.213.65.68 with SMTP id h4csp2196199imn; Sun, 8 Apr 2018 22:14:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx49A5eNcsoWCDYxFYfq8tWp0LQyC23YELEE8O6wCBJNIHtQ++p7faFgg4GFB51CExRAIWFFs X-Received: by 10.101.89.5 with SMTP id f5mr23957868pgu.428.1523250848320; Sun, 08 Apr 2018 22:14:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523250848; cv=none; d=google.com; s=arc-20160816; b=agTiMi1a01KFjrLlfIIh+Bgyk4IGJ4yAkOpBZVYdfnU9oQ+YKXkCcAQ/VXSoDzfw0Y qTU8N3HWOmBWoqPOKdOI6941SN/K6qb1HKSmWjvdb/pYh/RuN0x02tB7cLoS/P/eqf0P BvFUOz8mt32FJeTWsFMGBx709xr0HzKy32T0ug7SJqgvEeeu/cP85Lu2wC/mWW/o+3KF JfTLGeg4Q9WoAhQMput6kKcm8EiObPBw04DWQQxAnkR047nXi/GkZScVcjMtni1SV6xp +gl4RYkY5tNxfUwxmT+s//czB8cKdz4Y0/kH+OTezNh7DivGS/J84pIBOdQzsEh7eWjX rO0Q== 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=3Rekw/VesZrQPxD3iuVTJmdfQKlxAM7Tuu3Hj2Ydo3Q=; b=ihHJVCzocHow/5lxnvlI+1YmLvSxq5oBKONYMC1EKQei17Db/B7uEmMIv2sQphqhzA UoM3SGmbbcke+DX+12B7gVhCLAuQVK/9f6klXNoqkL9BE7g9hLe/QvsY0iTWRBHe07Gm jdOg1b3VvjxnO/IOCT+8mKVheA1/RGB7jgb+Fr7Qez2kIXU+pgtl7NXR9JwKrRY/wD/K MQLlNPAJLb77SLDpIQ0s3dimKC9itmRPqnp3+W3ndrd51nRCmdPWJz8cztUQroo/WK6Y CgPDFSM9HBXtoJ3d3sXS0WlzOv2Oo8mwy+s03ZBVsFbcguB6lipK9DEduit+K//H1vdi uKZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=RDLq2x18; 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 f6si10593678pgc.670.2018.04.08.22.13.31; Sun, 08 Apr 2018 22:14:08 -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=RDLq2x18; 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 S1754185AbeDIAUO (ORCPT + 99 others); Sun, 8 Apr 2018 20:20:14 -0400 Received: from mail-bn3nam01on0124.outbound.protection.outlook.com ([104.47.33.124]:14464 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754083AbeDIATf (ORCPT ); Sun, 8 Apr 2018 20:19:35 -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=3Rekw/VesZrQPxD3iuVTJmdfQKlxAM7Tuu3Hj2Ydo3Q=; b=RDLq2x18QKDJUkSdrTQFCeH0kR0l4JIpn1a2f9PsPg66l/i+D28LJrkZlHYtTesADQZOXhU+tHihabOTRD6L2KdmPdtBZ1T3mY+s62n+2U1j53THAlsVSFS9odzit8ILJL4SJ5nb7z/FDXBtHIDn7ekwDsxJVHdFWsTGsGVCDx4= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0726.namprd21.prod.outlook.com (10.167.108.39) 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:19:28 +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:19:28 +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.15 117/189] ocfs2/acl: use 'ip_xattr_sem' to protect getting extended attribute Thread-Topic: [PATCH AUTOSEL for 4.15 117/189] ocfs2/acl: use 'ip_xattr_sem' to protect getting extended attribute Thread-Index: AQHTz5hCI0nXsI/5UkWGq+Fj2cviHQ== Date: Mon, 9 Apr 2018 00:18:18 +0000 Message-ID: <20180409001637.162453-117-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB0726;7:Ol6MTibpZ5uExzUVrBo08RzIMojZpLvpxVYoCVh0Jd2mo9VClp9brEaT3SnMX2urEcsWhaU9oMH7JlgijRz85i7R0BRQgql6PTsfMuAqs7qTVl6DRVcjgciVMAU4UwIhM8rAdttbdu1RDh1EZIUXI/Y62YHWy40h/vZ2X62q5CZ9MZtKv9gGvS//G4NhlyP3ga2xsgIOLepoWz7cyMk0xIY6JcKbrit6XdEGKg3t/H4hjCipoQZhXHuAXLTtrCt9;20:AGxlE0e08yPSrWpsuRjMhe92kkiEP+5tJlpFNPvuwpSYYwVgsqAB8aScwmxdHlUxAASaqDYRwfqR7PKet55aMvM08yCmW0qrsPQt+VsRb8GVGkj5gaQmNcqIGtRZAKq0V2/aitW1SBJm+DzBZGoxzpV7TNaiUQoBU2QOuH5Yxqw= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 5513ee63-8b7f-4b85-b053-08d59daf8f0d x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0726; x-ms-traffictypediagnostic: DM5PR2101MB0726: 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)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB0726;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0726; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(346002)(39380400002)(39860400002)(396003)(376002)(199004)(189003)(39060400002)(6306002)(6486002)(26005)(6512007)(4326008)(81166006)(6666003)(6436002)(81156014)(8676002)(97736004)(186003)(36756003)(72206003)(53936002)(107886003)(2906002)(966005)(86362001)(76176011)(7416002)(110136005)(305945005)(10090500001)(486006)(3660700001)(102836004)(5660300001)(14454004)(476003)(86612001)(446003)(99286004)(68736007)(66066001)(11346002)(54906003)(2616005)(1076002)(7736002)(5250100002)(25786009)(8936002)(478600001)(2900100001)(2501003)(3280700002)(105586002)(59450400001)(316002)(106356001)(22452003)(6506007)(3846002)(10290500003)(6116002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0726;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: xm7FAjYRIWzFhC9+ZrbDiWixQyzCVXdj4abbhpPqB264LhrW42bETkr6enSn0RaN6bVbvn7XNAGMnDZeJiw1RPZFZq3p6dNr7YEUqxVXV+Q3synSvHCn9lF+aFST7cN+R50dSuDqfluAmARy3jRXhUNZ9mxsQ4HUHzke7JO5wg4b+N8ueJ316GniyYdSJJ5qP1j8kU6FM+25JP/JQp7iHb8vzNNYQErCc1P2qGsuGJ6XzTBU1JyxBpS+QL4yedhWVG70qtCii1CkzNYDe3feoYVobmLEzhLfp8ZemKobRUdn5kaXO9ymHTVFf3CJIQTxFLMStLmQBixkqHgL4WxbsaabgXQH7j72So7sOuZjweczeVBxic0un+Y+dVYChjB3W4G9LrxIYueZ3qeJR368HgGHv71n2WIpomO2Y2EBEGk= 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: 5513ee63-8b7f-4b85-b053-08d59daf8f0d X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:18.7713 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0726 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 c5898c59d411..e358f60f25f4 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