* [PATCH 2.6.12.3] Deny chmod in /proc/<pid>/
@ 2005-08-02 20:14 Johan Veenhuizen
2005-08-03 6:18 ` Jan Engelhardt
0 siblings, 1 reply; 5+ messages in thread
From: Johan Veenhuizen @ 2005-08-02 20:14 UTC (permalink / raw)
To: linux-kernel
Hi!
This patch tries to fix the strange behaviour in /proc/<pid>/,
where it is currently possible for the owner of a process to
temporarily chmod the entries.
Since the inodes for these entries are only temporary, the
permissions will suddenly be reset when the cache is reclaimed.
This is confusing and ugly.
The fix is simple: Deny chmod for all entries in /proc/<pid>/.
I figured this would be a lot easier than maintaining persistent
modes. The patch does also trigger an EPERM when someone tries
to chown/chgrp an entry (which is currently silently ignored).
Please send comments, corrections and suggestions.
Johan Veenhuizen
--- linux-2.6.12.3/fs/proc/base.c 2005-07-15 23:18:57.000000000 +0200
+++ linux-2.6.12.3-jpv/fs/proc/base.c 2005-08-02 20:08:36.000000000 +0200
@@ -496,6 +496,17 @@
return proc_check_root(inode);
}
+static int proc_setattr(struct dentry *dentry, struct iattr *attr)
+{
+ unsigned int ia_valid = attr->ia_valid;
+
+ if ((ia_valid & ATTR_MODE) || (ia_valid & ATTR_UID)
+ || (ia_valid & ATTR_GID))
+ return -EPERM;
+ else
+ return inode_setattr(dentry->d_inode, attr);
+}
+
extern struct seq_operations proc_pid_maps_op;
static int maps_open(struct inode *inode, struct file *file)
{
@@ -766,8 +777,13 @@
.write = oom_adjust_write,
};
+static struct inode_operations proc_default_inode_operations = {
+ .setattr = proc_setattr,
+};
+
static struct inode_operations proc_mem_inode_operations = {
.permission = proc_permission,
+ .setattr = proc_setattr,
};
#ifdef CONFIG_AUDITSYSCALL
@@ -965,7 +981,8 @@
static struct inode_operations proc_pid_link_inode_operations = {
.readlink = proc_pid_readlink,
- .follow_link = proc_pid_follow_link
+ .follow_link = proc_pid_follow_link,
+ .setattr = proc_setattr,
};
#define NUMBUF 10
@@ -1133,6 +1150,7 @@
ei->task = NULL;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
inode->i_ino = fake_ino(task->pid, ino);
+ inode->i_op = &proc_default_inode_operations;
if (!pid_alive(task))
goto out_unlock;
@@ -1349,11 +1367,13 @@
static struct inode_operations proc_fd_inode_operations = {
.lookup = proc_lookupfd,
.permission = proc_permission,
+ .setattr = proc_setattr,
};
static struct inode_operations proc_task_inode_operations = {
.lookup = proc_task_lookup,
.permission = proc_permission,
+ .setattr = proc_setattr,
};
#ifdef CONFIG_SECURITY
@@ -1627,10 +1647,12 @@
static struct inode_operations proc_tgid_base_inode_operations = {
.lookup = proc_tgid_base_lookup,
+ .setattr = proc_setattr,
};
static struct inode_operations proc_tid_base_inode_operations = {
.lookup = proc_tid_base_lookup,
+ .setattr = proc_setattr,
};
#ifdef CONFIG_SECURITY
@@ -1672,10 +1694,12 @@
static struct inode_operations proc_tgid_attr_inode_operations = {
.lookup = proc_tgid_attr_lookup,
+ .setattr = proc_setattr,
};
static struct inode_operations proc_tid_attr_inode_operations = {
.lookup = proc_tid_attr_lookup,
+ .setattr = proc_setattr,
};
#endif
@@ -1700,6 +1724,7 @@
static struct inode_operations proc_self_inode_operations = {
.readlink = proc_self_readlink,
.follow_link = proc_self_follow_link,
+ .setattr = proc_setattr,
};
/**
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 2.6.12.3] Deny chmod in /proc/<pid>/
2005-08-02 20:14 [PATCH 2.6.12.3] Deny chmod in /proc/<pid>/ Johan Veenhuizen
@ 2005-08-03 6:18 ` Jan Engelhardt
2005-08-03 10:05 ` Johan Veenhuizen
0 siblings, 1 reply; 5+ messages in thread
From: Jan Engelhardt @ 2005-08-03 6:18 UTC (permalink / raw)
To: Johan Veenhuizen; +Cc: linux-kernel
>This patch tries to fix the strange behaviour in /proc/<pid>/,
>where it is currently possible for the owner of a process to
>temporarily chmod the entries.
I am on 2.6.13-rc3-git5 and I do not see such behavior:
08:16 spectre:/proc/21345 # chown 1337 smaps
08:16 spectre:/proc/21345 # l -n smaps
-r--r--r-- 1 25121 0 0 Aug 3 08:16 smaps
08:16 spectre:/proc/21345 #
>The patch does also trigger an EPERM when someone tries
>to chown/chgrp an entry (which is currently silently ignored).
That's true. Though, chmod /proc/21345 correctly yielded EPERM.
>Please send comments, corrections and suggestions.
Jan Engelhardt
--
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2.6.12.3] Deny chmod in /proc/<pid>/
2005-08-03 6:18 ` Jan Engelhardt
@ 2005-08-03 10:05 ` Johan Veenhuizen
2005-08-04 6:06 ` Jan Engelhardt
0 siblings, 1 reply; 5+ messages in thread
From: Johan Veenhuizen @ 2005-08-03 10:05 UTC (permalink / raw)
To: Johan Veenhuizen, Jan Engelhardt; +Cc: linux-kernel
Jan Engelhardt <jengelh@linux01.gwdg.de> wrote:
>
> >This patch tries to fix the strange behaviour in /proc/<pid>/,
> >where it is currently possible for the owner of a process to
> >temporarily chmod the entries.
>
> I am on 2.6.13-rc3-git5 and I do not see such behavior:
>
> 08:16 spectre:/proc/21345 # chown 1337 smaps
> 08:16 spectre:/proc/21345 # l -n smaps
> -r--r--r-- 1 25121 0 0 Aug 3 08:16 smaps
> 08:16 spectre:/proc/21345 #
Did you mean "chmod"? And I don't even have "smaps".
I tried this on 2.6.13-rc5 to make sure it hasn't been fixed since
2.6.12.3. Here is a sample session to illustrate the problem:
$ uname -sr
Linux 2.6.13-rc5
$ ./a.out &
[2] 181
$ cd /proc/181
$ ls -l
total 0
-r-------- 1 jpv user 0 Aug 3 11:37 auxv
-r--r--r-- 1 jpv user 0 Aug 3 11:37 cmdline
lrwxrwxrwx 1 jpv user 0 Aug 3 11:37 cwd -> ...
-r-------- 1 jpv user 0 Aug 3 11:37 environ
lrwxrwxrwx 1 jpv user 0 Aug 3 11:37 exe -> ...
dr-x------ 2 jpv user 0 Aug 3 11:37 fd
-r--r--r-- 1 jpv user 0 Aug 3 11:37 maps
-rw------- 1 jpv user 0 Aug 3 11:37 mem
-r--r--r-- 1 jpv user 0 Aug 3 11:37 mounts
-rw-r--r-- 1 jpv user 0 Aug 3 11:37 oom_adj
-r--r--r-- 1 jpv user 0 Aug 3 11:37 oom_score
lrwxrwxrwx 1 jpv user 0 Aug 3 11:37 root -> /
-rw------- 1 jpv user 0 Aug 3 11:37 seccomp
-r--r--r-- 1 jpv user 0 Aug 3 11:37 stat
-r--r--r-- 1 jpv user 0 Aug 3 11:37 statm
-r--r--r-- 1 jpv user 0 Aug 3 11:37 status
dr-xr-xr-x 3 jpv user 0 Aug 3 11:37 task
-r--r--r-- 1 jpv user 0 Aug 3 11:37 wchan
$ chmod 7777 auxv cmdline environ fd m* o* s* task wchan
$ ls -l
total 0
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 auxv
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 cmdline
lrwxrwxrwx 1 jpv user 0 Aug 3 11:37 cwd -> ...
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 environ
lrwxrwxrwx 1 jpv user 0 Aug 3 11:37 exe -> ...
drwsrwsrwt 2 jpv user 0 Aug 3 11:37 fd
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 maps
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 mem
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 mounts
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 oom_adj
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 oom_score
lrwxrwxrwx 1 jpv user 0 Aug 3 11:37 root -> /
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 seccomp
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 stat
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 statm
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 status
drwsrwsrwt 3 jpv user 0 Aug 3 11:37 task
-rwsrwsrwt 1 jpv user 0 Aug 3 11:37 wchan
$ eatmem
malloc: Cannot allocate memory
$ ls -l
total 0
-r-------- 1 jpv user 0 Aug 3 11:44 auxv
-r--r--r-- 1 jpv user 0 Aug 3 11:44 cmdline
lrwxrwxrwx 1 jpv user 0 Aug 3 11:44 cwd -> ...
-r-------- 1 jpv user 0 Aug 3 11:44 environ
lrwxrwxrwx 1 jpv user 0 Aug 3 11:44 exe -> ...
dr-x------ 2 jpv user 0 Aug 3 11:44 fd
-r--r--r-- 1 jpv user 0 Aug 3 11:44 maps
-rw------- 1 jpv user 0 Aug 3 11:44 mem
-r--r--r-- 1 jpv user 0 Aug 3 11:44 mounts
-rw-r--r-- 1 jpv user 0 Aug 3 11:44 oom_adj
-r--r--r-- 1 jpv user 0 Aug 3 11:44 oom_score
lrwxrwxrwx 1 jpv user 0 Aug 3 11:44 root -> /
-rw------- 1 jpv user 0 Aug 3 11:44 seccomp
-r--r--r-- 1 jpv user 0 Aug 3 11:44 stat
-r--r--r-- 1 jpv user 0 Aug 3 11:44 statm
-r--r--r-- 1 jpv user 0 Aug 3 11:44 status
dr-xr-xr-x 3 jpv user 0 Aug 3 11:44 task
-r--r--r-- 1 jpv user 0 Aug 3 11:44 wchan
> Though, chmod /proc/21345 correctly yielded EPERM.
That's because the /proc/<pid> directories are S_IMMUTABLE, so the
problem doesn't arise there.
Johan Veenhuizen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2.6.12.3] Deny chmod in /proc/<pid>/
2005-08-03 10:05 ` Johan Veenhuizen
@ 2005-08-04 6:06 ` Jan Engelhardt
2005-08-04 10:59 ` Johan Veenhuizen
0 siblings, 1 reply; 5+ messages in thread
From: Jan Engelhardt @ 2005-08-04 6:06 UTC (permalink / raw)
To: Johan Veenhuizen; +Cc: linux-kernel
>Did you mean "chmod"?
No, I really meant chown - which just turned up another should-not-be:
no warning is generated when trying to chown;
chmod is even _persistent_ - for the moment.
>And I don't even have "smaps".
Just take any file.
Jan Engelhardt
--
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2.6.12.3] Deny chmod in /proc/<pid>/
2005-08-04 6:06 ` Jan Engelhardt
@ 2005-08-04 10:59 ` Johan Veenhuizen
0 siblings, 0 replies; 5+ messages in thread
From: Johan Veenhuizen @ 2005-08-04 10:59 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: linux-kernel
Jan Engelhardt <jengelh@linux01.gwdg.de> wrote:
>
> >Did you mean "chmod"?
>
> No, I really meant chown - which just turned up another should-not-be:
> no warning is generated when trying to chown;
> chmod is even _persistent_ - for the moment.
>
Did you even bother to read my first mail? Quoting myself:
"The patch does also trigger an EPERM when someone tries
to chown/chgrp an entry (which is currently silently ignored)."
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
and
"... it is currently possible for the owner of a process to
temporarily chmod the entries."
Those are the problems that my patch fixes! And NO, chmod is NOT
persistent. It just appears to be. The permissions are dropped
when the dentry for a file is released (and with it, the reference
to the temporary inode). (You might have understood this.
I don't know what you mean by "for the moment".)
It's a very Bad Thing that the chmod succeeds for a while, because
it gives users the impression that the files can be protected
(e.g. /proc/<pid>/cmdline). As it is now, you'll have to look
at the kernel source to figure out which files will preserve
their permissions...
> >And I don't even have "smaps".
>
> Just take any file.
Not any file exists under /proc, so I'll rather take a file that
is there for my examples.
Johan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-08-04 11:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-02 20:14 [PATCH 2.6.12.3] Deny chmod in /proc/<pid>/ Johan Veenhuizen
2005-08-03 6:18 ` Jan Engelhardt
2005-08-03 10:05 ` Johan Veenhuizen
2005-08-04 6:06 ` Jan Engelhardt
2005-08-04 10:59 ` Johan Veenhuizen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®