aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/sysctl/kernel.txt14
-rw-r--r--include/linux/printk.h1
-rw-r--r--kernel/sysctl.c10
-rw-r--r--lib/vsprintf.c22
4 files changed, 47 insertions, 0 deletions
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index 574067194f38..11d5ceda5bb0 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -34,6 +34,7 @@ show up in /proc/sys/kernel:
34- hotplug 34- hotplug
35- java-appletviewer [ binfmt_java, obsolete ] 35- java-appletviewer [ binfmt_java, obsolete ]
36- java-interpreter [ binfmt_java, obsolete ] 36- java-interpreter [ binfmt_java, obsolete ]
37- kptr_restrict
37- kstack_depth_to_print [ X86 only ] 38- kstack_depth_to_print [ X86 only ]
38- l2cr [ PPC only ] 39- l2cr [ PPC only ]
39- modprobe ==> Documentation/debugging-modules.txt 40- modprobe ==> Documentation/debugging-modules.txt
@@ -261,6 +262,19 @@ This flag controls the L2 cache of G3 processor boards. If
261 262
262============================================================== 263==============================================================
263 264
265kptr_restrict:
266
267This toggle indicates whether restrictions are placed on
268exposing kernel addresses via /proc and other interfaces. When
269kptr_restrict is set to (0), there are no restrictions. When
270kptr_restrict is set to (1), the default, kernel pointers
271printed using the %pK format specifier will be replaced with 0's
272unless the user has CAP_SYSLOG. When kptr_restrict is set to
273(2), kernel pointers printed using %pK will be replaced with 0's
274regardless of privileges.
275
276==============================================================
277
264kstack_depth_to_print: (X86 only) 278kstack_depth_to_print: (X86 only)
265 279
266Controls the number of words to print when dumping the raw 280Controls the number of words to print when dumping the raw
diff --git a/include/linux/printk.h b/include/linux/printk.h
index b772ca5fbdf0..9adfba6ec28a 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -83,6 +83,7 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
83 83
84extern int printk_delay_msec; 84extern int printk_delay_msec;
85extern int dmesg_restrict; 85extern int dmesg_restrict;
86extern int kptr_restrict;
86 87
87/* 88/*
88 * Print a one-time message (analogous to WARN_ONCE() et al): 89 * Print a one-time message (analogous to WARN_ONCE() et al):
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index ae5cbb1e3ced..c6811ee2092b 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -24,6 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/sysctl.h> 25#include <linux/sysctl.h>
26#include <linux/signal.h> 26#include <linux/signal.h>
27#include <linux/printk.h>
27#include <linux/proc_fs.h> 28#include <linux/proc_fs.h>
28#include <linux/security.h> 29#include <linux/security.h>
29#include <linux/ctype.h> 30#include <linux/ctype.h>
@@ -710,6 +711,15 @@ static struct ctl_table kern_table[] = {
710 .extra1 = &zero, 711 .extra1 = &zero,
711 .extra2 = &one, 712 .extra2 = &one,
712 }, 713 },
714 {
715 .procname = "kptr_restrict",
716 .data = &kptr_restrict,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 .proc_handler = proc_dointvec_minmax,
720 .extra1 = &zero,
721 .extra2 = &two,
722 },
713#endif 723#endif
714 { 724 {
715 .procname = "ngroups_max", 725 .procname = "ngroups_max",
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c150d3dafff4..6ff38524ec16 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -936,6 +936,8 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
936 return string(buf, end, uuid, spec); 936 return string(buf, end, uuid, spec);
937} 937}
938 938
939int kptr_restrict = 1;
940
939/* 941/*
940 * Show a '%p' thing. A kernel extension is that the '%p' is followed 942 * Show a '%p' thing. A kernel extension is that the '%p' is followed
941 * by an extra set of alphanumeric characters that are extended format 943 * by an extra set of alphanumeric characters that are extended format
@@ -979,6 +981,7 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
979 * Implements a "recursive vsnprintf". 981 * Implements a "recursive vsnprintf".
980 * Do not use this feature without some mechanism to verify the 982 * Do not use this feature without some mechanism to verify the
981 * correctness of the format string and va_list arguments. 983 * correctness of the format string and va_list arguments.
984 * - 'K' For a kernel pointer that should be hidden from unprivileged users
982 * 985 *
983 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 986 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
984 * function pointers are really function descriptors, which contain a 987 * function pointers are really function descriptors, which contain a
@@ -1035,6 +1038,25 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1035 return buf + vsnprintf(buf, end - buf, 1038 return buf + vsnprintf(buf, end - buf,
1036 ((struct va_format *)ptr)->fmt, 1039 ((struct va_format *)ptr)->fmt,
1037 *(((struct va_format *)ptr)->va)); 1040 *(((struct va_format *)ptr)->va));
1041 case 'K':
1042 /*
1043 * %pK cannot be used in IRQ context because its test
1044 * for CAP_SYSLOG would be meaningless.
1045 */
1046 if (in_irq() || in_serving_softirq() || in_nmi()) {
1047 if (spec.field_width == -1)
1048 spec.field_width = 2 * sizeof(void *);
1049 return string(buf, end, "pK-error", spec);
1050 } else if ((kptr_restrict == 0) ||
1051 (kptr_restrict == 1 &&
1052 has_capability_noaudit(current, CAP_SYSLOG)))
1053 break;
1054
1055 if (spec.field_width == -1) {
1056 spec.field_width = 2 * sizeof(void *);
1057 spec.flags |= ZEROPAD;
1058 }
1059 return number(buf, end, 0, spec);
1038 } 1060 }
1039 spec.flags |= SMALL; 1061 spec.flags |= SMALL;
1040 if (spec.field_width == -1) { 1062 if (spec.field_width == -1) {