Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C33CC433DB for ; Wed, 23 Dec 2020 08:48:58 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A16D820674 for ; Wed, 23 Dec 2020 08:48:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A16D820674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1krzpH-0000xk-Qd; Wed, 23 Dec 2020 08:48:55 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1krzpG-0000xd-5Y for linux-f2fs-devel@lists.sourceforge.net; Wed, 23 Dec 2020 08:48:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:CC:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=vcDoX4rEl+XUJIsXYCE3G3aEmLiTxTp/6RVpIiJYEqo=; b=I3wooqCQlY7zwNQivYSJI1AXBD tBjyX3Rqv4kFHKl9WFKaM2y/f1+FwCpHge0tjUZqdG7OJQuARxNBFLyUK8fyKZvbrG4aFvxJZJBob PkQrXGbD4dm+bmLPCiBHVMucNMIXFn5iR3nWyQUjlY5wqLtlzk0n9We/63iXyENQsJyY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:References:CC:To:Subject:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=vcDoX4rEl+XUJIsXYCE3G3aEmLiTxTp/6RVpIiJYEqo=; b=LyANCDl+bP53YLxlu0Zb1hqEiw TzxBQkzYQoO+zNfwPQcUo1fgjWR3vg3I2bgNxwF88BK1f6Yt3Yt9DuCKsDwwkdIYvmZKiEe+w9dfw DG72GZLs1Kiu6J4fnkGG18KQV69aLPzYVOo2zcaAjiHJs6oD6oAZus+fEBiSczSQwwiU=; Received: from szxga05-in.huawei.com ([45.249.212.191]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1krzp0-0064lm-Dl for linux-f2fs-devel@lists.sourceforge.net; Wed, 23 Dec 2020 08:48:54 +0000 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D16KW0jnbzhwjg; Wed, 23 Dec 2020 16:47:43 +0800 (CST) Received: from [10.136.114.67] (10.136.114.67) by smtp.huawei.com (10.3.19.203) with Microsoft SMTP Server (TLS) id 14.3.498.0; Wed, 23 Dec 2020 16:48:20 +0800 To: Weichao Guo , , References: <1607918093-204-1-git-send-email-guoweichao@oppo.com> <7129ad3d-cf60-2106-dcd6-783ec7470620@huawei.com> <41642a06-f629-bf5e-96b4-412473447c31@huawei.com> <16f46413-0c94-12d4-09bb-dcc26a670a7d@huawei.com> <8ca717f8-f787-c34a-4b4e-7f97b5e4d87c@oppo.com> From: Chao Yu Message-ID: <41c614ab-6937-3ff0-53e6-4c0b74fa3d56@huawei.com> Date: Wed, 23 Dec 2020 16:48:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <8ca717f8-f787-c34a-4b4e-7f97b5e4d87c@oppo.com> Content-Language: en-US X-Originating-IP: [10.136.114.67] X-CFilter-Loop: Reflected X-Headers-End: 1krzp0-0064lm-Dl Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to set inode->i_mode correctly for posix_acl_update_mode X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fh@oppo.com, Bin Shu , linux-f2fs-devel@lists.sourceforge.net Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="windows-1252"; Format="flowed" Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 2020/12/23 12:38, Weichao Guo wrote: > = > On 2020/12/23 9:14, Chao Yu wrote: >> On 2020/12/22 20:14, Weichao Guo wrote: >>> >>> On 2020/12/22 18:49, Chao Yu wrote: >>>> On 2020/12/22 17:32, Weichao Guo wrote: >>>>> >>>>> On 2020/12/22 16:24, Chao Yu wrote: >>>>>> On 2020/12/14 11:54, Weichao Guo wrote: >>>>>>> We should update the ~S_IRWXUGO part of inode->i_mode in >>>>>>> __setattr_copy, >>>>>>> because posix_acl_update_mode updates mode based on inode->i_mode, >>>>>>> which finally overwrites the ~S_IRWXUGO part of i_acl_mode with old >>>>>>> i_mode. >>>>>>> >>>>>>> Testcase to reproduce this bug: >>>>>>> 0. adduser abc >>>>>>> 1. mkfs.f2fs /dev/sdd >>>>>>> 2. mount -t f2fs /dev/sdd /mnt/f2fs >>>>>>> 3. mkdir /mnt/f2fs/test >>>>>>> 4. setfacl -m u:abc:r /mnt/f2fs/test >>>>>>> 5. chmod +s /mnt/f2fs/test >>>>>>> >>>>>>> Signed-off-by: Weichao Guo >>>>>>> Signed-off-by: Bin Shu >>>>>>> --- >>>>>>> =A0=A0=A0 fs/f2fs/file.c | 1 + >>>>>>> =A0=A0=A0 1 file changed, 1 insertion(+) >>>>>>> >>>>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >>>>>>> index 16ea10f..4d355f9 100644 >>>>>>> --- a/fs/f2fs/file.c >>>>>>> +++ b/fs/f2fs/file.c >>>>>>> @@ -850,6 +850,7 @@ static void __setattr_copy(struct inode *inode, >>>>>>> const struct iattr *attr) >>>>>>> =A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0=A0 if (!in_group_p(inode->i_gid= ) && !capable(CAP_FSETID)) >>>>>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 mode &=3D ~S_ISGID; >>>>>>> +=A0=A0=A0=A0=A0=A0=A0 inode->i_mode =3D (inode->i_mode & S_IRWXUGO= ) | (mode & >>>>>>> ~S_IRWXUGO); >>>>>> >>>>>> Sorry, I still have problem with this patch. >>>>>> >>>>>> I think this equals to inode->i_mode =3D mode; >>>>>> >>>>>> Because in chmod_common(), @mode was assigned as: >>>>>> >>>>>> newattrs.ia_mode =3D (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUG= O); >>>>> >>>>> Hi Chao, >>>>> >>>>> I think this means=A0 all bits of S_IALLUGO can be changed during >>>>> chmod(), >>>>> and i_acl_mode has >>>> >>>> Hi Weichao, >>>> >>>> Correct, >>>> >>>>> >>>>> new S_IRWXUGO bits , i_mode has old S_IRWXUGO bits. >>>> >>>> Look into acl related code again, I found what f2fs now do is trying to >>>> update i_mode and acl xattr entry atomically, so in advance updated >>>> mode >>>> will be record to i_acl_mode, and finally, it will update i_mode w/ >>>> i_acl_mode >>>> while acl entry update in path of f2fs_set_acl() - f2fs_setxattr(). >>> >>> Hi Chao, >>> >>> IMO, only the S_IRWXUGO of part of i_mode needs update with acl xattr >>> entry atomically. >> >> I don't get the point, IMO, all S_IALLUGO bits of i_mode and acl entries >> should be updated atomically. > = > Hi Chao, > = > I mean ACL is only related with user/group permissions (IIUC), it makes > sense to > = > keep the atomicity of ACL & S_IRWXUGO bits. For S_ISGID bit, why we > should keep Hi Weichao, Yeah, there is no such restriction on what order we update i_mode and acl, = my concern is to keep line with original implementation strategy of f2fs acl p= art. > = > this atomicity? It seems that even the atomicity of ACL & S_IRWXUGO bits > is not > = > considerd in EXT4. Maybe we can do better than ext4. :) Anyway your patch looks good to me, maybe I can send a separated patch to cleanup flow of acl part. Thanks, > = >> >>> >>>> >>>> In order to keep this rule, I think we need to change as below, let me >>>> know >>>> if I missed something. >>>> >>> If we change as below, "chmod +s dir" may be failed if ACL related code >>> occurs=A0 some error. However, >>> >>> this command should be successful , which is irrelevant with ACL. >> >> Will below appended change make sense to you? If posix_acl_chmod() >> failed, >> just bail out w/o updating i_mode. > = > Forget my example about "chmod +s dir", it will be executed correctly if > ACL errors > = > occur. Below change is not needed & will cause the problem in my example > if included. > = > Overall, keeping the atomicity of S_IALLUGO bits w/ ACL is enough to me. > Keeping the > = > atomicity of S_IALLUGO bits w/ ACL is also OK to me. > = > BR, > = > Weichao > = >> >> >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >> index 5bcaa68f74ad..8998fddde3e4 100644 >> --- a/fs/f2fs/file.c >> +++ b/fs/f2fs/file.c >> @@ -950,10 +950,9 @@ int f2fs_setattr(struct dentry *dentry, struct >> iattr *attr) >> >> =A0=A0=A0=A0 if (attr->ia_valid & ATTR_MODE) { >> =A0=A0=A0=A0=A0=A0=A0=A0 err =3D posix_acl_chmod(inode, f2fs_get_inode_= mode(inode)); >> -=A0=A0=A0=A0=A0=A0=A0 if (err || is_inode_flag_set(inode, FI_ACL_MODE))= { >> -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 inode->i_mode =3D F2FS_I(inode)->i_ac= l_mode; >> + >> +=A0=A0=A0=A0=A0=A0=A0 if (is_inode_flag_set(inode, FI_ACL_MODE)) >> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 clear_inode_flag(inode, FI_ACL_MOD= E); >> -=A0=A0=A0=A0=A0=A0=A0 } >> =A0=A0=A0=A0 } >> >>> >>> BR, >>> >>> Weichao >>> >>>> From: Weichao Guo >>>> Subject: [PATCH] f2fs: fix to set inode->i_mode correctly for >>>> =A0=A0posix_acl_update_mode >>>> >>>> --- >>>> =A0=A0fs/f2fs/acl.c=A0=A0 | 23 ++++++++++++++++++++++- >>>> =A0=A0fs/f2fs/xattr.c | 15 +++++++++------ >>>> =A0=A02 files changed, 31 insertions(+), 7 deletions(-) >>>> >>>> diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c >>>> index 1e5e9b1136ee..732ec10e7890 100644 >>>> --- a/fs/f2fs/acl.c >>>> +++ b/fs/f2fs/acl.c >>>> @@ -200,6 +200,27 @@ struct posix_acl *f2fs_get_acl(struct inode >>>> *inode, int type) >>>> =A0=A0=A0=A0=A0 return __f2fs_get_acl(inode, type, NULL); >>>> =A0=A0} >>>> >>>> +static int f2fs_acl_update_mode(struct inode *inode, umode_t *mode_p, >>>> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 struct posix_acl **acl) >>>> +{ >>>> +=A0=A0=A0 umode_t mode =3D inode->i_mode; >>>> +=A0=A0=A0 int error; >>>> + >>>> +=A0=A0=A0 if (is_inode_flag_set(inode, FI_ACL_MODE)) >>>> +=A0=A0=A0=A0=A0=A0=A0 mode =3D F2FS_I(inode)->i_acl_mode; >>>> + >>>> +=A0=A0=A0 error =3D posix_acl_equiv_mode(*acl, &mode); >>>> +=A0=A0=A0 if (error < 0) >>>> +=A0=A0=A0=A0=A0=A0=A0 return error; >>>> +=A0=A0=A0 if (error =3D=3D 0) >>>> +=A0=A0=A0=A0=A0=A0=A0 *acl =3D NULL; >>>> +=A0=A0=A0 if (!in_group_p(inode->i_gid) && >>>> +=A0=A0=A0=A0=A0=A0=A0 !capable_wrt_inode_uidgid(inode, CAP_FSETID)) >>>> +=A0=A0=A0=A0=A0=A0=A0 mode &=3D ~S_ISGID; >>>> +=A0=A0=A0 *mode_p =3D mode; >>>> +=A0=A0=A0 return 0; >>>> +} >>>> + >>>> =A0=A0static int __f2fs_set_acl(struct inode *inode, int type, >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 struct posix_acl *acl, struct= page *ipage) >>>> =A0=A0{ >>>> @@ -213,7 +234,7 @@ static int __f2fs_set_acl(struct inode *inode, int >>>> type, >>>> =A0=A0=A0=A0=A0 case ACL_TYPE_ACCESS: >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 name_index =3D F2FS_XATTR_INDEX_POSIX_ACL= _ACCESS; >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 if (acl && !ipage) { >>>> -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 error =3D posix_acl_update_mode(ino= de, &mode, &acl); >>>> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 error =3D f2fs_acl_update_mode(inod= e, &mode, &acl); >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (error) >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return error; >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 set_acl_inode(inode, mode); >>>> diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c >>>> index 65afcc3cc68a..2086bef6c154 100644 >>>> --- a/fs/f2fs/xattr.c >>>> +++ b/fs/f2fs/xattr.c >>>> @@ -673,7 +673,7 @@ static int __f2fs_setxattr(struct inode *inode, >>>> int index, >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 } >>>> >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 if (value && f2fs_xattr_value_same(here, = value, size)) >>>> -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 goto exit; >>>> +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 goto same; >>>> =A0=A0=A0=A0=A0 } else if ((flags & XATTR_REPLACE)) { >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 error =3D -ENODATA; >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 goto exit; >>>> @@ -738,17 +738,20 @@ static int __f2fs_setxattr(struct inode *inode, >>>> int index, >>>> =A0=A0=A0=A0=A0 if (error) >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 goto exit; >>>> >>>> -=A0=A0=A0 if (is_inode_flag_set(inode, FI_ACL_MODE)) { >>>> -=A0=A0=A0=A0=A0=A0=A0 inode->i_mode =3D F2FS_I(inode)->i_acl_mode; >>>> -=A0=A0=A0=A0=A0=A0=A0 inode->i_ctime =3D current_time(inode); >>>> -=A0=A0=A0=A0=A0=A0=A0 clear_inode_flag(inode, FI_ACL_MODE); >>>> -=A0=A0=A0 } >>>> =A0=A0=A0=A0=A0 if (index =3D=3D F2FS_XATTR_INDEX_ENCRYPTION && >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 !strcmp(name, F2FS_XATTR_NAME= _ENCRYPTION_CONTEXT)) >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 f2fs_set_encrypted_inode(inode); >>>> =A0=A0=A0=A0=A0 f2fs_mark_inode_dirty_sync(inode, true); >>>> =A0=A0=A0=A0=A0 if (!error && S_ISDIR(inode->i_mode)) >>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0 set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_C= P); >>>> + >>>> +same: >>>> +=A0=A0=A0 if (is_inode_flag_set(inode, FI_ACL_MODE)) { >>>> +=A0=A0=A0=A0=A0=A0=A0 inode->i_mode =3D F2FS_I(inode)->i_acl_mode; >>>> +=A0=A0=A0=A0=A0=A0=A0 inode->i_ctime =3D current_time(inode); >>>> +=A0=A0=A0=A0=A0=A0=A0 clear_inode_flag(inode, FI_ACL_MODE); >>>> +=A0=A0=A0 } >>>> + >>>> =A0=A0exit: >>>> =A0=A0=A0=A0=A0 kfree(base_addr); >>>> =A0=A0=A0=A0=A0 return error; >>> . >>> > . > = _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel