From patchwork Thu Nov 1 21:48:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 10664559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E851C157A for ; Thu, 1 Nov 2018 21:49:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB3BF2C3D1 for ; Thu, 1 Nov 2018 21:49:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CED652C3D5; Thu, 1 Nov 2018 21:49:30 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 744172C3D1 for ; Thu, 1 Nov 2018 21:49:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727870AbeKBGx6 (ORCPT ); Fri, 2 Nov 2018 02:53:58 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58260 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727760AbeKBGx4 (ORCPT ); Fri, 2 Nov 2018 02:53:56 -0400 Received: from mail-io1-f72.google.com ([209.85.166.72]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gIKpw-0008Jj-Fr for linux-fsdevel@vger.kernel.org; Thu, 01 Nov 2018 21:49:08 +0000 Received: by mail-io1-f72.google.com with SMTP id q22-v6so2561436iog.9 for ; Thu, 01 Nov 2018 14:49:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WpsqCbr7w6G1e66H+z4zXCEMfE/WMPxAtYiui+F+0TQ=; b=YIHRKzLRpTrF8Hsb68R8mgTIaQHCUwDqiCLwqthzLObs7780aJae55psa0tSzo2C2t FNV1QUrlJUJ5SGG3B7ib6wMdCezTW5OFyNkg+X/8jsCkPCV3pTjB2IOtcYxhsPO4YeBs /rq2mH3ojOvJWeTmwdziEnEL69D0D2B7bVHPO104AAVpK3/HUVCGQAgH7udyq7iDbkCX RmFBNd5gtKLcAzw8ylVYDDLiiUMe5MMIk+/epmkR0018F0t+t6O59BzasuXf757CVfGR heB5jBYhb/PhD+3FBe1Yeh6V/3IYh2QIt8E/KSoWqsnFf363zyafU6v4wZJbvzXkOLR6 beJA== X-Gm-Message-State: AGRZ1gJNPu6d1Ep2IHonNdDhCCq0Pke1y6L9wYUM0b4GPwcMlvVlytau bN54Wn4ibkFnRqeyN5yuAdhp1tQ0apo2VQfziB9qVC3T2lu/l4vUmfRTSVtI1PmrUDxbHvCp+cD AFYwfywdXj31Vvrj8Hh/X5Y8v2Ia1dssHOD4ljQjs1Kg= X-Received: by 2002:a6b:abc5:: with SMTP id u188-v6mr6751446ioe.211.1541108946962; Thu, 01 Nov 2018 14:49:06 -0700 (PDT) X-Google-Smtp-Source: AJdET5fjfZ7jrynE6AvGM6JEoWp141CvRE5cDt6y0xbNn7gwywf5aXDUTjg2PXVVig5KIofZ+e7igg== X-Received: by 2002:a6b:abc5:: with SMTP id u188-v6mr6751433ioe.211.1541108946470; Thu, 01 Nov 2018 14:49:06 -0700 (PDT) Received: from localhost ([2605:a601:ac7:2a20:7c8b:4047:a2ef:69cd]) by smtp.gmail.com with ESMTPSA id x21-v6sm11574038ita.6.2018.11.01.14.49.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Nov 2018 14:49:05 -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 3/6] shiftfs: copy inode attrs up from underlying fs Date: Thu, 1 Nov 2018 16:48:53 -0500 Message-Id: <20181101214856.4563-4-seth.forshee@canonical.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181101214856.4563-1-seth.forshee@canonical.com> References: <20181101214856.4563-1-seth.forshee@canonical.com> 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 Not all inode permission checks go through the permission callback, e.g. some checks related to file capabilities. Always copy up the inode attrs to ensure these checks work as expected. Also introduce helpers helpers for shifting kernel ids from one user ns to another, as this is an operation that is going to be repeated. Signed-off-by: Seth Forshee --- fs/shiftfs.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/fs/shiftfs.c b/fs/shiftfs.c index b179a1be7bc1..556594988dd2 100644 --- a/fs/shiftfs.c +++ b/fs/shiftfs.c @@ -266,6 +266,33 @@ static int shiftfs_xattr_set(const struct xattr_handler *handler, return shiftfs_setxattr(dentry, inode, name, value, size, flags); } +static kuid_t shift_kuid(struct user_namespace *from, struct user_namespace *to, + kuid_t kuid) +{ + uid_t uid = from_kuid(from, kuid); + return make_kuid(to, uid); +} + +static kgid_t shift_kgid(struct user_namespace *from, struct user_namespace *to, + kgid_t kgid) +{ + gid_t gid = from_kgid(from, kgid); + return make_kgid(to, gid); +} + +static void shiftfs_copyattr(struct inode *from, struct inode *to) +{ + struct user_namespace *from_ns = from->i_sb->s_user_ns; + struct user_namespace *to_ns = to->i_sb->s_user_ns; + + to->i_uid = shift_kuid(from_ns, to_ns, from->i_uid); + to->i_gid = shift_kgid(from_ns, to_ns, from->i_gid); + to->i_mode = from->i_mode; + to->i_atime = from->i_atime; + to->i_mtime = from->i_mtime; + to->i_ctime = from->i_ctime; +} + static void shiftfs_fill_inode(struct inode *inode, struct dentry *dentry) { struct inode *reali; @@ -278,6 +305,7 @@ static void shiftfs_fill_inode(struct inode *inode, struct dentry *dentry) if (!reali->i_op->get_link) inode->i_opflags |= IOP_NOFOLLOW; + shiftfs_copyattr(reali, inode); inode->i_mapping = reali->i_mapping; inode->i_private = reali; set_nlink(inode, reali->i_nlink); @@ -573,7 +601,7 @@ static int shiftfs_setattr(struct dentry *dentry, struct iattr *attr) return err; /* all OK, reflect the change on our inode */ - setattr_copy(d_inode(dentry), attr); + shiftfs_copyattr(reali, d_inode(dentry)); return 0; }