License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* linux/fs/proc/root.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
*
|
|
|
|
* proc root directory handling functions
|
|
|
|
*/
|
|
|
|
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/init.h>
|
2006-10-18 17:55:46 +00:00
|
|
|
#include <linux/sched.h>
|
2017-02-08 17:51:35 +00:00
|
|
|
#include <linux/sched/stat.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/bitops.h>
|
2013-03-24 21:28:27 +00:00
|
|
|
#include <linux/user_namespace.h>
|
2018-11-01 23:07:25 +00:00
|
|
|
#include <linux/fs_context.h>
|
2006-10-02 09:17:07 +00:00
|
|
|
#include <linux/mount.h>
|
2007-10-19 06:40:08 +00:00
|
|
|
#include <linux/pid_namespace.h>
|
2018-11-01 23:07:25 +00:00
|
|
|
#include <linux/fs_parser.h>
|
2017-02-02 16:54:15 +00:00
|
|
|
#include <linux/cred.h>
|
2018-11-01 23:07:25 +00:00
|
|
|
#include <linux/magic.h>
|
2018-11-01 23:07:25 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-08 09:04:16 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
struct proc_fs_context {
|
|
|
|
struct pid_namespace *pid_ns;
|
|
|
|
unsigned int mask;
|
|
|
|
int hidepid;
|
|
|
|
int gid;
|
2012-01-10 23:11:27 +00:00
|
|
|
};
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
enum proc_param {
|
|
|
|
Opt_gid,
|
|
|
|
Opt_hidepid,
|
2012-01-10 23:11:27 +00:00
|
|
|
};
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
static const struct fs_parameter_spec proc_param_specs[] = {
|
|
|
|
fsparam_u32("gid", Opt_gid),
|
|
|
|
fsparam_u32("hidepid", Opt_hidepid),
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct fs_parameter_description proc_fs_parameters = {
|
|
|
|
.specs = proc_param_specs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
2012-01-10 23:11:27 +00:00
|
|
|
{
|
2018-11-01 23:07:25 +00:00
|
|
|
struct proc_fs_context *ctx = fc->fs_private;
|
|
|
|
struct fs_parse_result result;
|
|
|
|
int opt;
|
|
|
|
|
|
|
|
opt = fs_parse(fc, &proc_fs_parameters, param, &result);
|
|
|
|
if (opt < 0)
|
|
|
|
return opt;
|
|
|
|
|
|
|
|
switch (opt) {
|
|
|
|
case Opt_gid:
|
|
|
|
ctx->gid = result.uint_32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Opt_hidepid:
|
|
|
|
ctx->hidepid = result.uint_32;
|
|
|
|
if (ctx->hidepid < HIDEPID_OFF ||
|
|
|
|
ctx->hidepid > HIDEPID_INVISIBLE)
|
|
|
|
return invalf(fc, "proc: hidepid value must be between 0 and 2.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2012-01-10 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
ctx->mask |= 1 << opt;
|
|
|
|
return 0;
|
2012-01-10 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
static void proc_apply_options(struct super_block *s,
|
|
|
|
struct fs_context *fc,
|
|
|
|
struct pid_namespace *pid_ns,
|
|
|
|
struct user_namespace *user_ns)
|
2012-01-10 23:11:27 +00:00
|
|
|
{
|
2018-11-01 23:07:25 +00:00
|
|
|
struct proc_fs_context *ctx = fc->fs_private;
|
|
|
|
|
|
|
|
if (ctx->mask & (1 << Opt_gid))
|
|
|
|
pid_ns->pid_gid = make_kgid(user_ns, ctx->gid);
|
|
|
|
if (ctx->mask & (1 << Opt_hidepid))
|
|
|
|
pid_ns->hide_pid = ctx->hidepid;
|
2012-01-10 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
static int proc_fill_super(struct super_block *s, struct fs_context *fc)
|
2018-11-01 23:07:25 +00:00
|
|
|
{
|
2018-11-01 23:07:25 +00:00
|
|
|
struct pid_namespace *pid_ns = get_pid_ns(s->s_fs_info);
|
2018-11-01 23:07:25 +00:00
|
|
|
struct inode *root_inode;
|
|
|
|
int ret;
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
proc_apply_options(s, fc, pid_ns, current_user_ns());
|
2018-11-01 23:07:25 +00:00
|
|
|
|
|
|
|
/* User space would break if executables or devices appear on proc */
|
|
|
|
s->s_iflags |= SB_I_USERNS_VISIBLE | SB_I_NOEXEC | SB_I_NODEV;
|
|
|
|
s->s_flags |= SB_NODIRATIME | SB_NOSUID | SB_NOEXEC;
|
|
|
|
s->s_blocksize = 1024;
|
|
|
|
s->s_blocksize_bits = 10;
|
|
|
|
s->s_magic = PROC_SUPER_MAGIC;
|
|
|
|
s->s_op = &proc_sops;
|
|
|
|
s->s_time_gran = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* procfs isn't actually a stacking filesystem; however, there is
|
|
|
|
* too much magic going on inside it to permit stacking things on
|
|
|
|
* top of it
|
|
|
|
*/
|
|
|
|
s->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;
|
|
|
|
|
|
|
|
/* procfs dentries and inodes don't require IO to create */
|
|
|
|
s->s_shrink.seeks = 0;
|
|
|
|
|
|
|
|
pde_get(&proc_root);
|
|
|
|
root_inode = proc_get_inode(s, &proc_root);
|
|
|
|
if (!root_inode) {
|
|
|
|
pr_err("proc_fill_super: get root inode failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->s_root = d_make_root(root_inode);
|
|
|
|
if (!s->s_root) {
|
|
|
|
pr_err("proc_fill_super: allocate dentry failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = proc_setup_self(s);
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return proc_setup_thread_self(s);
|
|
|
|
}
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
static int proc_reconfigure(struct fs_context *fc)
|
2012-01-10 23:11:27 +00:00
|
|
|
{
|
2018-11-01 23:07:25 +00:00
|
|
|
struct super_block *sb = fc->root->d_sb;
|
2012-01-10 23:11:27 +00:00
|
|
|
struct pid_namespace *pid = sb->s_fs_info;
|
2014-03-13 14:14:33 +00:00
|
|
|
|
|
|
|
sync_filesystem(sb);
|
2018-11-01 23:07:25 +00:00
|
|
|
|
|
|
|
proc_apply_options(sb, fc, pid, current_user_ns());
|
|
|
|
return 0;
|
2012-01-10 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
static int proc_get_tree(struct fs_context *fc)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2018-11-01 23:07:25 +00:00
|
|
|
struct proc_fs_context *ctx = fc->fs_private;
|
2007-10-19 06:40:08 +00:00
|
|
|
|
2019-09-03 23:05:48 +00:00
|
|
|
return get_tree_keyed(fc, proc_fill_super, ctx->pid_ns);
|
2018-11-01 23:07:25 +00:00
|
|
|
}
|
2007-10-19 06:40:08 +00:00
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
static void proc_fs_context_free(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
struct proc_fs_context *ctx = fc->fs_private;
|
|
|
|
|
2019-05-12 22:10:24 +00:00
|
|
|
put_pid_ns(ctx->pid_ns);
|
2018-11-01 23:07:25 +00:00
|
|
|
kfree(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fs_context_operations proc_fs_context_ops = {
|
|
|
|
.free = proc_fs_context_free,
|
|
|
|
.parse_param = proc_parse_param,
|
|
|
|
.get_tree = proc_get_tree,
|
|
|
|
.reconfigure = proc_reconfigure,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int proc_init_fs_context(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
struct proc_fs_context *ctx;
|
|
|
|
|
|
|
|
ctx = kzalloc(sizeof(struct proc_fs_context), GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
return -ENOMEM;
|
2007-10-19 06:40:08 +00:00
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
ctx->pid_ns = get_pid_ns(task_active_pid_ns(current));
|
2019-05-12 22:10:24 +00:00
|
|
|
put_user_ns(fc->user_ns);
|
|
|
|
fc->user_ns = get_user_ns(ctx->pid_ns->user_ns);
|
2018-11-01 23:07:25 +00:00
|
|
|
fc->fs_private = ctx;
|
|
|
|
fc->ops = &proc_fs_context_ops;
|
|
|
|
return 0;
|
2007-10-19 06:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void proc_kill_sb(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct pid_namespace *ns;
|
|
|
|
|
|
|
|
ns = (struct pid_namespace *)sb->s_fs_info;
|
2013-03-29 23:27:05 +00:00
|
|
|
if (ns->proc_self)
|
|
|
|
dput(ns->proc_self);
|
2014-07-31 10:10:50 +00:00
|
|
|
if (ns->proc_thread_self)
|
|
|
|
dput(ns->proc_thread_self);
|
2007-10-19 06:40:08 +00:00
|
|
|
kill_anon_super(sb);
|
|
|
|
put_pid_ns(ns);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
proc: fix NULL ->i_fop oops
proc_kill_inodes() can clear ->i_fop in the middle of vfs_readdir resulting in
NULL dereference during "file->f_op->readdir(file, buf, filler)".
The solution is to remove proc_kill_inodes() completely:
a) we don't have tricky modules implementing their tricky readdir hooks which
could keeping this revoke from hell.
b) In a situation when module is gone but PDE still alive, standard
readdir will return only "." and "..", because pde->next was cleared by
remove_proc_entry().
c) the race proc_kill_inode() destined to prevent is not completely
fixed, just race window made smaller, because vfs_readdir() is run
without sb_lock held and without file_list_lock held. Effectively,
->i_fop is cleared at random moment, which can't fix properly anything.
BUG: unable to handle kernel NULL pointer dereference at virtual address 00000018
printing eip: c1061205 *pdpt = 0000000005b22001 *pde = 0000000000000000
Oops: 0000 [#1] PREEMPT SMP
Modules linked in: foo af_packet ipv6 cpufreq_ondemand loop serio_raw sr_mod k8temp cdrom hwmon amd_rng
Pid: 2033, comm: find Not tainted (2.6.24-rc1-b1d08ac064268d0ae2281e98bf5e82627e0f0c56 #2)
EIP: 0060:[<c1061205>] EFLAGS: 00010246 CPU: 0
EIP is at vfs_readdir+0x47/0x74
EAX: c6b6a780 EBX: 00000000 ECX: c1061040 EDX: c5decf94
ESI: c6b6a780 EDI: fffffffe EBP: c9797c54 ESP: c5decf78
DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Process find (pid: 2033, ti=c5dec000 task=c64bba90 task.ti=c5dec000)
Stack: c5decf94 c1061040 fffffff7 0805ffbc 00000000 c6b6a780 c1061295 0805ffbc
00000000 00000400 00000000 00000004 0805ffbc 4588eff4 c5dec000 c10026ba
00000004 0805ffbc 00000400 0805ffbc 4588eff4 bfdc6c70 000000dc 0000007b
Call Trace:
[<c1061040>] filldir64+0x0/0xc5
[<c1061295>] sys_getdents64+0x63/0xa5
[<c10026ba>] sysenter_past_esp+0x5f/0x85
=======================
Code: 49 83 78 18 00 74 43 8d 6b 74 bf fe ff ff ff 89 e8 e8 b8 c0 12 00 f6 83 2c 01 00 00 10 75 22 8b 5e 10 8b 4c 24 04 89 f0 8b 14 24 <ff> 53 18 f6 46 1a 04 89 c7 75 0b 8b 56 0c 8b 46 08 e8 c8 66 00
EIP: [<c1061205>] vfs_readdir+0x47/0x74 SS:ESP 0068:c5decf78
hch: "Nice, getting rid of this is a very good step formwards.
Unfortunately we have another copy of this junk in
security/selinux/selinuxfs.c:sel_remove_entries() which would need the
same treatment."
Signed-off-by: Alexey Dobriyan <adobriyan@sw.ru>
Acked-by: Christoph Hellwig <hch@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: James Morris <jmorris@namei.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-11-29 00:21:23 +00:00
|
|
|
static struct file_system_type proc_fs_type = {
|
2018-11-01 23:07:25 +00:00
|
|
|
.name = "proc",
|
|
|
|
.init_fs_context = proc_init_fs_context,
|
|
|
|
.parameters = &proc_fs_parameters,
|
|
|
|
.kill_sb = proc_kill_sb,
|
2019-05-15 14:28:34 +00:00
|
|
|
.fs_flags = FS_USERNS_MOUNT | FS_DISALLOW_NOTIFY_PERM,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void __init proc_root_init(void)
|
|
|
|
{
|
2018-04-10 23:31:09 +00:00
|
|
|
proc_init_kmemcache();
|
2016-12-13 00:45:32 +00:00
|
|
|
set_proc_pid_nlink();
|
2010-07-10 21:52:49 +00:00
|
|
|
proc_self_init();
|
2014-07-31 10:10:50 +00:00
|
|
|
proc_thread_self_init();
|
2014-08-11 04:24:59 +00:00
|
|
|
proc_symlink("mounts", NULL, "self/mounts");
|
2007-09-12 10:01:34 +00:00
|
|
|
|
|
|
|
proc_net_init();
|
2008-04-29 08:01:42 +00:00
|
|
|
proc_mkdir("fs", NULL);
|
2008-04-29 08:01:44 +00:00
|
|
|
proc_mkdir("driver", NULL);
|
2015-05-11 21:44:25 +00:00
|
|
|
proc_create_mount_point("fs/nfsd"); /* somewhere for the nfsd filesystem to be mounted */
|
2005-04-16 22:20:36 +00:00
|
|
|
#if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
|
|
|
|
/* just give it a mountpoint */
|
2015-05-11 21:44:25 +00:00
|
|
|
proc_create_mount_point("openprom");
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
proc_tty_init();
|
2008-04-29 08:01:41 +00:00
|
|
|
proc_mkdir("bus", NULL);
|
2007-02-14 08:34:12 +00:00
|
|
|
proc_sys_init();
|
2018-04-10 23:31:57 +00:00
|
|
|
|
|
|
|
register_filesystem(&proc_fs_type);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
statx: Add a system call to make enhanced file info available
Add a system call to make extended file information available, including
file creation and some attribute flags where available through the
underlying filesystem.
The getattr inode operation is altered to take two additional arguments: a
u32 request_mask and an unsigned int flags that indicate the
synchronisation mode. This change is propagated to the vfs_getattr*()
function.
Functions like vfs_stat() are now inline wrappers around new functions
vfs_statx() and vfs_statx_fd() to reduce stack usage.
========
OVERVIEW
========
The idea was initially proposed as a set of xattrs that could be retrieved
with getxattr(), but the general preference proved to be for a new syscall
with an extended stat structure.
A number of requests were gathered for features to be included. The
following have been included:
(1) Make the fields a consistent size on all arches and make them large.
(2) Spare space, request flags and information flags are provided for
future expansion.
(3) Better support for the y2038 problem [Arnd Bergmann] (tv_sec is an
__s64).
(4) Creation time: The SMB protocol carries the creation time, which could
be exported by Samba, which will in turn help CIFS make use of
FS-Cache as that can be used for coherency data (stx_btime).
This is also specified in NFSv4 as a recommended attribute and could
be exported by NFSD [Steve French].
(5) Lightweight stat: Ask for just those details of interest, and allow a
netfs (such as NFS) to approximate anything not of interest, possibly
without going to the server [Trond Myklebust, Ulrich Drepper, Andreas
Dilger] (AT_STATX_DONT_SYNC).
(6) Heavyweight stat: Force a netfs to go to the server, even if it thinks
its cached attributes are up to date [Trond Myklebust]
(AT_STATX_FORCE_SYNC).
And the following have been left out for future extension:
(7) Data version number: Could be used by userspace NFS servers [Aneesh
Kumar].
Can also be used to modify fill_post_wcc() in NFSD which retrieves
i_version directly, but has just called vfs_getattr(). It could get
it from the kstat struct if it used vfs_xgetattr() instead.
(There's disagreement on the exact semantics of a single field, since
not all filesystems do this the same way).
(8) BSD stat compatibility: Including more fields from the BSD stat such
as creation time (st_btime) and inode generation number (st_gen)
[Jeremy Allison, Bernd Schubert].
(9) Inode generation number: Useful for FUSE and userspace NFS servers
[Bernd Schubert].
(This was asked for but later deemed unnecessary with the
open-by-handle capability available and caused disagreement as to
whether it's a security hole or not).
(10) Extra coherency data may be useful in making backups [Andreas Dilger].
(No particular data were offered, but things like last backup
timestamp, the data version number and the DOS archive bit would come
into this category).
(11) Allow the filesystem to indicate what it can/cannot provide: A
filesystem can now say it doesn't support a standard stat feature if
that isn't available, so if, for instance, inode numbers or UIDs don't
exist or are fabricated locally...
(This requires a separate system call - I have an fsinfo() call idea
for this).
(12) Store a 16-byte volume ID in the superblock that can be returned in
struct xstat [Steve French].
(Deferred to fsinfo).
(13) Include granularity fields in the time data to indicate the
granularity of each of the times (NFSv4 time_delta) [Steve French].
(Deferred to fsinfo).
(14) FS_IOC_GETFLAGS value. These could be translated to BSD's st_flags.
Note that the Linux IOC flags are a mess and filesystems such as Ext4
define flags that aren't in linux/fs.h, so translation in the kernel
may be a necessity (or, possibly, we provide the filesystem type too).
(Some attributes are made available in stx_attributes, but the general
feeling was that the IOC flags were to ext[234]-specific and shouldn't
be exposed through statx this way).
(15) Mask of features available on file (eg: ACLs, seclabel) [Brad Boyer,
Michael Kerrisk].
(Deferred, probably to fsinfo. Finding out if there's an ACL or
seclabal might require extra filesystem operations).
(16) Femtosecond-resolution timestamps [Dave Chinner].
(A __reserved field has been left in the statx_timestamp struct for
this - if there proves to be a need).
(17) A set multiple attributes syscall to go with this.
===============
NEW SYSTEM CALL
===============
The new system call is:
int ret = statx(int dfd,
const char *filename,
unsigned int flags,
unsigned int mask,
struct statx *buffer);
The dfd, filename and flags parameters indicate the file to query, in a
similar way to fstatat(). There is no equivalent of lstat() as that can be
emulated with statx() by passing AT_SYMLINK_NOFOLLOW in flags. There is
also no equivalent of fstat() as that can be emulated by passing a NULL
filename to statx() with the fd of interest in dfd.
Whether or not statx() synchronises the attributes with the backing store
can be controlled by OR'ing a value into the flags argument (this typically
only affects network filesystems):
(1) AT_STATX_SYNC_AS_STAT tells statx() to behave as stat() does in this
respect.
(2) AT_STATX_FORCE_SYNC will require a network filesystem to synchronise
its attributes with the server - which might require data writeback to
occur to get the timestamps correct.
(3) AT_STATX_DONT_SYNC will suppress synchronisation with the server in a
network filesystem. The resulting values should be considered
approximate.
mask is a bitmask indicating the fields in struct statx that are of
interest to the caller. The user should set this to STATX_BASIC_STATS to
get the basic set returned by stat(). It should be noted that asking for
more information may entail extra I/O operations.
buffer points to the destination for the data. This must be 256 bytes in
size.
======================
MAIN ATTRIBUTES RECORD
======================
The following structures are defined in which to return the main attribute
set:
struct statx_timestamp {
__s64 tv_sec;
__s32 tv_nsec;
__s32 __reserved;
};
struct statx {
__u32 stx_mask;
__u32 stx_blksize;
__u64 stx_attributes;
__u32 stx_nlink;
__u32 stx_uid;
__u32 stx_gid;
__u16 stx_mode;
__u16 __spare0[1];
__u64 stx_ino;
__u64 stx_size;
__u64 stx_blocks;
__u64 __spare1[1];
struct statx_timestamp stx_atime;
struct statx_timestamp stx_btime;
struct statx_timestamp stx_ctime;
struct statx_timestamp stx_mtime;
__u32 stx_rdev_major;
__u32 stx_rdev_minor;
__u32 stx_dev_major;
__u32 stx_dev_minor;
__u64 __spare2[14];
};
The defined bits in request_mask and stx_mask are:
STATX_TYPE Want/got stx_mode & S_IFMT
STATX_MODE Want/got stx_mode & ~S_IFMT
STATX_NLINK Want/got stx_nlink
STATX_UID Want/got stx_uid
STATX_GID Want/got stx_gid
STATX_ATIME Want/got stx_atime{,_ns}
STATX_MTIME Want/got stx_mtime{,_ns}
STATX_CTIME Want/got stx_ctime{,_ns}
STATX_INO Want/got stx_ino
STATX_SIZE Want/got stx_size
STATX_BLOCKS Want/got stx_blocks
STATX_BASIC_STATS [The stuff in the normal stat struct]
STATX_BTIME Want/got stx_btime{,_ns}
STATX_ALL [All currently available stuff]
stx_btime is the file creation time, stx_mask is a bitmask indicating the
data provided and __spares*[] are where as-yet undefined fields can be
placed.
Time fields are structures with separate seconds and nanoseconds fields
plus a reserved field in case we want to add even finer resolution. Note
that times will be negative if before 1970; in such a case, the nanosecond
fields will also be negative if not zero.
The bits defined in the stx_attributes field convey information about a
file, how it is accessed, where it is and what it does. The following
attributes map to FS_*_FL flags and are the same numerical value:
STATX_ATTR_COMPRESSED File is compressed by the fs
STATX_ATTR_IMMUTABLE File is marked immutable
STATX_ATTR_APPEND File is append-only
STATX_ATTR_NODUMP File is not to be dumped
STATX_ATTR_ENCRYPTED File requires key to decrypt in fs
Within the kernel, the supported flags are listed by:
KSTAT_ATTR_FS_IOC_FLAGS
[Are any other IOC flags of sufficient general interest to be exposed
through this interface?]
New flags include:
STATX_ATTR_AUTOMOUNT Object is an automount trigger
These are for the use of GUI tools that might want to mark files specially,
depending on what they are.
Fields in struct statx come in a number of classes:
(0) stx_dev_*, stx_blksize.
These are local system information and are always available.
(1) stx_mode, stx_nlinks, stx_uid, stx_gid, stx_[amc]time, stx_ino,
stx_size, stx_blocks.
These will be returned whether the caller asks for them or not. The
corresponding bits in stx_mask will be set to indicate whether they
actually have valid values.
If the caller didn't ask for them, then they may be approximated. For
example, NFS won't waste any time updating them from the server,
unless as a byproduct of updating something requested.
If the values don't actually exist for the underlying object (such as
UID or GID on a DOS file), then the bit won't be set in the stx_mask,
even if the caller asked for the value. In such a case, the returned
value will be a fabrication.
Note that there are instances where the type might not be valid, for
instance Windows reparse points.
(2) stx_rdev_*.
This will be set only if stx_mode indicates we're looking at a
blockdev or a chardev, otherwise will be 0.
(3) stx_btime.
Similar to (1), except this will be set to 0 if it doesn't exist.
=======
TESTING
=======
The following test program can be used to test the statx system call:
samples/statx/test-statx.c
Just compile and run, passing it paths to the files you want to examine.
The file is built automatically if CONFIG_SAMPLES is enabled.
Here's some example output. Firstly, an NFS directory that crosses to
another FSID. Note that the AUTOMOUNT attribute is set because transiting
this directory will cause d_automount to be invoked by the VFS.
[root@andromeda ~]# /tmp/test-statx -A /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:26 Inode: 1703937 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Attributes: 0000000000001000 (-------- -------- -------- -------- -------- -------- ---m---- --------)
Secondly, the result of automounting on that directory.
[root@andromeda ~]# /tmp/test-statx /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:27 Inode: 2 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2017-01-31 16:46:22 +00:00
|
|
|
static int proc_root_getattr(const struct path *path, struct kstat *stat,
|
|
|
|
u32 request_mask, unsigned int query_flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
statx: Add a system call to make enhanced file info available
Add a system call to make extended file information available, including
file creation and some attribute flags where available through the
underlying filesystem.
The getattr inode operation is altered to take two additional arguments: a
u32 request_mask and an unsigned int flags that indicate the
synchronisation mode. This change is propagated to the vfs_getattr*()
function.
Functions like vfs_stat() are now inline wrappers around new functions
vfs_statx() and vfs_statx_fd() to reduce stack usage.
========
OVERVIEW
========
The idea was initially proposed as a set of xattrs that could be retrieved
with getxattr(), but the general preference proved to be for a new syscall
with an extended stat structure.
A number of requests were gathered for features to be included. The
following have been included:
(1) Make the fields a consistent size on all arches and make them large.
(2) Spare space, request flags and information flags are provided for
future expansion.
(3) Better support for the y2038 problem [Arnd Bergmann] (tv_sec is an
__s64).
(4) Creation time: The SMB protocol carries the creation time, which could
be exported by Samba, which will in turn help CIFS make use of
FS-Cache as that can be used for coherency data (stx_btime).
This is also specified in NFSv4 as a recommended attribute and could
be exported by NFSD [Steve French].
(5) Lightweight stat: Ask for just those details of interest, and allow a
netfs (such as NFS) to approximate anything not of interest, possibly
without going to the server [Trond Myklebust, Ulrich Drepper, Andreas
Dilger] (AT_STATX_DONT_SYNC).
(6) Heavyweight stat: Force a netfs to go to the server, even if it thinks
its cached attributes are up to date [Trond Myklebust]
(AT_STATX_FORCE_SYNC).
And the following have been left out for future extension:
(7) Data version number: Could be used by userspace NFS servers [Aneesh
Kumar].
Can also be used to modify fill_post_wcc() in NFSD which retrieves
i_version directly, but has just called vfs_getattr(). It could get
it from the kstat struct if it used vfs_xgetattr() instead.
(There's disagreement on the exact semantics of a single field, since
not all filesystems do this the same way).
(8) BSD stat compatibility: Including more fields from the BSD stat such
as creation time (st_btime) and inode generation number (st_gen)
[Jeremy Allison, Bernd Schubert].
(9) Inode generation number: Useful for FUSE and userspace NFS servers
[Bernd Schubert].
(This was asked for but later deemed unnecessary with the
open-by-handle capability available and caused disagreement as to
whether it's a security hole or not).
(10) Extra coherency data may be useful in making backups [Andreas Dilger].
(No particular data were offered, but things like last backup
timestamp, the data version number and the DOS archive bit would come
into this category).
(11) Allow the filesystem to indicate what it can/cannot provide: A
filesystem can now say it doesn't support a standard stat feature if
that isn't available, so if, for instance, inode numbers or UIDs don't
exist or are fabricated locally...
(This requires a separate system call - I have an fsinfo() call idea
for this).
(12) Store a 16-byte volume ID in the superblock that can be returned in
struct xstat [Steve French].
(Deferred to fsinfo).
(13) Include granularity fields in the time data to indicate the
granularity of each of the times (NFSv4 time_delta) [Steve French].
(Deferred to fsinfo).
(14) FS_IOC_GETFLAGS value. These could be translated to BSD's st_flags.
Note that the Linux IOC flags are a mess and filesystems such as Ext4
define flags that aren't in linux/fs.h, so translation in the kernel
may be a necessity (or, possibly, we provide the filesystem type too).
(Some attributes are made available in stx_attributes, but the general
feeling was that the IOC flags were to ext[234]-specific and shouldn't
be exposed through statx this way).
(15) Mask of features available on file (eg: ACLs, seclabel) [Brad Boyer,
Michael Kerrisk].
(Deferred, probably to fsinfo. Finding out if there's an ACL or
seclabal might require extra filesystem operations).
(16) Femtosecond-resolution timestamps [Dave Chinner].
(A __reserved field has been left in the statx_timestamp struct for
this - if there proves to be a need).
(17) A set multiple attributes syscall to go with this.
===============
NEW SYSTEM CALL
===============
The new system call is:
int ret = statx(int dfd,
const char *filename,
unsigned int flags,
unsigned int mask,
struct statx *buffer);
The dfd, filename and flags parameters indicate the file to query, in a
similar way to fstatat(). There is no equivalent of lstat() as that can be
emulated with statx() by passing AT_SYMLINK_NOFOLLOW in flags. There is
also no equivalent of fstat() as that can be emulated by passing a NULL
filename to statx() with the fd of interest in dfd.
Whether or not statx() synchronises the attributes with the backing store
can be controlled by OR'ing a value into the flags argument (this typically
only affects network filesystems):
(1) AT_STATX_SYNC_AS_STAT tells statx() to behave as stat() does in this
respect.
(2) AT_STATX_FORCE_SYNC will require a network filesystem to synchronise
its attributes with the server - which might require data writeback to
occur to get the timestamps correct.
(3) AT_STATX_DONT_SYNC will suppress synchronisation with the server in a
network filesystem. The resulting values should be considered
approximate.
mask is a bitmask indicating the fields in struct statx that are of
interest to the caller. The user should set this to STATX_BASIC_STATS to
get the basic set returned by stat(). It should be noted that asking for
more information may entail extra I/O operations.
buffer points to the destination for the data. This must be 256 bytes in
size.
======================
MAIN ATTRIBUTES RECORD
======================
The following structures are defined in which to return the main attribute
set:
struct statx_timestamp {
__s64 tv_sec;
__s32 tv_nsec;
__s32 __reserved;
};
struct statx {
__u32 stx_mask;
__u32 stx_blksize;
__u64 stx_attributes;
__u32 stx_nlink;
__u32 stx_uid;
__u32 stx_gid;
__u16 stx_mode;
__u16 __spare0[1];
__u64 stx_ino;
__u64 stx_size;
__u64 stx_blocks;
__u64 __spare1[1];
struct statx_timestamp stx_atime;
struct statx_timestamp stx_btime;
struct statx_timestamp stx_ctime;
struct statx_timestamp stx_mtime;
__u32 stx_rdev_major;
__u32 stx_rdev_minor;
__u32 stx_dev_major;
__u32 stx_dev_minor;
__u64 __spare2[14];
};
The defined bits in request_mask and stx_mask are:
STATX_TYPE Want/got stx_mode & S_IFMT
STATX_MODE Want/got stx_mode & ~S_IFMT
STATX_NLINK Want/got stx_nlink
STATX_UID Want/got stx_uid
STATX_GID Want/got stx_gid
STATX_ATIME Want/got stx_atime{,_ns}
STATX_MTIME Want/got stx_mtime{,_ns}
STATX_CTIME Want/got stx_ctime{,_ns}
STATX_INO Want/got stx_ino
STATX_SIZE Want/got stx_size
STATX_BLOCKS Want/got stx_blocks
STATX_BASIC_STATS [The stuff in the normal stat struct]
STATX_BTIME Want/got stx_btime{,_ns}
STATX_ALL [All currently available stuff]
stx_btime is the file creation time, stx_mask is a bitmask indicating the
data provided and __spares*[] are where as-yet undefined fields can be
placed.
Time fields are structures with separate seconds and nanoseconds fields
plus a reserved field in case we want to add even finer resolution. Note
that times will be negative if before 1970; in such a case, the nanosecond
fields will also be negative if not zero.
The bits defined in the stx_attributes field convey information about a
file, how it is accessed, where it is and what it does. The following
attributes map to FS_*_FL flags and are the same numerical value:
STATX_ATTR_COMPRESSED File is compressed by the fs
STATX_ATTR_IMMUTABLE File is marked immutable
STATX_ATTR_APPEND File is append-only
STATX_ATTR_NODUMP File is not to be dumped
STATX_ATTR_ENCRYPTED File requires key to decrypt in fs
Within the kernel, the supported flags are listed by:
KSTAT_ATTR_FS_IOC_FLAGS
[Are any other IOC flags of sufficient general interest to be exposed
through this interface?]
New flags include:
STATX_ATTR_AUTOMOUNT Object is an automount trigger
These are for the use of GUI tools that might want to mark files specially,
depending on what they are.
Fields in struct statx come in a number of classes:
(0) stx_dev_*, stx_blksize.
These are local system information and are always available.
(1) stx_mode, stx_nlinks, stx_uid, stx_gid, stx_[amc]time, stx_ino,
stx_size, stx_blocks.
These will be returned whether the caller asks for them or not. The
corresponding bits in stx_mask will be set to indicate whether they
actually have valid values.
If the caller didn't ask for them, then they may be approximated. For
example, NFS won't waste any time updating them from the server,
unless as a byproduct of updating something requested.
If the values don't actually exist for the underlying object (such as
UID or GID on a DOS file), then the bit won't be set in the stx_mask,
even if the caller asked for the value. In such a case, the returned
value will be a fabrication.
Note that there are instances where the type might not be valid, for
instance Windows reparse points.
(2) stx_rdev_*.
This will be set only if stx_mode indicates we're looking at a
blockdev or a chardev, otherwise will be 0.
(3) stx_btime.
Similar to (1), except this will be set to 0 if it doesn't exist.
=======
TESTING
=======
The following test program can be used to test the statx system call:
samples/statx/test-statx.c
Just compile and run, passing it paths to the files you want to examine.
The file is built automatically if CONFIG_SAMPLES is enabled.
Here's some example output. Firstly, an NFS directory that crosses to
another FSID. Note that the AUTOMOUNT attribute is set because transiting
this directory will cause d_automount to be invoked by the VFS.
[root@andromeda ~]# /tmp/test-statx -A /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:26 Inode: 1703937 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Attributes: 0000000000001000 (-------- -------- -------- -------- -------- -------- ---m---- --------)
Secondly, the result of automounting on that directory.
[root@andromeda ~]# /tmp/test-statx /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:27 Inode: 2 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2017-01-31 16:46:22 +00:00
|
|
|
generic_fillattr(d_inode(path->dentry), stat);
|
2006-02-08 19:37:40 +00:00
|
|
|
stat->nlink = proc_root.nlink + nr_processes();
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-06-10 21:13:09 +00:00
|
|
|
static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry, unsigned int flags)
|
2006-02-08 19:37:40 +00:00
|
|
|
{
|
2019-03-05 23:50:29 +00:00
|
|
|
if (!proc_pid_lookup(dentry, flags))
|
2005-04-16 22:20:36 +00:00
|
|
|
return NULL;
|
2018-11-01 23:07:25 +00:00
|
|
|
|
2014-08-08 21:21:27 +00:00
|
|
|
return proc_lookup(dir, dentry, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 16:07:31 +00:00
|
|
|
static int proc_root_readdir(struct file *file, struct dir_context *ctx)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-05-16 16:07:31 +00:00
|
|
|
if (ctx->pos < FIRST_PROCESS_ENTRY) {
|
2013-08-19 16:30:31 +00:00
|
|
|
int error = proc_readdir(file, ctx);
|
|
|
|
if (unlikely(error <= 0))
|
|
|
|
return error;
|
2013-05-16 16:07:31 +00:00
|
|
|
ctx->pos = FIRST_PROCESS_ENTRY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 16:07:31 +00:00
|
|
|
return proc_pid_readdir(file, ctx);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The root /proc directory is special, as it has the
|
|
|
|
* <pid> directories. Thus we don't use the generic
|
|
|
|
* directory handling functions for that..
|
|
|
|
*/
|
2007-02-12 08:55:34 +00:00
|
|
|
static const struct file_operations proc_root_operations = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.read = generic_read_dir,
|
2016-04-20 21:13:54 +00:00
|
|
|
.iterate_shared = proc_root_readdir,
|
|
|
|
.llseek = generic_file_llseek,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* proc root can do almost nothing..
|
|
|
|
*/
|
2007-02-12 08:55:40 +00:00
|
|
|
static const struct inode_operations proc_root_inode_operations = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.lookup = proc_root_lookup,
|
2006-02-08 19:37:40 +00:00
|
|
|
.getattr = proc_root_getattr,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the root "inode" in the /proc tree..
|
|
|
|
*/
|
|
|
|
struct proc_dir_entry proc_root = {
|
|
|
|
.low_ino = PROC_ROOT_INO,
|
|
|
|
.namelen = 5,
|
|
|
|
.mode = S_IFDIR | S_IRUGO | S_IXUGO,
|
|
|
|
.nlink = 2,
|
2018-04-10 23:32:14 +00:00
|
|
|
.refcnt = REFCOUNT_INIT(1),
|
2005-04-16 22:20:36 +00:00
|
|
|
.proc_iops = &proc_root_inode_operations,
|
|
|
|
.proc_fops = &proc_root_operations,
|
|
|
|
.parent = &proc_root,
|
2018-04-10 23:32:20 +00:00
|
|
|
.subdir = RB_ROOT,
|
2018-06-13 18:43:19 +00:00
|
|
|
.name = "/proc",
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2007-10-19 06:40:11 +00:00
|
|
|
int pid_ns_prepare_proc(struct pid_namespace *ns)
|
|
|
|
{
|
2018-11-01 23:07:25 +00:00
|
|
|
struct proc_fs_context *ctx;
|
|
|
|
struct fs_context *fc;
|
2007-10-19 06:40:11 +00:00
|
|
|
struct vfsmount *mnt;
|
|
|
|
|
2018-11-01 23:07:25 +00:00
|
|
|
fc = fs_context_for_mount(&proc_fs_type, SB_KERNMOUNT);
|
|
|
|
if (IS_ERR(fc))
|
|
|
|
return PTR_ERR(fc);
|
|
|
|
|
|
|
|
if (fc->user_ns != ns->user_ns) {
|
|
|
|
put_user_ns(fc->user_ns);
|
|
|
|
fc->user_ns = get_user_ns(ns->user_ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = fc->fs_private;
|
|
|
|
if (ctx->pid_ns != ns) {
|
|
|
|
put_pid_ns(ctx->pid_ns);
|
|
|
|
get_pid_ns(ns);
|
|
|
|
ctx->pid_ns = ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
mnt = fc_mount(fc);
|
|
|
|
put_fs_context(fc);
|
2007-10-19 06:40:11 +00:00
|
|
|
if (IS_ERR(mnt))
|
|
|
|
return PTR_ERR(mnt);
|
|
|
|
|
2010-07-26 09:09:36 +00:00
|
|
|
ns->proc_mnt = mnt;
|
2007-10-19 06:40:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pid_ns_release_proc(struct pid_namespace *ns)
|
|
|
|
{
|
2011-12-09 04:20:45 +00:00
|
|
|
kern_unmount(ns->proc_mnt);
|
2007-10-19 06:40:11 +00:00
|
|
|
}
|