Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2528388imm; Mon, 28 May 2018 09:48:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJioU4MY5EUTxN4j3/2KlnD7++57f7MVTFoN+/gU6VtXfcKqNxmWHpfXSCA7bLrAY6hmMvZ X-Received: by 2002:a63:a00a:: with SMTP id r10-v6mr4456991pge.222.1527526100793; Mon, 28 May 2018 09:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527526100; cv=none; d=google.com; s=arc-20160816; b=bQtJ4fU8lEP+kfVvgM2VESZwEQLJBK4IZelLxkF1Q89zjhFFAc2nE1kftHrc7TjBFc iF3PnCYZgLZHDQgIASeIUiFn93uUczmgRVDkMkPpAwKbpBG5GnlrN5Gl2RihjVsyBY7T Ei/H+Wrr8tZToXUWdbjJuGtr7xxav4iurkTvX1FtxLEr3+1GcM5qWOkIsraNZ+1J5O3A nVkNa7d271o8BhyHJ5jS+yMZXUyyNfPTc1uZItJDne669YGzR7QI3yEKK8mZeEP2Dl2w YKaL8xvkNG5MYy9sWOpeAEjw5MEAukTrxelC4zrmY7IfTddpfZLnIIJ9WStb1bnzCVkq HBxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=TJ36NyhK7c2zhDmu8ue5Nq2Q/yQ3F2BMPy2bFpSTS6U=; b=Lcveyg9+NvupTrG8E3moay2mLr7IRHdc/MfqktYOa1u/UqQ+D/3DQiMk+oxPc0APQP oBEPS75L/i2iKdtiN6KAns0QtC8M74Vtx1CRXU8NJFxqga9YFFqoegiYXnI5YZgoYNsU +nOx5mGAQYBTFHFYGUECJT5PYtZ4b0DwLMW8TsYhrQnoZUQPYQnr4go2x+A6qpHFvBjb rTtdmIfDEqLLIeNUQ3gKmsAUbE7TLFUtaS8pEASyLgL0lwoHU9dXjgNemhYIOFRgZDqL mnqcuVBxpBTlRygReat/SDBVhiSNE3NZqPrRyhtfvFWKy1vsV3kxN9bvjsZoyXGMIopP KOVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Z9ZFtYcV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m64-v6si30647600pfm.0.2018.05.28.09.48.06; Mon, 28 May 2018 09:48:20 -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=@kernel.org header.s=default header.b=Z9ZFtYcV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754967AbeE1KG6 (ORCPT + 99 others); Mon, 28 May 2018 06:06:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:54802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754767AbeE1KGv (ORCPT ); Mon, 28 May 2018 06:06:51 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DED26208A0; Mon, 28 May 2018 10:06:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502011; bh=QXF+G5f84lQJYvb0ThjLdHq0hlvFZgDLvDCx0n/615c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z9ZFtYcVUDytkMhHkU5kmtCRM/0X8vAfazemSMtd0tDjlmPigEIzLOon2rekWPrBV 4VjzYru6Q1f2wqDqE12Lzufb4KU6K6+mJK50tNTSVzXoRhGOJNQAkCezqFNqysBr1T gAazImGGPzIP3NBDOjYUIbNjENM4BB4dTWvGxkW0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jun Piao , Alex Chen , Mark Fasheh , Joel Becker , Junxiao Bi , Joseph Qi , Changwei Ge , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 3.18 028/185] ocfs2/acl: use ip_xattr_sem to protect getting extended attribute Date: Mon, 28 May 2018 12:01:09 +0200 Message-Id: <20180528100052.273625112@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/acl.c | 6 ++++++ fs/ocfs2/xattr.c | 2 ++ 2 files changed, 8 insertions(+) --- a/fs/ocfs2/acl.c +++ b/fs/ocfs2/acl.c @@ -300,7 +300,9 @@ struct posix_acl *ocfs2_iop_get_acl(stru if (ret < 0) return ERR_PTR(ret); + down_read(&OCFS2_I(inode)->ip_xattr_sem); acl = ocfs2_get_acl_nolock(inode, type, di_bh); + up_read(&OCFS2_I(inode)->ip_xattr_sem); brelse(di_bh); @@ -319,7 +321,9 @@ int ocfs2_acl_chmod(struct inode *inode, if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) return 0; + down_read(&OCFS2_I(inode)->ip_xattr_sem); acl = 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 = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode); @@ -350,8 +354,10 @@ int ocfs2_init_acl(handle_t *handle, if (!S_ISLNK(inode->i_mode)) { if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) { + down_read(&OCFS2_I(dir)->ip_xattr_sem); acl = 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); } --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -645,9 +645,11 @@ int ocfs2_calc_xattr_init(struct inode * si->value_len); if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) { + down_read(&OCFS2_I(dir)->ip_xattr_sem); acl_len = 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 = ocfs2_xattr_entry_real_size(0, acl_len); if (S_ISDIR(mode))