procfs: add hidepid and hidenet modes
Subsystems (4)
RFC 1/1 procfs: add hidepid and hidenet modes
This patch introduces support of procfs mount options and adds mount options to restrict access to /proc/PID/ directories and /proc/PID/net/ contents. The default backward-compatible behaviour is left untouched.
The first mount option is called "hidepid" and its value defines how much info about processes we want to be available for non-owners:
hidepid=0 (default) means the current behaviour - anybody may read all world-readable /proc/PID/* files.
hidepid=1 means users may not access any /proc/<pid>/ directories, but their own. Sensitive files like cmdline, io, sched*, status, wchan are now protected against other users. As permission checking done in proc_pid_permission() and files' permissions are left untouched, programs expecting specific files' permissions are not confused.
hidepid=2 means hidepid=1 plus all /proc/PID/ will be invisible to other users. It doesn't mean that it hides a fact whether a process exists (it can be learned by other means, e.g. by sending signals), but it hides process' euid and egid. It greatly compicates intruder's task of gathering info about running processes, whether some daemon runs with elevated privileges, whether other user runs some sensitive program, whether other users run any program at all, etc.
hidenet means /proc/PID/net will be accessible to processes with CAP_NET_ADMIN capability or to members of a special group.
gid=XXX defines a group that will be able to gather all processes' info and network connections info.
Similar features are implemented for old kernels in -ow patches (for Linux 2.2 and 2.4) and for Linux 2.6 in -grsecurity (but both of them are implemented as configure options, not cofigurable in runtime).
In current version hidenet works for CONFIG_NET_NS=y via creating a "fake" net namespace and slipping it to nonauthorized users, resulting in users observing blank net files (like nobody use the network). If CONFIG_NET_NS=n I don't see anything better than just fully denying access to /proc/<pid>/net. More elegant ideas are welcome.
--
Documentation/filesystems/proc.txt | 51 ++++++++++++++++++++++ fs/proc/base.c | 62 ++++++++++++++++++++++++++- fs/proc/inode.c | 20 +++++++++ fs/proc/internal.h | 1 + fs/proc/proc_net.c | 26 +++++++++++ fs/proc/root.c | 83 +++++++++++++++++++++++++++++++++++- include/linux/pid_namespace.h | 3 + include/net/net_namespace.h | 2 + net/core/net_namespace.c | 2 +- 9 files changed, 246 insertions(+), 4 deletions(-)
Documentation/filesystems/proc.txt +51 -0
@@ -41,6 +41,8 @@ Table of Contents 3.5 /proc/<pid>/mountinfo - Information about mounts 3.6 /proc/<pid>/comm & /proc/<pid>/task/<tid>/comm + 4 Configuring procfs + 4.1 Mount options ------------------------------------------------------------------------------ Preface
@@ -1535,3 +1537,52 @@ a task to set its own or one of its thread siblings comm value. The comm value is limited in size compared to the cmdline value, so writing anything longer then the kernel's TASK_COMM_LEN (currently 16 chars) will result in a truncated comm value. + + +------------------------------------------------------------------------------ +Configuring procfs +------------------------------------------------------------------------------ + +4.1 Mount options +--------------------- + +The following mount options are supported: + + hidepid= Set /proc/<pid>/ access mode. + hidenet Hide /proc/<pid>/net/ from nonauthorized users. + nohidenet Don't hide /proc/<pid>/net/ from nonauthorized users. + gid= Set the group authorized to learn processes and + networking information. + +hidepid=0 means classic mode - everybody may access all /proc/<pid>/ directories +(default). + +hidepid=1 means users may not access any /proc/<pid>/ directories, but their +own. Sensitive files like cmdline, io, sched*, status, wchan are now protected +against other users. This makes impossible to learn whether any user runs +specific program (given the program doesn't reveal itself by its behaviour). +As an additional bonus, as /proc/<pid>/cmdline is unaccessible for other users, +poorly written programs passing sensitive information via program arguments are +now protected against local eavesdroppers. + +hidepid=2 means hidepid=1 plus all /proc/<pid>/ will be fully invisible to other +users. It doesn't mean that it hides a fact whether a process with a specific +pid value exists (it can be learned by other means, e.g. by sending signals), +but it hides process' euid and egid, which may be learned by stat()'ing +/proc/<pid>/ otherwise. It greatly complicates intruder's task of gathering info +about running processes, whether some daemon runs with elevated privileges, +whether other user runs some sensitive program, whether other users run any +program at all, etc. + +hidenet means /proc/<pid>/net/ will be accessible to processes with +CAP_NET_ADMIN capability or to members of a special group. It means +nonauthorized users may not learn any networking connections information. If +network namespaces support is enabled (CONFIG_NET_NS=y) then common users would +obtain net directory, but all files would indicate no networking activity at +all. If network namespaces are disabled, net directory is unaccessible to +common users. + +gid= means group authorized to learn processes information prohibited by +hidepid= and networking information prohibited by hidenet. If you use some +daemon like identd which have to learn information about net/processes +information, just add identd to this group.
fs/proc/base.c +61 -1
143 lines not on this page · raw message
fs/proc/inode.c +20 -0
@@ -7,6 +7,7 @@#include <linux/time.h> #include <linux/proc_fs.h> #include <linux/kernel.h> +#include <linux/pid_namespace.h> #include <linux/mm.h> #include <linux/string.h> #include <linux/stat.h>
@@ -17,7 +18,9 @@#include <linux/init.h> #include <linux/module.h> #include <linux/sysctl.h> +#include <linux/seq_file.h> #include <linux/slab.h> +#include <linux/mount.h> #include <asm/system.h> #include <asm/uaccess.h>
@@ -93,12 +96,29 @@ void __init proc_init_inodecache(void) init_once); } +static int proc_show_options (struct seq_file *seq,struct vfsmount *vfs) +{ +struct super_block *sb = vfs->mnt_sb; +struct pid_namespace *pid = sb->s_fs_info; + +if (pid->pid_gid) +seq_printf (seq,",gid=%lu" , (unsigned long )pid->pid_gid); +if (pid->hide_pid !=0 ) +seq_printf (seq,",hidepid=%u" , pid->hide_pid); +if (pid->hide_net) +seq_printf (seq,",hidenet" ); + +return 0 ; +} +static const struct super_operations proc_sops = { .alloc_inode = proc_alloc_inode, .destroy_inode = proc_destroy_inode, .drop_inode = generic_delete_inode, .evict_inode = proc_evict_inode, .statfs = simple_statfs, + .remount_fs = proc_remount, + .show_options = proc_show_options, };static void __pde_users_dec (struct proc_dir_entry *pde)
fs/proc/internal.h +1 -0
@@ -110,6 +110,7 @@ void pde_put(struct proc_dir_entry *pde);extern struct vfsmount *proc_mnt;int proc_fill_super (struct super_block *);struct inode *proc_get_inode (struct super_block *,struct proc_dir_entry *); +int proc_remount (struct super_block *sb,int *flags,char *data);/* * These are generic /proc routines that use the internal
fs/proc/proc_net.c +26 -0
@@ -22,10 +22,13 @@#include <linux/mount.h> #include <linux/nsproxy.h> #include <net/net_namespace.h> +#include <linux/pid_namespace.h> #include <linux/seq_file.h> #include "internal.h" +static struct net *fake_net; +static struct net *get_proc_net (const struct inode *inode) {
@@ -105,6 +108,15 @@ static struct net *get_proc_task_net(struct inode *dir)struct task_struct *task;struct nsproxy *ns;struct net *net =NULL ; +struct pid_namespace *pid = dir->i_sb->s_fs_info; + +if (pid->hide_net && + !in_group_p (pid->pid_gid) && + !capable (CAP_NET_ADMIN )) { +if (fake_net) +get_net (fake_net); +return fake_net; + }rcu_read_lock (); task =pid_task (proc_pid (dir),PIDTYPE_PID );
@@ -239,3 +251,17 @@ int __init proc_net_init(void)return register_pernet_subsys (&proc_net_ns_ops); } + +#ifdef CONFIG_NET_NS +int __init proc_net_initcall (void ) +{ + fake_net =net_create (); +if (fake_net ==NULL ) +return -ENOMEM ; + +get_net (fake_net); +return 0 ; +} + +late_initcall (proc_net_initcall); +#endif
fs/proc/root.c +81 -2
115 lines not on this page · raw message
include/linux/pid_namespace.h +3 -0
@@ -30,6 +30,9 @@ struct pid_namespace {#ifdef CONFIG_BSD_PROCESS_ACCT struct bsd_acct_struct *bacct;#endif +gid_t pid_gid; +int hide_pid; +bool hide_net; };extern struct pid_namespace init_pid_ns;
include/net/net_namespace.h +2 -0
@@ -113,6 +113,8 @@ static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns) }#endif /* CONFIG_NET */ +extern struct net *net_create (void ); +extern struct list_head net_namespace_list;
net/core/net_namespace.c +1 -1
@@ -216,7 +216,7 @@ static void net_free(struct net *net)kmem_cache_free (net_cachep, net); } -static struct net *net_create (void ) +struct net *net_create (void ) {struct net *net;int rv;
--
Quoted 11 lines · Vasiliy Kulikov
hidenet means
/proc/PID/netwill be accessible to processes withCAP_NET_ADMINcapability or to members of a special group.gid=XXX defines a group that will be able to gather all processes' info and network connections info.
Similar features are implemented for old kernels in -ow patches (for Linux 2.2 and 2.4) and for Linux 2.6 in -grsecurity (but both of them are implemented as configure options, not cofigurable in runtime).
Quoted 5 lines
In current version hidenet works for
CONFIG_NET_NS=yvia creating a "fake" net namespace and slipping it to nonauthorized users, resulting in users observing blank net files (like nobody use the network). IfCONFIG_NET_NS=nI don't see anything better than just fully denying access to /proc/<pid>/net. More elegant ideas are welcome.
This fake netns concept is ugly.
If you wan't deny something, why don't you return -E?
Regardless, these should be separate patch from PID stuff.
Quoted 12 lines · Alexey Dobriyan
Quoted 11 lines · Vasiliy Kulikov
hidenet means
/proc/PID/netwill be accessible to processes withCAP_NET_ADMINcapability or to members of a special group.gid=XXX defines a group that will be able to gather all processes' info and network connections info.
Similar features are implemented for old kernels in -ow patches (for Linux 2.2 and 2.4) and for Linux 2.6 in -grsecurity (but both of them are implemented as configure options, not cofigurable in runtime).
Quoted 8 lines
Quoted 5 lines
In current version hidenet works for
CONFIG_NET_NS=yvia creating a "fake" net namespace and slipping it to nonauthorized users, resulting in users observing blank net files (like nobody use the network). IfCONFIG_NET_NS=nI don't see anything better than just fully denying access to /proc/<pid>/net. More elegant ideas are welcome.This fake netns concept is ugly.
If you wan't deny something, why don't you return -E?
Sorry, I should have mentioned it. It's a workaround. The thing is that /proc/net/* is so core and existed for a long time that some programs might be confused if these files are missing or if open() returns -EXXX. netstat handles this and outputs smth like "Networking was disabled in your kernel", which is a bit confusing. Also I saw some programs didn't handle missing files at all, I recall brctl sigfaulted when he couldn't access some sysfs file.
As fake_net doesn't break something, but instead keeps some compatibility with old programs, why don't use it?
BTW, there is no fake_net in -ow or -grsecurity. I thought it might be helpful for upstream in sense of compatibility.
Quoted 1 line
Regardless, these should be separate patch from PID stuff.
No problem.
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments