From patchwork Fri Feb 14 18:35:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 11383053 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17A3913A4 for ; Fri, 14 Feb 2020 18:38:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01BEF222C2 for ; Fri, 14 Feb 2020 18:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390707AbgBNSiw (ORCPT ); Fri, 14 Feb 2020 13:38:52 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:33659 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730491AbgBNSiB (ORCPT ); Fri, 14 Feb 2020 13:38:01 -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 1j2fqN-0000uO-MI; Fri, 14 Feb 2020 18:37:39 +0000 From: Christian Brauner To: =?utf-8?q?St=C3=A9phane_Graber?= , "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 06/28] cred: add kfs{g,u}id Date: Fri, 14 Feb 2020 19:35:32 +0100 Message-Id: <20200214183554.1133805-7-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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org After the introduction of fsid mappings we need to carefully handle single-superblock filesystems that are visible in user namespaces. This specifically concerns proc and sysfs. For those filesystems we want to continue looking up fsid in the id mappings of the relevant user namespace. We can either do this by dynamically translating between these fsids or we simply keep them around with the other creds. The latter option is not just simpler but also more performant since we don't need to do the translation from fsid mappings into id mappings on the fly. Link: https://lore.kernel.org/r/20200212145149.zohmc6d3x52bw6j6@wittgenstein Cc: Jann Horn Signed-off-by: Christian Brauner --- /* v2 */ patch added --- include/linux/cred.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/cred.h b/include/linux/cred.h index 18639c069263..604914d3fd51 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -125,6 +125,8 @@ struct cred { kgid_t egid; /* effective GID of the task */ kuid_t fsuid; /* UID for VFS ops */ kgid_t fsgid; /* GID for VFS ops */ + kuid_t kfsuid; /* UID for VFS ops for userns visible filesystems */ + kgid_t kfsgid; /* GID for VFS ops for userns visible filesystems */ unsigned securebits; /* SUID-less security management */ kernel_cap_t cap_inheritable; /* caps our children can inherit */ kernel_cap_t cap_permitted; /* caps we're permitted */ @@ -384,6 +386,8 @@ static inline void put_cred(const struct cred *_cred) #define current_sgid() (current_cred_xxx(sgid)) #define current_fsuid() (current_cred_xxx(fsuid)) #define current_fsgid() (current_cred_xxx(fsgid)) +#define current_kfsuid() (current_cred_xxx(kfsuid)) +#define current_kfsgid() (current_cred_xxx(kfsgid)) #define current_cap() (current_cred_xxx(cap_effective)) #define current_user() (current_cred_xxx(user))