Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp27903pxb; Tue, 12 Jan 2021 18:59:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDK1Q2l/yVqsVF781M+VxbvQ1dcBlj02HZsuD5xisowhbZWmwWnwYX2doaa7HSEdiscmXb X-Received: by 2002:a50:fd88:: with SMTP id o8mr67324edt.386.1610506791325; Tue, 12 Jan 2021 18:59:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610506791; cv=none; d=google.com; s=arc-20160816; b=zApAyYAkW1xuSrMQzhsUWgiSJhMa5ZpRJONycAbeYQRuojAWuathjAy2o2soMG47De bKhS8Jyqg/914Z+2799k26u3yLa8yjz50hb5n1em6R1oLM8BEuIuE1mexaJsT3yB9U0b iANj/7SA2I9CjYgtOc0DVJlcn1Z8YmFQfeVgDRz3FHSaPoGN63XDAX5EiUl/JJKeWQbP tzQ47fvC+uGCSmJA6yolpl12TkSG5QjeLOHU1vqNUqPPl/zEGKtQlCUGeefBW322KcjH pAnOzoYOctNbbnNQDwZYwprsL3nf1IGmjnimjoOVk2eJ/GMHwpDaUEtlSyL+8qa95Cd0 xmcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7grI9rgCAbILA1x6rCRdHPvQ9dNN1Jef1USz8nr1v2I=; b=ryxv5aJzNP0MaR7hecvCqJI3nwg7/Y4/8O8l98LOp7rIsWsuUhtjTWzocTeNA41bjn VHyuZmyjPiX7hb9NRD3sj4iOVnX/dORsn/qoBqP/1hg7bFgBgTUGJWNqgxiyVBKyxlIy sBJS6LR6Y5ARlyKBuGvinUCsJ/bbZkdjaYVZ8RsGNkugXsYnXQCFkQkshPIumthxKU2M MgFyqrJMj9Pj0ScoNSvtD6iGnDKGctFsyBlhp9CznzsgkeudIwc6s51RldZ+w1p4bPx2 z125V+Vus9VjA9RWa/t619Y3FSii89d5RkahGpXsrC+6dyEDkQeSO1nXkwIEZ+xf6n3I S+Qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j24si293684ejd.743.2021.01.12.18.59.27; Tue, 12 Jan 2021 18:59:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394251AbhALWGD (ORCPT + 99 others); Tue, 12 Jan 2021 17:06:03 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:43187 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393942AbhALWEK (ORCPT ); Tue, 12 Jan 2021 17:04:10 -0500 Received: from ip5f5af0a0.dynamic.kabel-deutschland.de ([95.90.240.160] 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 1kzRl7-0003bd-87; Tue, 12 Jan 2021 22:03:25 +0000 From: Christian Brauner To: Alexander Viro , Christoph Hellwig , linux-fsdevel@vger.kernel.org Cc: John Johansen , James Morris , Mimi Zohar , Dmitry Kasatkin , Stephen Smalley , Casey Schaufler , Arnd Bergmann , Andreas Dilger , OGAWA Hirofumi , Geoffrey Thomas , Mrunal Patel , Josh Triplett , Andy Lutomirski , Theodore Tso , Alban Crequy , Tycho Andersen , David Howells , James Bottomley , Seth Forshee , =?UTF-8?q?St=C3=A9phane=20Graber?= , Linus Torvalds , Aleksa Sarai , Lennart Poettering , "Eric W. Biederman" , smbarber@chromium.org, Phil Estes , Serge Hallyn , Kees Cook , Todd Kjos , Paul Moore , Jonathan Corbet , containers@lists.linux-foundation.org, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, Christian Brauner , Christoph Hellwig Subject: [PATCH v5 15/42] fs: add file_user_ns() helper Date: Tue, 12 Jan 2021 23:00:57 +0100 Message-Id: <20210112220124.837960-16-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210112220124.837960-1-christian.brauner@ubuntu.com> References: <20210112220124.837960-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; i=MZF5H2APPgBbS6dalQP77IpBwjL8HOOCA8mxwD5I4mI=; m=rorofWYhlCYDsCHBmUT6ySFEXdKQZ/BhNiBUrVhD44Y=; p=donUDu8QUHywwTXuK+sEKtSO4q8ThCf0JgX/00ZRl3c=; g=56b63087ece42342c8428cabd6c7826fd940bf53 X-Patch-Sig: m=pgp; i=christian.brauner@ubuntu.com; s=0x0x91C61BC06578DCA2; b=iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCX/4YtgAKCRCRxhvAZXjcoinBAP9Zb0X yPth7UfV2DKrmKc17yNpYOz/9nCdo68TG5JthyQD/fWKi5+wXROsRJbp1i3YxlH/gCo28bVGPOR3L W/gWZAw= Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add a simple helper to retrieve the user namespace associated with the vfsmount of a file. Christoph correctly points out that this makes codepaths (e.g. ioctls) way easier to follow that would otherwise dereference via mnt_user_ns(file->f_path.mnt). In order to make file_user_ns() static inline we'd need to include mount.h in either file.h or fs.h which seems undesirable so let's simply not force file_user_ns() to be inline. Cc: David Howells Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org Suggested-by: Christoph Hellwig Signed-off-by: Christian Brauner --- /* v2 */ patch not present /* v3 */ patch not present /* v4 */ patch not present /* v5 */ patch introduced base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837 --- fs/namei.c | 6 ++++++ include/linux/fs.h | 1 + 2 files changed, 7 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index cd124e18cec5..d8dee449e92a 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -259,6 +259,12 @@ void putname(struct filename *name) __putname(name); } +struct user_namespace *file_user_ns(struct file *file) +{ + return mnt_user_ns(file->f_path.mnt); +} +EXPORT_SYMBOL(file_user_ns); + /** * check_acl - perform ACL permission checking * @mnt_userns: user namespace of the mount the inode was found from diff --git a/include/linux/fs.h b/include/linux/fs.h index ef993857682b..89e41a821bad 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2585,6 +2585,7 @@ static inline struct file *file_clone_open(struct file *file) return dentry_open(&file->f_path, file->f_flags, file->f_cred); } extern int filp_close(struct file *, fl_owner_t id); +extern struct user_namespace *file_user_ns(struct file *file); extern struct filename *getname_flags(const char __user *, int, int *); extern struct filename *getname(const char __user *); -- 2.30.0