fs: introduce pipe-only dump mode suid_dumpable=3
Subsystems (4)
PATCH v2 1/1 fs: introduce pipe-only dump mode suid_dumpable=3
When the suid_dumpable sysctl is set to "2", and there is no core dump pipe defined in the core_pattern sysctl, a local user can cause core files to be written to root-writable directories, potentially with user-controlled content. This means an admin can unknowningly reintroduce a variation of CVE-2006-2451.
$ cat /proc/sys/fs/suid_dumpable 2 $ cat /proc/sys/kernel/core_pattern core $ ulimit -c unlimited $ cd / $ ls -l core ls: cannot access core: No such file or directory $ touch core touch: cannot touch `core': Permission denied $ OHAI="evil-string-here" ping localhost >/dev/null 2>&1 & $ pid=$! $ sleep 1 $ kill -SEGV $pid $ ls -l core -rw------- 1 root kees 458752 Jun 21 11:35 core $ sudo strings core | grep evil OHAI=evil-string-here
While cron has been fixed to abort reading a file when there is any parse error, there are still other sensitive directories that will read any file present and skip unparsable lines.
This patch introduces suid_dumpable=3 to allow privilege-changed processes to be dumped only to a pipe handler (and not directly to disk). The value of suid_dumpable=2 is now deprecated, and attempting to set this sysctl value returns -EINVAL.
---
v2:
- switch to mode 3, deprecate mode 2, suggested by Alan Cox.
--- Documentation/sysctl/fs.txt | 12 +++++----- fs/exec.c | 53 ++++++++++++++++++------------------------ kernel/sysctl.c | 31 ++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 39 deletions(-)
Documentation/sysctl/fs.txt +6 -6
@@ -167,12 +167,12 @@ or otherwise protected/tainted binaries. The modes are 1 - (debug) - all processes dump core when possible. The core dump is owned by the current user and no security is applied. This is intended for system debugging situations only. Ptrace is unchecked. -2 - (suidsafe) - any binary which normally would not be dumped is dumped - readable by root only. This allows the end user to remove - such a dump but not access it directly. For security reasons - core dumps in this mode will not overwrite one another or - other files. This mode is appropriate when administrators are - attempting to debug problems in a normal environment. +2 - (suidsafe) - no longer allowed (returns -EINVAL). +3 - (pipeforced) - any binary which normally would not be dumped is dumped + anyway, but only if a core dump pipe handler is defined (see the + "core_pattern" kernel sysctl). This mode is appropriate when + administrators are attempting to debug problems in a normal + environment. ==============================================================
fs/exec.c +23 -30
126 lines not on this page · raw message
kernel/sysctl.c +28 -3
@@ -174,6 +174,9 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos);#endif +static int proc_dointvec_suid_dumpable (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos); +#ifdef CONFIG_MAGIC_SYSRQ /* Note: sysrq code uses it's own private copy */ static int __sysrq_enabled =SYSRQ_DEFAULT_ENABLE ;
@@ -1498,9 +1501,7 @@ static struct ctl_table fs_table[] = { .data = &suid_dumpable, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = &zero, - .extra2 = &two, + .proc_handler = proc_dointvec_suid_dumpable, },#if defined(CONFIG_BINFMT_MISC ) || defined(CONFIG_BINFMT_MISC_MODULE ) {
@@ -2009,6 +2010,30 @@ int proc_dointvec_minmax(struct ctl_table *table, int write, do_proc_dointvec_minmax_conv, ¶m); } +/* Allow only the integers 0, 1, and 3. */ +static int proc_dointvec_suid_dumpable (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ +int rc, min, max; +struct do_proc_dointvec_minmax_conv_param param = { + .min = &min, + .max = &max, + }; + + min =0 ; + max =1 ; + rc =do_proc_dointvec (table, write, buffer, lenp, ppos, + do_proc_dointvec_minmax_conv, ¶m); +if (rc != -EINVAL ) +return rc; + + min =3 ; + max =3 ; + rc =do_proc_dointvec (table, write, buffer, lenp, ppos, + do_proc_dointvec_minmax_conv, ¶m); +return rc; +} + static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos,
Signature · 1 line
1.7.0.4
Quoted 6 lines
This patch introduces suid_dumpable=3 to allow privilege-changed processes to be dumped only to a pipe handler (and not directly to disk). The value of suid_dumpable=2 is now deprecated, and attempting to set this sysctl value returns
-EINVAL.Signed-off-by Kees Cook <[email protected]>
Quoted 4 lines · Kees Cook
This patch introduces suid_dumpable=3 to allow privilege-changed processes to be dumped only to a pipe handler (and not directly to disk). The value of suid_dumpable=2 is now deprecated, and attempting to set this sysctl value returns
-EINVAL.
Your patch descriptoin is wrong. Deprecate means something is encouraged not to be used not that the functionality is removed. I think what you are trying to say is that the value suid_dumpable=2 is now historic.
Your implementation is absolutely gross. Reading the value from
twice from user space?? Is an if statement that hard to code?
Eric
Quoted 27 lines
kernel/sysctl.c +24
-0+/* Allow only the integers 0, 1, and 3. */ +static int proc_dointvec_suid_dumpable (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ +int rc, min, max; +struct do_proc_dointvec_minmax_conv_param param = { + .min = &min, + .max = &max, + }; + + min =0 ; + max =1 ; + rc =do_proc_dointvec (table, write, buffer, lenp, ppos, + do_proc_dointvec_minmax_conv, ¶m); +if (rc != -EINVAL ) +return rc; + + min =3 ; + max =3 ; + rc =do_proc_dointvec (table, write, buffer, lenp, ppos, + do_proc_dointvec_minmax_conv, ¶m); +return rc; +} + static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos,
Quoted 7 lines · Eric W. Biederman
Quoted 4 lines · Kees Cook
This patch introduces suid_dumpable=3 to allow privilege-changed processes to be dumped only to a pipe handler (and not directly to disk). The value of suid_dumpable=2 is now deprecated, and attempting to set this sysctl value returns
-EINVAL.
Quoted 6 lines
Your patch descriptoin is wrong. Deprecate means something is encouraged not to be used not that the functionality is removed. I think what you are trying to say is that the value suid_dumpable=2 is now historic.
Your implementation is absolutely gross. Reading the value from twice from user space?? Is an if statement that hard to code?
I will rework this and resend.
-Kees
Signature · 2 lines
Kees Cook Chrome OS Security