2007-11-20 10:45:35

by Daniel Reichelt

[permalink] [raw]
Subject: Patch: Hide process info from other users/users not in my group

Hi list,

this patch sets (if the corresponding kconfig option is active) the access
modes of /proc/<pid>-dirs to 550 instead of 555 in order to provide some
privacy to users. Tools like lsof and ps to spy out on other users become
ineffective.

Cheers,
--
Daniel Reichelt

# diff -Naur linux-2.6.23.8/fs/Kconfig linux-2.6.23.8-dhr/fs/Kconfig
--- linux-2.6.23.8/fs/Kconfig 2007-11-16 19:14:27.000000000 +0100
+++ linux-2.6.23.8-dhr/fs/Kconfig 2007-11-20 11:33:18.000000000 +0100
@@ -918,6 +918,17 @@
help
Exports the dump image of crashed kernel in ELF format.

+config PROC_SECURED_PID_DIRS
+ bool "chmod /proc/<pid>-dirs to 550"
+ depends on PROC_FS
+ default n
+ help
+ chmod /proc/<pid>-dirs to 550 instead of 555 which provides a bit
+ moreprivacy to users on your system as only the user's and the user's
+ group's process details may be viewed. Other users' tasks running on
+ the system will be completely hidden from the means of utilities like
+ ps or lsof.
+
config PROC_SYSCTL
bool "Sysctl support (/proc/sys)" if EMBEDDED
depends on PROC_FS
# diff -Naur linux-2.6.23.8/fs/proc/base.c linux-2.6.23.8-dhr/fs/proc/base.c
--- linux-2.6.23.8/fs/proc/base.c 2007-11-16 19:14:27.000000000 +0100
+++ linux-2.6.23.8-dhr/fs/proc/base.c 2007-11-20 11:31:31.000000000 +0100
@@ -2200,7 +2200,11 @@
if (!inode)
goto out;

+#ifdef CONFIG_PROC_SECURED_PID_DIRS
+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
+#else
inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
+#endif
inode->i_op = &proc_tgid_base_inode_operations;
inode->i_fop = &proc_tgid_base_operations;
inode->i_flags|=S_IMMUTABLE;


2007-11-20 17:53:24

by Johannes Weiner

[permalink] [raw]
Subject: Re: Patch: Hide process info from other users/users not in my group

Hi Daniel,

On Tue, Nov 20, 2007 at 11:34:20AM +0100, Daniel Reichelt wrote:
> # diff -Naur linux-2.6.23.8/fs/Kconfig linux-2.6.23.8-dhr/fs/Kconfig
> --- linux-2.6.23.8/fs/Kconfig 2007-11-16 19:14:27.000000000 +0100
> +++ linux-2.6.23.8-dhr/fs/Kconfig 2007-11-20 11:33:18.000000000 +0100
> @@ -918,6 +918,17 @@
> help
> Exports the dump image of crashed kernel in ELF format.
>
> +config PROC_SECURED_PID_DIRS
> + bool "chmod /proc/<pid>-dirs to 550"
> + depends on PROC_FS
> + default n
> + help
> + chmod /proc/<pid>-dirs to 550 instead of 555 which provides a bit
> + moreprivacy to users on your system as only the user's and the user's

Missing space ^.

I like the idea, but I would prefer to have three checkboxes for this option:

* Normal modes (as in how they are right now)
* User and group visible
* Visible for the owning user only

How about that?

Hannes

2007-11-20 19:50:52

by Daniel Reichelt

[permalink] [raw]
Subject: Re: Patch: Hide process info from other users/users not in my group

> I like the idea, but I would prefer to have three checkboxes for this option:
Nice addition, thanks for the input.

--- linux-2.6.23.8/fs/Kconfig 2007-11-16 19:14:27.000000000 +0100
+++ linux-2.6.23.8-dhr/fs/Kconfig 2007-11-20 19:54:54.000000000 +0100
@@ -918,6 +918,36 @@
help
Exports the dump image of crashed kernel in ELF format.

+choice
+ prompt "Restrict access to /proc/<pid>-dirs"
+ default PROC_PIDDIRS_UNRESTRICTED
+config PROC_PIDDIRS_UNRESTRICTED
+ bool "no restriction"
+ depends on PROC_FS
+ help
+ Don't restrict access to /proc/<pid>-dirs, i.e. leave mode at 555
+ respectively r-xr-xr-x . This is the traditional mode of operation.
+
+ If unsure, say Y.
+config PROC_PIDDIRS_RESTRICT_TO_UG
+ bool "restrict to user and group
+ depends on PROC_FS
+ help
+ Restrict access to /proc/<pid>-dirs to user and group, i.e. set mode
+ to 550 respectively r-xr-x--- .
+
+ If unsure, say N.
+
+config PROC_PIDDIRS_RESTRICT_TO_U
+ bool "restrict to user
+ depends on PROC_FS
+ help
+ Restrict access to /proc/<pid>-dirs to user only, i.e. set mode to
+ 500 respectively r-x------ .
+
+ If unsure, say N.
+endchoice
+
config PROC_SYSCTL
bool "Sysctl support (/proc/sys)" if EMBEDDED
depends on PROC_FS
--- linux-2.6.23.8/fs/proc/base.c 2007-11-16 19:14:27.000000000 +0100
+++ linux-2.6.23.8-dhr/fs/proc/base.c 2007-11-20 20:01:33.000000000 +0100
@@ -2200,7 +2200,13 @@
if (!inode)
goto out;

