Received: by 10.192.165.148 with SMTP id m20csp529097imm; Wed, 25 Apr 2018 03:44:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx49jKyrN1OuCa8fP4FTXyZDBOQQrLXIuA/uw7Aofi8tKXPnAgvIUTH/mR5chcaE2NYRWelyS X-Received: by 2002:a17:902:71c2:: with SMTP id t2-v6mr18278217plm.243.1524653079583; Wed, 25 Apr 2018 03:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524653079; cv=none; d=google.com; s=arc-20160816; b=ZjnSXhmTxG9eS8w4ydQRFmsySrF5iw4rfOFqaglNhx9jJzUIdzA/qq3583i4UB+44y SjOenYuh9yBmwAdFV5ux2NV9Vd2KEzDJNXh2/kPaGuIw9awaOIOM6BWJ73Pd1yQklX0K +OdgJf4gpHlmun7CsujGNoXqSDZKkiK1MQvOapsWgcPRNm5HanVRaja1QnhW3SRDcf6w zz4KlxrQrwJiKGhd1dfHG0qHJoRRNLs2+2mFIfWVImUKPCqB/a5b0BG+b0e38J4ZA/vc phio6yiT4DLNx7A4KqLMG9DMQZjQe3BdYHAPb7ABo6gmBdrqYgDxl69nid3QwtJINYMy mc0w== 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 :arc-authentication-results; bh=aOnVQLtdLIdPlCmin3UPiitvWj7x67wGFqFm6dg+g24=; b=IHIew+iUf1POt+Dq7VWfUn4FBmgbrjEk00JM2hWlEMXCHyO/5yIETQRG+nK0oraHsj hAjDiWwTkylo2Co8unB4xW0l8QHXhdCIV3lL9m8ZB0TmroudaZ7sZR5k09lxXeMu3ICZ vuMN6hGHXAoqeFwBRxdb2IdNsHPWlGrZtyMRekv9XV6G6GEs7PSAPSMO3flUk9VWdSgE iTY0kwPuu8JRw4hX8wqVda6w3Kopwa75m7XaSCZchjyuLvL9FEQFlXzt627wmjX96yri /cH0MD/lE6MghaB6vj1mNwk7cR22sv6mQCPIo8dSli4huao9Q52qEQhsp3O/KwzkznZ8 asSQ== ARC-Authentication-Results: i=1; mx.google.com; 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 bg11-v6si16197731plb.171.2018.04.25.03.44.25; Wed, 25 Apr 2018 03:44:39 -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; 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 S1754208AbeDYKnX (ORCPT + 99 others); Wed, 25 Apr 2018 06:43:23 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52900 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753730AbeDYKnO (ORCPT ); Wed, 25 Apr 2018 06:43:14 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3888C266; Wed, 25 Apr 2018 10:43:13 +0000 (UTC) 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 4.14 109/183] ocfs2/acl: use ip_xattr_sem to protect getting extended attribute Date: Wed, 25 Apr 2018 12:35:29 +0200 Message-Id: <20180425103246.832974235@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@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 4.14-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 @@ -311,7 +311,9 @@ struct posix_acl *ocfs2_iop_get_acl(stru if (had_lock < 0) return ERR_PTR(had_lock); + 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); ocfs2_inode_unlock_tracker(inode, 0, &oh, had_lock); brelse(di_bh); @@ -330,7 +332,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); @@ -361,8 +365,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 @@ -638,9 +638,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))