From patchwork Tue Feb 14 06:29:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 9571267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8F20360578 for ; Tue, 14 Feb 2017 06:30:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F78F28112 for ; Tue, 14 Feb 2017 06:30:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67D0D28178; Tue, 14 Feb 2017 06:30:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8FA328112 for ; Tue, 14 Feb 2017 06:30:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751858AbdBNGaA (ORCPT ); Tue, 14 Feb 2017 01:30:00 -0500 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:43158 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751635AbdBNG37 (ORCPT ); Tue, 14 Feb 2017 01:29:59 -0500 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id B20598EE142; Mon, 13 Feb 2017 22:29:58 -0800 (PST) Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8DlElClUmo-9; Mon, 13 Feb 2017 22:29:58 -0800 (PST) Received: from [153.66.254.194] (50-47-107-254.evrt.wa.frontiernet.net [50.47.107.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 256AB8EE0A4; Mon, 13 Feb 2017 22:29:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1487053798; bh=XxLycW6+64NI06gFwvb1pLz2YrczSmOXvZLxrXMnVCE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=uxCdZP7v44eUoDIcfpiFGDkNqBycsbPRw5CakaidkGsQJdjJbhKIkrlSUKK9Sma31 FNJQ1iz583v9VcVBvnJJHQvaK/A3oICe1SMIuMITqd4NnNTIEhFa7nBdHDjAxsBtfm VXyGhNv/saSZvClbksKm3psxDopobMCZV+xSvPIo= Message-ID: <1487053797.3125.75.camel@HansenPartnership.com> Subject: [PATCH 2/2] xfs: fix inode uid/gid initialization From: James Bottomley To: Christoph Hellwig , Dave Chinner Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Eric W. Biederman" , Seth Forshee Date: Mon, 13 Feb 2017 22:29:57 -0800 In-Reply-To: <1487053651.3125.72.camel@HansenPartnership.com> References: <1487008001.3125.41.camel@HansenPartnership.com> <20170213194337.GA9852@infradead.org> <20170213213416.GA15349@dastard> <20170214060809.GA21114@infradead.org> <1487053651.3125.72.camel@HansenPartnership.com> X-Mailer: Evolution 3.16.5 Mime-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I was debugging a creation failure using a vfs shifting patch set and discovered that xfs itself doesn't actually respect the superblock namespace in a couple of places (these showed up as files with the wrong ownership in my tests). The fix is to convert xfs away from hand rolling inode_init_owner() and to use the i_uid/gid_read/write functions. The rule should be that we use the i_uid/gid_read/write() functions when converting to or from the filesystem id_uid and id_gid view. Signed-off-by: James Bottomley diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index de32f0f..291a3ac 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -814,10 +814,10 @@ xfs_ialloc( if (ip->i_d.di_version == 1) ip->i_d.di_version = 2; - inode->i_mode = mode; + inode_init_owner(inode, pip ? VFS_I(pip) : NULL, mode); set_nlink(inode, nlink); - ip->i_d.di_uid = xfs_kuid_to_uid(current_fsuid()); - ip->i_d.di_gid = xfs_kgid_to_gid(current_fsgid()); + ip->i_d.di_uid = i_uid_read(inode); + ip->i_d.di_gid = i_gid_read(inode); xfs_set_projid(ip, prid); if (pip && XFS_INHERIT_GID(pip)) { @@ -1172,10 +1172,9 @@ xfs_create( /* * Make sure that we have allocated dquot(s) on disk. */ - error = xfs_qm_vop_dqalloc(dp, xfs_kuid_to_uid(current_fsuid()), - xfs_kgid_to_gid(current_fsgid()), prid, - XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, - &udqp, &gdqp, &pdqp); + error = xfs_qm_vop_dqalloc(dp, i_fsuid(VFS_I(dp)), i_fsgid(VFS_I(dp)), + prid, XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, + &udqp, &gdqp, &pdqp); if (error) return error; @@ -1347,10 +1346,9 @@ xfs_create_tmpfile( /* * Make sure that we have allocated dquot(s) on disk. */ - error = xfs_qm_vop_dqalloc(dp, xfs_kuid_to_uid(current_fsuid()), - xfs_kgid_to_gid(current_fsgid()), prid, - XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, - &udqp, &gdqp, &pdqp); + error = xfs_qm_vop_dqalloc(dp, i_fsuid(VFS_I(dp)), i_fsgid(VFS_I(dp)), + prid, XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, + &udqp, &gdqp, &pdqp); if (error) return error; diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 22c1615..306766d 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -643,8 +643,8 @@ xfs_setattr_nonsize( */ ASSERT(udqp == NULL); ASSERT(gdqp == NULL); - error = xfs_qm_vop_dqalloc(ip, xfs_kuid_to_uid(uid), - xfs_kgid_to_gid(gid), + error = xfs_qm_vop_dqalloc(ip, from_kuid(inode->i_sb->s_user_ns, uid), + from_kgid(inode->i_sb->s_user_ns, gid), xfs_get_projid(ip), qflags, &udqp, &gdqp, NULL); if (error) @@ -714,8 +714,9 @@ xfs_setattr_nonsize( olddquot1 = xfs_qm_vop_chown(tp, ip, &ip->i_udquot, udqp); } - ip->i_d.di_uid = xfs_kuid_to_uid(uid); inode->i_uid = uid; + ip->i_d.di_uid = i_uid_read(inode); + } if (!gid_eq(igid, gid)) { if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_GQUOTA_ON(mp)) { @@ -726,8 +727,8 @@ xfs_setattr_nonsize( olddquot2 = xfs_qm_vop_chown(tp, ip, &ip->i_gdquot, gdqp); } - ip->i_d.di_gid = xfs_kgid_to_gid(gid); inode->i_gid = gid; + ip->i_d.di_gid = i_gid_read(inode); } } @@ -1213,8 +1214,8 @@ xfs_setup_inode( /* make the inode look hashed for the writeback code */ hlist_add_fake(&inode->i_hash); - inode->i_uid = xfs_uid_to_kuid(ip->i_d.di_uid); - inode->i_gid = xfs_gid_to_kgid(ip->i_d.di_gid); + i_uid_write(inode, ip->i_d.di_uid); + i_gid_write(inode, ip->i_d.di_gid); switch (inode->i_mode & S_IFMT) { case S_IFBLK: diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index f2cb45e..49278e1 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -211,11 +211,9 @@ xfs_symlink( /* * Make sure that we have allocated dquot(s) on disk. */ - error = xfs_qm_vop_dqalloc(dp, - xfs_kuid_to_uid(current_fsuid()), - xfs_kgid_to_gid(current_fsgid()), prid, - XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, - &udqp, &gdqp, &pdqp); + error = xfs_qm_vop_dqalloc(dp, i_fsuid(VFS_I(dp)), i_fsgid(VFS_I(dp)), + prid, XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, + &udqp, &gdqp, &pdqp); if (error) return error;