* [PATCH] sysctl: control functionality of /proc/pid/mem
@ 2012-01-21 8:43 Kees Cook
2012-01-21 9:03 ` Ingo Molnar
0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2012-01-21 8:43 UTC (permalink / raw)
To: linux-kernel
Cc: Linus Torvalds, Randy Dunlap, Andrew Morton, Borislav Petkov,
Vasiliy Kulikov, Dan Ballard, Jiri Kosina, Al Viro,
Stephen Wilson, David Rientjes, Ingo Molnar, Peter Zijlstra,
Eric Paris, Serge E. Hallyn, linux-doc
Add the "proc_pid_mem" sysctl to control whether or not /proc/pid/mem is
allowed to work: 0: disabled, 1: read only, 2: read/write.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Documentation/sysctl/kernel.txt | 14 ++++++++++++++
fs/proc/base.c | 11 +++++++++++
kernel/sysctl.c | 14 ++++++++++++++
3 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index 8c20fbd..6d52dba 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -56,6 +56,7 @@ show up in /proc/sys/kernel:
- printk_delay
- printk_ratelimit
- printk_ratelimit_burst
+- proc_pid_mem
- randomize_va_space
- real-root-dev ==> Documentation/initrd.txt
- reboot-cmd [ SPARC only ]
@@ -477,6 +478,19 @@ send before ratelimiting kicks in.
==============================================================
+proc_pid_mem:
+
+This option can be used to select the level of access given to potential
+ptracers when using the per-process "mem" file in /proc/pid/mem.
+
+0 - Disable entirely.
+
+1 - Allow potential ptracers read access to process memory, but not writes.
+
+2 - Allow potential ptracers read and write access to process memory.
+
+==============================================================
+
randomize_va_space:
This option can be used to select the type of process address
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 9cde9ed..35f4651 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -109,6 +109,8 @@ struct pid_entry {
union proc_op op;
};
+int sysctl_proc_pid_mem = 2;
+
#define NOD(NAME, MODE, IOP, FOP, OP) { \
.name = (NAME), \
.len = sizeof(NAME) - 1, \
@@ -702,6 +704,9 @@ static int mem_open(struct inode* inode, struct file* file)
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
struct mm_struct *mm;
+ if (sysctl_proc_pid_mem < 1)
+ return -EACCES;
+
if (!task)
return -ESRCH;
@@ -726,6 +731,9 @@ static ssize_t mem_read(struct file * file, char __user * buf,
unsigned long src = *ppos;
struct mm_struct *mm = file->private_data;
+ if (sysctl_proc_pid_mem < 1)
+ return -EACCES;
+
if (!mm)
return 0;
@@ -770,6 +778,9 @@ static ssize_t mem_write(struct file * file, const char __user *buf,
unsigned long dst = *ppos;
struct mm_struct *mm = file->private_data;
+ if (sysctl_proc_pid_mem < 2)
+ return -EACCES;
+
if (!mm)
return 0;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index f487f25..dda911f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -109,6 +109,9 @@ extern int sysctl_nr_trim_pages;
#ifdef CONFIG_BLOCK
extern int blk_iopoll_enabled;
#endif
+#ifdef CONFIG_PROC_FS
+extern int sysctl_proc_pid_mem;
+#endif
/* Constants used for minimum and maximum */
#ifdef CONFIG_LOCKUP_DETECTOR
@@ -1004,6 +1007,17 @@ static struct ctl_table kern_table[] = {
.proc_handler = proc_dointvec,
},
#endif
+#ifdef CONFIG_PROC_FS
+ {
+ .procname = "proc_pid_mem",
+ .data = &sysctl_proc_pid_mem,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec_minmax,
+ .extra1 = &zero,
+ .extra2 = &two,
+ },
+#endif
{ }
};
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sysctl: control functionality of /proc/pid/mem
2012-01-21 8:43 [PATCH] sysctl: control functionality of /proc/pid/mem Kees Cook
@ 2012-01-21 9:03 ` Ingo Molnar
2012-01-21 9:11 ` Kees Cook
0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2012-01-21 9:03 UTC (permalink / raw)
To: Kees Cook
Cc: linux-kernel, Linus Torvalds, Randy Dunlap, Andrew Morton,
Borislav Petkov, Vasiliy Kulikov, Dan Ballard, Jiri Kosina,
Al Viro, Stephen Wilson, David Rientjes, Peter Zijlstra,
Eric Paris, Serge E. Hallyn, linux-doc
* Kees Cook <keescook@chromium.org> wrote:
> @@ -702,6 +704,9 @@ static int mem_open(struct inode* inode, struct file* file)
> struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
> struct mm_struct *mm;
>
> + if (sysctl_proc_pid_mem < 1)
> + return -EACCES;
This looks like an unprivileged user-space triggerable memory
leak DoS. The task reference is already acquired at that point.
See how easy it is to introduce bugs with potential security
side-effects, even when the intention is to increase security?
:-)
( Btw., this is why i generally prefer 'invariant' local
variable definition blocks that have no serious side effects -
it makes the flow more obvious. Local variables slip off the
eye rather often and don't register as 'real' code.)
Thanks,
Ingo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sysctl: control functionality of /proc/pid/mem
2012-01-21 9:03 ` Ingo Molnar
@ 2012-01-21 9:11 ` Kees Cook
0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2012-01-21 9:11 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Linus Torvalds, Randy Dunlap, Andrew Morton,
Borislav Petkov, Vasiliy Kulikov, Dan Ballard, Jiri Kosina,
Al Viro, Stephen Wilson, David Rientjes, Peter Zijlstra,
Eric Paris, Serge E. Hallyn, linux-doc
On Sat, Jan 21, 2012 at 1:03 AM, Ingo Molnar <mingo@elte.hu> wrote:
> * Kees Cook <keescook@chromium.org> wrote:
>
>> @@ -702,6 +704,9 @@ static int mem_open(struct inode* inode, struct file* file)
>> struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
>> struct mm_struct *mm;
>>
>> + if (sysctl_proc_pid_mem < 1)
>> + return -EACCES;
>
> This looks like an unprivileged user-space triggerable memory
> leak DoS. The task reference is already acquired at that point.
Ah, good catch; thanks. I'll respin.
-Kees
--
Kees Cook
ChromeOS Security
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-01-21 9:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-21 8:43 [PATCH] sysctl: control functionality of /proc/pid/mem Kees Cook
2012-01-21 9:03 ` Ingo Molnar
2012-01-21 9:11 ` Kees Cook
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.