Skip to content

Commit bfdc0b4

Browse files
richardweinbergertorvalds
authored andcommitted
sysctl: restrict write access to dmesg_restrict
When dmesg_restrict is set to 1 CAP_SYS_ADMIN is needed to read the kernel ring buffer. But a root user without CAP_SYS_ADMIN is able to reset dmesg_restrict to 0. This is an issue when e.g. LXC (Linux Containers) are used and complete user space is running without CAP_SYS_ADMIN. A unprivileged and jailed root user can bypass the dmesg_restrict protection. With this patch writing to dmesg_restrict is only allowed when root has CAP_SYS_ADMIN. Signed-off-by: Richard Weinberger <richard@nod.at> Acked-by: Dan Rosenberg <drosenberg@vsecurity.com> Acked-by: Serge E. Hallyn <serge@hallyn.com> Cc: Eric Paris <eparis@redhat.com> Cc: Kees Cook <kees.cook@canonical.com> Cc: James Morris <jmorris@namei.org> Cc: Eugene Teo <eugeneteo@kernel.org> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent cb16e95 commit bfdc0b4

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎kernel/sysctl.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ static int proc_taint(struct ctl_table *table, int write,
170170
void __user *buffer, size_t *lenp, loff_t *ppos);
171171
#endif
172172

173+
#ifdef CONFIG_PRINTK
174+
static int proc_dmesg_restrict(struct ctl_table *table, int write,
175+
void __user *buffer, size_t *lenp, loff_t *ppos);
176+
#endif
177+
173178
#ifdef CONFIG_MAGIC_SYSRQ
174179
/* Note: sysrq code uses it's own private copy */
175180
static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
@@ -707,7 +712,7 @@ static struct ctl_table kern_table[] = {
707712
.data = &kptr_restrict,
708713
.maxlen = sizeof(int),
709714
.mode = 0644,
710-
.proc_handler = proc_dointvec_minmax,
715+
.proc_handler = proc_dmesg_restrict,
711716
.extra1 = &zero,
712717
.extra2 = &two,
713718
},
@@ -2394,6 +2399,17 @@ static int proc_taint(struct ctl_table *table, int write,
23942399
return err;
23952400
}
23962401

2402+
#ifdef CONFIG_PRINTK
2403+
static int proc_dmesg_restrict(struct ctl_table *table, int write,
2404+
void __user *buffer, size_t *lenp, loff_t *ppos)
2405+
{
2406+
if (write && !capable(CAP_SYS_ADMIN))
2407+
return -EPERM;
2408+
2409+
return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2410+
}
2411+
#endif
2412+
23972413
struct do_proc_dointvec_minmax_conv_param {
23982414
int *min;
23992415
int *max;

0 commit comments

Comments
 (0)