Restrict unprivileged access to kernel syslog
Subsystems (4)
PATCH v2 1/1 Restrict unprivileged access to kernel syslog
The kernel syslog contains debugging information that is often useful during exploitation of other vulnerabilities, such as kernel heap addresses. Rather than futilely attempt to sanitize hundreds (or thousands) of printk statements and simultaneously cripple useful debugging functionality, it is far simpler to create an option that prevents unprivileged users from reading the syslog.
This patch, loosely based on grsecurity's GRKERNSEC_DMESG, creates the dmesg_restrict sysctl. When set to "0", the default, no restrictions are enforced. When set to "1", only users with CAP_SYS_ADMIN can read the kernel syslog via dmesg(8) or other mechanisms.
v2 adds CONFIG_SECURITY_RESTRICT_DMESG. When enabled, the default sysctl value is set to "1". When disabled, the default sysctl value is set to "0".
---
Documentation/sysctl/kernel.txt | 11 +++++++++++ include/linux/kernel.h | 1 + kernel/printk.c | 6 ++++++ kernel/sysctl.c | 9 +++++++++ security/Kconfig | 11 +++++++++++ security/commoncap.c | 2 ++ 6 files changed, 40 insertions(+), 0 deletions(-)
Documentation/sysctl/kernel.txt +11 -0
@@ -28,6 +28,7 @@ show up in /proc/sys/kernel: - core_uses_pid - ctrl-alt-del - dentry-state +- dmesg_restrict - domainname - hostname - hotplug
@@ -213,6 +214,16 @@ to decide what to do with it. ============================================================== +dmesg_restrict: + +This toggle indicates whether unprivileged users are prevented +from using dmesg(8) to view messages from the kernel's log +buffer. By default, it is set to (0), resulting in no +restrictions. When set to (1), users must have CAP_SYS_ADMIN +to use dmesg(8). + +============================================================== + domainname & hostname: These files can be used to set the NIS/YP domainname and the
include/linux/kernel.h +1 -0
@@ -293,6 +293,7 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, unsigned int interval_msec);extern int printk_delay_msec; +extern int dmesg_restrict;/* * Print a one-time message (analogous to WARN_ONCE() et al):
kernel/printk.c +6 -0
@@ -261,6 +261,12 @@ static inline void boot_delay_msec(void) }#endif +#ifdef CONFIG_SECURITY_RESTRICT_DMESG +int dmesg_restrict =1 ; +#else +int dmesg_restrict; +#endif +int do_syslog (int type,char __user *buf,int len,bool from_file) {unsigned i, j, limit, count;
kernel/sysctl.c +9 -0
@@ -704,6 +704,15 @@ static struct ctl_table kern_table[] = { },#endif { + .procname = "dmesg_restrict", + .data = &dmesg_restrict, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, + { .procname = "ngroups_max", .data = &ngroups_max, .maxlen = sizeof (int),
security/Kconfig +11 -0
@@ -39,6 +39,17 @@ config KEYS_DEBUG_PROC_KEYS If you are unsure as to whether this is required, answer N. +config SECURITY_RESTRICT_DMESG + bool "Restrict unprivileged access to the kernel syslog" + help + This enforces restrictions on unprivileged users reading the kernel + syslog via dmesg(8). + + If this option is not selected, no restrictions will be enforced + unless the dmesg_restrict sysctl is explicitly set to (1). + + If you are unsure how to answer this question, answer N. + config SECURITY bool "Enable different security models" depends on SYSFS
security/commoncap.c +2 -0
@@ -895,6 +895,8 @@ int cap_syslog(int type, bool from_file) {if (type !=SYSLOG_ACTION_OPEN && from_file)return 0 ; +if (dmesg_restrict && !capable (CAP_SYS_ADMIN )) +return -EPERM ;if ((type !=SYSLOG_ACTION_READ_ALL && type !=SYSLOG_ACTION_SIZE_BUFFER ) && !capable (CAP_SYS_ADMIN ))return -EPERM ;
Quoted 16 lines · Dan Rosenberg
The kernel syslog contains debugging information that is often useful during exploitation of other vulnerabilities, such as kernel heap addresses. Rather than futilely attempt to sanitize hundreds (or thousands) of printk statements and simultaneously cripple useful debugging functionality, it is far simpler to create an option that prevents unprivileged users from reading the syslog.
This patch, loosely based on grsecurity's
GRKERNSEC_DMESG, creates thedmesg_restrictsysctl. When set to "0", the default, no restrictions are enforced. When set to "1", only users withCAP_SYS_ADMINcan read the kernel syslog via dmesg(8) or other mechanisms.v2 adds
CONFIG_SECURITY_RESTRICT_DMESG. When enabled, the default sysctl value is set to "1". When disabled, the default sysctl value is set to "0".
Quoted 5 lines
Signed-off-by Dan Rosenberg <[email protected]>CC Linus Torvalds <[email protected]>CC Ingo Molnar <[email protected]>CC Kees Cook <[email protected]>CC stable <[email protected]>
Linus, Andrew, any objections against pushing this trivial control flag upstream out of band, after a bit of testing? It's not like it can break anything, and the flag is very useful to distros.
Thanks,
Ingo
Quoted 25 lines · On Wed, 10 Nov 2010 09:25:16 +0100 Ingo Molnar <[email protected]> wrote:
Quoted 16 lines · Dan Rosenberg
The kernel syslog contains debugging information that is often useful during exploitation of other vulnerabilities, such as kernel heap addresses. Rather than futilely attempt to sanitize hundreds (or thousands) of printk statements and simultaneously cripple useful debugging functionality, it is far simpler to create an option that prevents unprivileged users from reading the syslog.
This patch, loosely based on grsecurity's
GRKERNSEC_DMESG, creates thedmesg_restrictsysctl. When set to "0", the default, no restrictions are enforced. When set to "1", only users withCAP_SYS_ADMINcan read the kernel syslog via dmesg(8) or other mechanisms.v2 adds
CONFIG_SECURITY_RESTRICT_DMESG. When enabled, the default sysctl value is set to "1". When disabled, the default sysctl value is set to "0".Quoted 5 lines
Signed-off-by Dan Rosenberg <[email protected]>CC Linus Torvalds <[email protected]>CC Ingo Molnar <[email protected]>CC Kees Cook <[email protected]>CC stable <[email protected]>
Quoted 6 lines
Acked-by Ingo Molnar <[email protected]>Linus, Andrew, any objections against pushing this trivial control flag upstream out of band, after a bit of testing? It's not like it can break anything, and the flag is very useful to distros.
OK by me, apart from ...
a) I'd question the need for the config option. Are distros really so lame that they can't trust themselves to poke a number into procfs at boot time?
b) we have "dmesg_restrict" and "CONFIG_RESTRICT_DMESG". Less dyslexia, please.
Quoted 16 lines · Dan Rosenberg
The kernel syslog contains debugging information that is often useful during exploitation of other vulnerabilities, such as kernel heap addresses. Rather than futilely attempt to sanitize hundreds (or thousands) of printk statements and simultaneously cripple useful debugging functionality, it is far simpler to create an option that prevents unprivileged users from reading the syslog.
This patch, loosely based on grsecurity's
GRKERNSEC_DMESG, creates thedmesg_restrictsysctl. When set to "0", the default, no restrictions are enforced. When set to "1", only users withCAP_SYS_ADMINcan read the kernel syslog via dmesg(8) or other mechanisms.v2 adds
CONFIG_SECURITY_RESTRICT_DMESG. When enabled, the default sysctl value is set to "1". When disabled, the default sysctl value is set to "0".
Quoted 5 lines
Signed-off-by Dan Rosenberg <[email protected]>CC Linus Torvalds <[email protected]>CC Ingo Molnar <[email protected]>CC Kees Cook <[email protected]>CC stable <[email protected]>
As before, this looks fine and does the right thing with regard to /proc access to the kernel log.
Signature · 2 lines
Kees Cook Ubuntu Security Team
Quoted 3 lines · Andrew Morton
a) I'd question the need for the config option. Are distros really so lame that they can't trust themselves to poke a number into procfs at boot time?
short answer: yes.
* /etc/sysctl.conf is for users to override decisions distros have made, rather than a catalog of those decisions.
* Sometimes we change our mind on those decisions. Flipping a config option in the kernel means we push out an update, and forget about it. Users /etc/sysctl.conf's contain all kinds of crazyness. ask Davem about the stale TCP 'tuning' crap that lingered for years in Fedora users configs before anyone noticed.
(We could update the sysctl.conf at post-install of the kernel package,
but if you've ever seen a distro kernel packaging schema, you'd understand why adding more magic like this isn't desirable)
There's a bunch of patches we carry in Fedora that change defaults because there's no CONFIG option for them, which I've been meaning to get around to hacking up into options so we can carry a few less patches.
Dave
Quoted 5 lines · Andrew Morton
OK by me, apart from ...
a) I'd question the need for the config option. Are distros really so lame that they can't trust themselves to poke a number into procfs at boot time?
When it comes to security i personally prefer 'permanent' defaults that is a property of the booting image. I'd even change the default for the x86 defconfig for example - and we could make this option default-y in the future. (We cannot ever make the sysctl default itself default-1, it would break compatibility with old behavior.)
Quoted 2 lines
b) we have "
dmesg_restrict" and "CONFIG_RESTRICT_DMESG". Less dyslexia, please.
Good point. CONFIG_DMESG_RESTRICT is the proper hierarchical naming i suspect.
Thanks,
Ingo
Quoted 20 lines · Dave Jones
Quoted 3 lines · Andrew Morton
a) I'd question the need for the config option. Are distros really so lame that they can't trust themselves to poke a number into procfs at boot time?
short answer: yes.
*
/etc/sysctl.confis for users to override decisions distros have made, rather than a catalog of those decisions.* Sometimes we change our mind on those decisions. Flipping a config option in the kernel means we push out an update, and forget about it. Users /etc/sysctl.conf's contain all kinds of crazyness. ask Davem about the stale TCP 'tuning' crap that lingered for years in Fedora users configs before anyone noticed.
(We could update the sysctl.conf at post-install of the kernel package,
but if you've ever seen a distro kernel packaging schema, you'd understand why adding more magic like this isn't desirable)
Quoted 3 lines
There's a bunch of patches we carry in Fedora that change defaults because there's no CONFIG option for them, which I've been meaning to get around to hacking up into options so we can carry a few less patches.
_YES_.
A self-contained .config that carries all kernel related defaults is a very powerful thing. We need more of that.
Thanks,
Ingo