From patchwork Tue Feb 18 14:33:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 11388683 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 11EC0924 for ; Tue, 18 Feb 2020 14:36:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EFF9E21D56 for ; Tue, 18 Feb 2020 14:36:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727786AbgBROgX (ORCPT ); Tue, 18 Feb 2020 09:36:23 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:53041 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726856AbgBROfj (ORCPT ); Tue, 18 Feb 2020 09:35:39 -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 1j43xw-0000fF-2o; Tue, 18 Feb 2020 14:35:12 +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 v3 08/25] cred: add kfs{g,u}id Date: Tue, 18 Feb 2020 15:33:54 +0100 Message-Id: <20200218143411.2389182-9-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200218143411.2389182-1-christian.brauner@ubuntu.com> References: <20200218143411.2389182-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 /* v3 */ unchanged --- 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))