Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932749AbcKGRJN (ORCPT ); Mon, 7 Nov 2016 12:09:13 -0500 Received: from out03.mta.xmission.com ([166.70.13.233]:37328 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753308AbcKGRJM (ORCPT ); Mon, 7 Nov 2016 12:09:12 -0500 From: ebiederm@xmission.com (Eric W. Biederman) To: Dmitry Safonov Cc: , <0x7f454c46@gmail.com>, Al Viro , Andrey Vagin , Rob Landley References: <20161107160635.21556-1-dsafonov@virtuozzo.com> Date: Mon, 07 Nov 2016 11:06:33 -0600 In-Reply-To: <20161107160635.21556-1-dsafonov@virtuozzo.com> (Dmitry Safonov's message of "Mon, 7 Nov 2016 19:06:35 +0300") Message-ID: <87pom743ty.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=1c3nPn-0005VK-GU;;;mid=<87pom743ty.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=75.170.125.99;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18B2/Q5WpHlhlUaQ4ab9xX2gNU510FBTpc= X-SA-Exim-Connect-IP: 75.170.125.99 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.7 XMSubLong Long Subject * 0.0 TVD_RCVD_IP Message was received from an IP address * 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 * [sa05 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_04 7+ unique symbols in subject * 0.0 T_TooManySym_03 6+ unique symbols in subject * 0.0 T_TooManySym_02 5+ unique symbols in subject X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Dmitry Safonov X-Spam-Relay-Country: X-Spam-Timing: total 6146 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 6 (0.1%), b_tie_ro: 4.1 (0.1%), parse: 1.91 (0.0%), extract_message_metadata: 25 (0.4%), get_uri_detail_list: 2.7 (0.0%), tests_pri_-1000: 13 (0.2%), tests_pri_-950: 1.25 (0.0%), tests_pri_-900: 0.96 (0.0%), tests_pri_-400: 30 (0.5%), check_bayes: 29 (0.5%), b_tokenize: 8 (0.1%), b_tok_get_all: 10 (0.2%), b_comp_prob: 2.6 (0.0%), b_tok_touch_all: 4.4 (0.1%), b_finish: 0.77 (0.0%), tests_pri_0: 433 (7.0%), check_dkim_signature: 0.60 (0.0%), check_dkim_adsp: 4.5 (0.1%), tests_pri_500: 5627 (91.6%), poll_dns_idle: 5620 (91.4%), rewrite_mail: 0.00 (0.0%) Subject: Re: [RFC] proc: don't show kernel-internal mnt_id in fdinfo (if possible) 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 Content-Length: 3699 Lines: 115 Dmitry Safonov writes: > Some kernel special fs could be mounted by userspace, let's show > userspace mnt_id in those cases. You are asking the kernel to lie to userspace in the case when the truth in inconvenient. That seems blantantly wrong. In the case of an internal mount you may want to use the device id of the device the filesystem is mounted on so you can tie all of the mounts together. That would allow restore and other things to do something useful. That information is available with fstat on a file descriptor so I don't think we need to export it. But if it is not available I can see the point of a patch. Outright ling to userpsace. No. That is just horrible. Nacked-by: "Eric W. Biederman" > > Otherwise, I got: > [~]# cat /proc/11299/fdinfo/3 > pos: 0 > flags: 02000002 > mnt_id: 14 > [~]# cat /proc/11299/mountinfo | grep '^14' > [~]# ls -l /proc/11299/fd/3 > lrwx------. 1 root root 64 Nov 7 18:30 /proc/11299/fd/3 -> /test-queue > [~]# ls /dev/mqueue/ > test-queue > [~]# cat /proc/11299/mountinfo | grep mqueue > 32 18 0:14 / /dev/mqueue rw,relatime shared:17 - mqueue mqueue rw,seclabel > > This happens because mqueue fs is mounted twice: > - the first is kernel-internal mnt on init: > kernel_init=>do_one_initcall=>init_mqueue_fs=>mq_init_ns=>vfs_kern_mount > - the second time it's systemd's mount-unit: > entry_SYSCALL_64_fastpath=>SyS_mount=>do_mount=>vfs_kern_mount > > For the purpose of userspace parsing, having in-kernel mnt_id is less > useful then mnt_id of mount point: afterwards I'm able to see fs type, > path, etc: > [~]# cat /proc/11152/mountinfo | grep mqueue > 32 18 0:14 / /dev/mqueue rw,relatime shared:18 - mqueue mqueue rw,seclabel > [~]# cat /proc/11152/fdinfo/3 > pos: 0 > flags: 02000002 > mnt_id: 32 > > On a bad side - if we've no userspace mount, we still can't tell a thing > about opened fd.. > > Cc: Al Viro > Cc: Andrey Vagin > Cc: "Eric W. Biederman" > Cc: Rob Landley > Signed-off-by: Dmitry Safonov > --- > fs/proc/fd.c | 24 +++++++++++++++++++++--- > 1 file changed, 21 insertions(+), 3 deletions(-) > > diff --git a/fs/proc/fd.c b/fs/proc/fd.c > index d21dafef3102..bfa8699bcd8e 100644 > --- a/fs/proc/fd.c > +++ b/fs/proc/fd.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > > #include > > @@ -19,9 +20,10 @@ > static int seq_show(struct seq_file *m, void *v) > { > struct files_struct *files = NULL; > - int f_flags = 0, ret = -ENOENT; > + int f_flags = 0, ret = -ENOENT, mnt_id = 0; > struct file *file = NULL; > struct task_struct *task; > + struct mount *mount; > > task = get_proc_task(m->private); > if (!task) > @@ -52,9 +54,25 @@ static int seq_show(struct seq_file *m, void *v) > if (ret) > return ret; > > + mount = real_mount(file->f_path.mnt); > + if (mount->mnt_ns == MNT_NS_INTERNAL) { > + struct mount *mnt; > + > + lock_mount_hash(); > + list_for_each_entry(mnt, &mount->mnt_instance, mnt_instance) { > + if (current->nsproxy->mnt_ns == mnt->mnt_ns) { > + mnt_id = mnt->mnt_id; > + break; > + } > + } > + unlock_mount_hash(); > + } > + > + if (mnt_id == 0) > + mnt_id = mount->mnt_id; > + > seq_printf(m, "pos:\t%lli\nflags:\t0%o\nmnt_id:\t%i\n", > - (long long)file->f_pos, f_flags, > - real_mount(file->f_path.mnt)->mnt_id); > + (long long)file->f_pos, f_flags, mnt_id); > > show_fd_locks(m, file, files); > if (seq_has_overflowed(m))