+#ifdef CONFIG_PROC_PIDDIRS_UNRESTRICTED
inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
+#elifdef CONFIG_PROC_PIDDIRS_RESTRICT_TO_UG
+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
+#elifdef CONFIG_PROC_PIDDIRS_RESTRICT_TO_U
+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
+#endif
inode->i_op = &proc_tgid_base_inode_operations;
inode->i_fop = &proc_tgid_base_operations;
inode->i_flags|=S_IMMUTABLE;


--
Daniel

2007-11-21 10:58:00

by Daniel Reichelt

[permalink] [raw]
Subject: Re: Patch: Hide process info from other users/users not in my group

Hi,

sorry, I messed up the #ifdef directives (confused them with C++...). Here's
the really working patch:

--- linux-2.6.23.8/fs/Kconfig 2007-11-16 19:14:27.000000000 +0100
+++ linux-2.6.23.8-dhr/fs/Kconfig 2007-11-20 19:54:54.000000000 +0100
@@ -918,6 +918,36 @@
help
Exports the dump image of crashed kernel in ELF format.

+choice
+ prompt "Restrict access to /proc/<pid>-dirs"
+ default PROC_PIDDIRS_UNRESTRICTED
+config PROC_PIDDIRS_UNRESTRICTED
+ bool "no restriction"
+ depends on PROC_FS
+ help
+ Don't restrict access to /proc/<pid>-dirs, i.e. leave mode at 555
+ respectively r-xr-xr-x . This is the traditional mode of operation.
+
+ If unsure, say Y.
+config PROC_PIDDIRS_RESTRICT_TO_UG
+ bool "restrict to user and group
+ depends on PROC_FS
+ help
+ Restrict access to /proc/<pid>-dirs to user and group, i.e. set mode
+ to 550 respectively r-xr-x--- .
+
+ If unsure, say N.
+
+config PROC_PIDDIRS_RESTRICT_TO_U
+ bool "restrict to user
+ depends on PROC_FS
+ help
+ Restrict access to /proc/<pid>-dirs to user only, i.e. set mode to
+ 500 respectively r-x------ .
+
+ If unsure, say N.
+endchoice
+
config PROC_SYSCTL
bool "Sysctl support (/proc/sys)" if EMBEDDED
depends on PROC_FS
--- linux-2.6.23.8/fs/proc/base.c 2007-11-16 19:14:27.000000000 +0100
+++ linux-2.6.23.8-dhr/fs/proc/base.c 2007-11-21 10:44:17.000000000 +0100
@@ -2200,7 +2200,13 @@
if (!inode)
goto out;

+#if defined CONFIG_PROC_PIDDIRS_UNRESTRICTED
inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
+#elif defined CONFIG_PROC_PIDDIRS_RESTRICT_TO_UG
+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
+#elif defined CONFIG_PROC_PIDDIRS_RESTRICT_TO_U
+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
+#endif
inode->i_op = &proc_tgid_base_inode_operations;
inode->i_fop = &proc_tgid_base_operations;
inode->i_flags|=S_IMMUTABLE;

--
Daniel

2007-11-25 17:26:33

by Pavel Machek

[permalink] [raw]
Subject: Re: Patch: Hide process info from other users/users not in my group

Hi!

> this patch sets (if the corresponding kconfig option is active) the access
> modes of /proc/<pid>-dirs to 550 instead of 555 in order to provide some
> privacy to users. Tools like lsof and ps to spy out on other users become
> ineffective.
>
> Cheers,
> --
> Daniel Reichelt
>
> # diff -Naur linux-2.6.23.8/fs/Kconfig linux-2.6.23.8-dhr/fs/Kconfig
> --- linux-2.6.23.8/fs/Kconfig 2007-11-16 19:14:27.000000000 +0100
> +++ linux-2.6.23.8-dhr/fs/Kconfig 2007-11-20 11:33:18.000000000 +0100
> @@ -918,6 +918,17 @@
> help
> Exports the dump image of crashed kernel in ELF format.
>
> +config PROC_SECURED_PID_DIRS
> + bool "chmod /proc/<pid>-dirs to 550"
> + depends on PROC_FS
> + default n
> + help
> + chmod /proc/<pid>-dirs to 550 instead of 555 which provides a bit
> + moreprivacy to users on your system as only the user's and the user's
> + group's process details may be viewed. Other users' tasks running on
> + the system will be completely hidden from the means of utilities like
> + ps or lsof.
> +

This really needs to be runtime-configurable.

--
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2007-11-25 17:44:22

by Daniel Reichelt

[permalink] [raw]
Subject: Re: Patch: Hide process info from other users/users not in my group

Hi Pavel,

> This really needs to be runtime-configurable.
Hm. When this setting is changed during runtime, all the pre-existing
permissions would have to be changed as weill which might be done by iterating
through a list of running processes. Unfortunately I don't know how to do that.
This is my very first kernel patch (ever) and if I'd try to code s.th. like
that, I'd probably conjure race-conditions and other beasts... If you're
willing to help me, we might come up with a solution...

cu
Daniel