From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751341AbdEJAk3 (ORCPT ); Tue, 9 May 2017 20:40:29 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:57983 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750939AbdEJAk1 (ORCPT ); Tue, 9 May 2017 20:40:27 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Andrei Vagin Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, criu@openvz.org, Linux Containers References: <20170509231938.6467-1-avagin@openvz.org> Date: Tue, 09 May 2017 19:34:00 -0500 In-Reply-To: <20170509231938.6467-1-avagin@openvz.org> (Andrei Vagin's message of "Tue, 9 May 2017 16:19:38 -0700") Message-ID: <87k25psg7b.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1d8Ffw-0006oQ-4x;;;mid=<87k25psg7b.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=97.121.81.159;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18I7t77AutuXCpH7n/WfQK3SBoMQZTFQ7c= X-SA-Exim-Connect-IP: 97.121.81.159 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Andrei Vagin X-Spam-Relay-Country: X-Spam-Timing: total 5734 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 2.8 (0.0%), b_tie_ro: 1.86 (0.0%), parse: 0.77 (0.0%), extract_message_metadata: 17 (0.3%), get_uri_detail_list: 2.1 (0.0%), tests_pri_-1000: 8 (0.1%), tests_pri_-950: 1.13 (0.0%), tests_pri_-900: 0.97 (0.0%), tests_pri_-400: 24 (0.4%), check_bayes: 23 (0.4%), b_tokenize: 8 (0.1%), b_tok_get_all: 8 (0.1%), b_comp_prob: 2.2 (0.0%), b_tok_touch_all: 3.5 (0.1%), b_finish: 0.65 (0.0%), tests_pri_0: 1212 (21.1%), check_dkim_signature: 0.49 (0.0%), check_dkim_adsp: 2.9 (0.1%), tests_pri_500: 4463 (77.8%), poll_dns_idle: 4457 (77.7%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] fs: add an ioctl to get an owning userns for a superblock X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andrei Vagin writes: > The introduced ioctl returns a file descriptor that refers to a owning > user namespace for a superblock which is associated with a target file > descriptor. > > EPERM is returned if the current process doesn't have CAP_SYS_ADMIN in > the returned user namespace. > > This information is required to dump and restore mount namespaces. We > need to know to which user namespace a superblock is belonged to. > > We already have the SIOCGSKNS ioctl for sockets to get a network > namespace, so it looks reasonable to use the same interface for > superblocks too. > > This functionality can be useful for users in order to understand > a running system. This will probably work. And the capability check eases any concerns I might have that this would be a trivial information leak. That said can we hold off just a little bit. If open_fs work actually turns into a real interface that would seem to be the perfect place to stick this functionality. Eric > > Cc: Alexander Viro > Cc: Eric W. Biederman > Signed-off-by: Andrei Vagin > --- > fs/ioctl.c | 23 +++++++++++++++++++++++ > include/uapi/linux/fs.h | 2 ++ > 2 files changed, 25 insertions(+) > > diff --git a/fs/ioctl.c b/fs/ioctl.c > index 569db68..22bbf37 100644 > --- a/fs/ioctl.c > +++ b/fs/ioctl.c > @@ -16,6 +16,8 @@ > #include > #include > #include > +#include > +#include > > #include "internal.h" > > @@ -614,6 +616,25 @@ static int ioctl_file_dedupe_range(struct file *file, void __user *arg) > return ret; > } > > +static struct ns_common *get_sb_userns(struct ns_common *ns_common) > +{ > + struct user_namespace *ns; > + > + ns = container_of(ns_common, struct user_namespace, ns); > + > + return &get_user_ns(ns)->ns; > +} > + > +static int ioctl_fs_sb_userns(struct file *filp) > +{ > + struct super_block *sb = file_inode(filp)->i_sb; > + > + if (!ns_capable(sb->s_user_ns, CAP_SYS_ADMIN)) > + return -EPERM; > + > + return open_related_ns(&sb->s_user_ns->ns, get_sb_userns); > +} > + > /* > * When you add any new common ioctls to the switches above and below > * please update compat_sys_ioctl() too. > @@ -677,6 +698,8 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, > > case FIDEDUPERANGE: > return ioctl_file_dedupe_range(filp, argp); > + case FS_IOC_SB_USERNS: > + return ioctl_fs_sb_userns(filp); > > default: > if (S_ISREG(inode->i_mode)) > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h > index 33423aa..26ef2d5 100644 > --- a/include/uapi/linux/fs.h > +++ b/include/uapi/linux/fs.h > @@ -246,6 +246,8 @@ struct fsxattr { > #define FICLONE _IOW(0x94, 9, int) > #define FICLONERANGE _IOW(0x94, 13, struct file_clone_range) > #define FIDEDUPERANGE _IOWR(0x94, 54, struct file_dedupe_range) > +/* Get a file descriptor to an owning userns for a superblock */ > +#define FS_IOC_SB_USERNS _IOR('X', 55, int) > > #define FS_IOC_GETFLAGS _IOR('f', 1, long) > #define FS_IOC_SETFLAGS _IOW('f', 2, long)