Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2059150ybv; Fri, 14 Feb 2020 10:39:03 -0800 (PST) X-Google-Smtp-Source: APXvYqyCw/3P2d0ihkMwWRVnMC5yQ9q3TwmZTwEiqZXrx8Z2507WFB/8KOyWhXTAYVZh43A+QELW X-Received: by 2002:aca:c415:: with SMTP id u21mr2856526oif.49.1581705543556; Fri, 14 Feb 2020 10:39:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581705543; cv=none; d=google.com; s=arc-20160816; b=Y+LsftW/9dTbTm+tG6Dih0Oh0W+uektV8oNC2Mkppz0nq7XbqMhb9JwKzv5BbUlJ5j 2biC4JyepbJN/EnQXAnDKBzGzr/DOkMlmj5AnUuSmawksJwZvXcEkuMHN/jk/39KJ6BD fqD0TVXtOBAX7EPFzVk9OO//FNl2WUMfDbJO0pBLWOucn6uFRBcx9/LyRcrLCAioqxGS F8YBqVii89Pcz2JhEO7sylblkynSijYKHSjEYgbEEdXZuOt4ux2+unUSMyx99jOEmqoO V5T9Qaq6sTJ1fiQEEjiSt+0zJiymRRD2B9rdjEoigTqThROLOxd97jgmKQVtOWQSs27a dNoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Z+BVo32deo1TPezYDm/JAplIkCCdxzMIlTsKElpdukw=; b=Vg+IWAama66KYvMHB+n7cUj7eDya+kv+tXavLOLg5kb+zw6uzfWdxGJ9YhFxbnhhAb vuYtk5y4KG4RtKzbbgsQ+DaqCYqa/7XUPjr9SEh8gEsJmxHQrSviEpV4irXVsENG8YVQ aqFm/Lf7UjIyQ+LpOeBaZkEVC51EQcr09KJk0aN4Utsg5EIywkuhgHBK6mb12PERw78T RpLfPU555abUSPWub6JbQCY6oxJFbQ/kGi5VRgALJ23CxBZcCJlznU1YE57/spSRrbwl VkciNyMDJKrXV4CMAdj8owG6cjl6oLbWET0z38zeaNLVfqbJ/YaP23GavORNg98FLwOd YM/g== 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 q65si2882269oic.123.2020.02.14.10.38.51; Fri, 14 Feb 2020 10:39:03 -0800 (PST) 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 S1730746AbgBNSiK (ORCPT + 99 others); Fri, 14 Feb 2020 13:38:10 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:33722 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389468AbgBNSiJ (ORCPT ); Fri, 14 Feb 2020 13:38:09 -0500 Received: from ip5f5bf7ec.dynamic.kabel-deutschland.de ([95.91.247.236] helo=wittgenstein.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j2fqd-0000uO-Bq; Fri, 14 Feb 2020 18:37:55 +0000 From: Christian Brauner To: =?UTF-8?q?St=C3=A9phane=20Graber?= , "Eric W. Biederman" , Aleksa Sarai , Jann Horn Cc: smbarber@chromium.org, Seth Forshee , Alexander Viro , Alexey Dobriyan , Serge Hallyn , James Morris , Kees Cook , Jonathan Corbet , Phil Estes , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, containers@lists.linux-foundation.org, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org, Christian Brauner Subject: [PATCH v2 18/28] capability: privileged_wrt_inode_uidgid(): handle fsid mappings Date: Fri, 14 Feb 2020 19:35:44 +0100 Message-Id: <20200214183554.1133805-19-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200214183554.1133805-1-christian.brauner@ubuntu.com> References: <20200214183554.1133805-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Switch privileged_wrt_inode_uidgid() to lookup fsids in the fsid mappings. If no fsid mappings are setup the behavior is unchanged, i.e. fsids are looked up in the id mappings. Filesystems that share a superblock in all user namespaces they are mounted in will retain their old semantics even with the introduction of fsidmappings. Signed-off-by: Christian Brauner --- /* v2 */ unchanged --- kernel/capability.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/capability.c b/kernel/capability.c index 1444f3954d75..2b0c1dc992e2 100644 --- a/kernel/capability.c +++ b/kernel/capability.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include /* * Leveraged for setting/resetting capabilities @@ -486,8 +488,12 @@ EXPORT_SYMBOL(file_ns_capable); */ bool privileged_wrt_inode_uidgid(struct user_namespace *ns, const struct inode *inode) { - return kuid_has_mapping(ns, inode->i_uid) && - kgid_has_mapping(ns, inode->i_gid); + if (is_userns_visible(inode->i_sb->s_iflags)) + return kuid_has_mapping(ns, inode->i_uid) && + kgid_has_mapping(ns, inode->i_gid); + + return kfsuid_has_mapping(ns, inode->i_uid) && + kfsgid_has_mapping(ns, inode->i_gid); } /** -- 2.25.0