From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from youngberry.canonical.com ([91.189.89.112]:58265 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727650AbeKBGx6 (ORCPT ); Fri, 2 Nov 2018 02:53:58 -0400 Received: from mail-io1-f70.google.com ([209.85.166.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gIKpy-0008Jz-7o for linux-fsdevel@vger.kernel.org; Thu, 01 Nov 2018 21:49:10 +0000 Received: by mail-io1-f70.google.com with SMTP id k3-v6so8832866ioq.8 for ; Thu, 01 Nov 2018 14:49:10 -0700 (PDT) From: Seth Forshee To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, containers@lists.linux-foundation.org, James Bottomley Subject: [RFC PATCH 4/6] shiftfs: translate uids using s_user_ns from lower fs Date: Thu, 1 Nov 2018 16:48:54 -0500 Message-Id: <20181101214856.4563-5-seth.forshee@canonical.com> In-Reply-To: <20181101214856.4563-1-seth.forshee@canonical.com> References: <20181101214856.4563-1-seth.forshee@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Do not assume that ids from the lower filesystem are from init_user_ns. Instead, translate them from that filesystem's s_user_ns and then to the shiftfs user ns. Signed-off-by: Seth Forshee --- fs/shiftfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/shiftfs.c b/fs/shiftfs.c index 556594988dd2..226c03d8588b 100644 --- a/fs/shiftfs.c +++ b/fs/shiftfs.c @@ -613,6 +613,8 @@ static int shiftfs_getattr(const struct path *path, struct kstat *stat, struct inode *reali = real->d_inode; const struct inode_operations *iop = reali->i_op; struct path newpath = { .mnt = path->dentry->d_sb->s_fs_info, .dentry = real }; + struct user_namespace *from_ns = reali->i_sb->s_user_ns; + struct user_namespace *to_ns = inode->i_sb->s_user_ns; int err = 0; if (iop->getattr) @@ -624,8 +626,8 @@ static int shiftfs_getattr(const struct path *path, struct kstat *stat, return err; /* transform the underlying id */ - stat->uid = make_kuid(inode->i_sb->s_user_ns, __kuid_val(stat->uid)); - stat->gid = make_kgid(inode->i_sb->s_user_ns, __kgid_val(stat->gid)); + stat->uid = shift_kuid(from_ns, to_ns, stat->uid); + stat->gid = shift_kgid(from_ns, to_ns, stat->gid); return 0; } -- 2.19.1