Skip to content

Commit 2a8c3a6

Browse files
committed
Merge branch 'for-5.12-no_hash_pointers' into for-linus
2 parents 8a8109f + 5ead723 commit 2a8c3a6

File tree

5 files changed

+72
-12
lines changed

5 files changed

+72
-12
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,6 +3281,21 @@
32813281
in certain environments such as networked servers or
32823282
real-time systems.
32833283

3284+
no_hash_pointers
3285+
Force pointers printed to the console or buffers to be
3286+
unhashed. By default, when a pointer is printed via %p
3287+
format string, that pointer is "hashed", i.e. obscured
3288+
by hashing the pointer value. This is a security feature
3289+
that hides actual kernel addresses from unprivileged
3290+
users, but it also makes debugging the kernel more
3291+
difficult since unequal pointers can no longer be
3292+
compared. However, if this command-line option is
3293+
specified, then all normal pointers will have their true
3294+
value printed. Pointers printed via %pK may still be
3295+
hashed. This option should only be specified when
3296+
debugging the kernel. Please do not use on production
3297+
kernels.
3298+
32843299
nohibernate [HIBERNATION] Disable hibernation and resume.
32853300

32863301
nohz= [KNL] Boottime enable/disable dynamic ticks

lib/test_bitmap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
#include "../tools/testing/selftests/kselftest_module.h"
1818

19-
static unsigned total_tests __initdata;
20-
static unsigned failed_tests __initdata;
19+
KSTM_MODULE_GLOBALS();
2120

2221
static char pbl_buffer[PAGE_SIZE] __initdata;
2322

lib/test_printf.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
#define PAD_SIZE 16
3131
#define FILL_CHAR '$'
3232

33-
static unsigned total_tests __initdata;
34-
static unsigned failed_tests __initdata;
33+
KSTM_MODULE_GLOBALS();
34+
3535
static char *test_buffer __initdata;
3636
static char *alloced_buffer __initdata;
3737

38+
extern bool no_hash_pointers;
39+
3840
static int __printf(4, 0) __init
3941
do_test(int bufsize, const char *expect, int elen,
4042
const char *fmt, va_list ap)
@@ -301,6 +303,12 @@ plain(void)
301303
{
302304
int err;
303305

306+
if (no_hash_pointers) {
307+
pr_warn("skipping plain 'p' tests");
308+
skipped_tests += 2;
309+
return;
310+
}
311+
304312
err = plain_hash();
305313
if (err) {
306314
pr_warn("plain 'p' does not appear to be hashed\n");

lib/vsprintf.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,32 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode,
20902090
return widen_string(buf, buf - buf_start, end, spec);
20912091
}
20922092

2093+
/* Disable pointer hashing if requested */
2094+
bool no_hash_pointers __ro_after_init;
2095+
EXPORT_SYMBOL_GPL(no_hash_pointers);
2096+
2097+
static int __init no_hash_pointers_enable(char *str)
2098+
{
2099+
no_hash_pointers = true;
2100+
2101+
pr_warn("**********************************************************\n");
2102+
pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n");
2103+
pr_warn("** **\n");
2104+
pr_warn("** This system shows unhashed kernel memory addresses **\n");
2105+
pr_warn("** via the console, logs, and other interfaces. This **\n");
2106+
pr_warn("** might reduce the security of your system. **\n");
2107+
pr_warn("** **\n");
2108+
pr_warn("** If you see this message and you are not debugging **\n");
2109+
pr_warn("** the kernel, report this immediately to your system **\n");
2110+
pr_warn("** administrator! **\n");
2111+
pr_warn("** **\n");
2112+
pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n");
2113+
pr_warn("**********************************************************\n");
2114+
2115+
return 0;
2116+
}
2117+
early_param("no_hash_pointers", no_hash_pointers_enable);
2118+
20932119
/*
20942120
* Show a '%p' thing. A kernel extension is that the '%p' is followed
20952121
* by an extra set of alphanumeric characters that are extended format
@@ -2297,8 +2323,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
22972323
}
22982324
}
22992325

2300-
/* default is to _not_ leak addresses, hash before printing */
2301-
return ptr_to_id(buf, end, ptr, spec);
2326+
/*
2327+
* default is to _not_ leak addresses, so hash before printing,
2328+
* unless no_hash_pointers is specified on the command line.
2329+
*/
2330+
if (unlikely(no_hash_pointers))
2331+
return pointer_string(buf, end, ptr, spec);
2332+
else
2333+
return ptr_to_id(buf, end, ptr, spec);
23022334
}
23032335

23042336
/*

tools/testing/selftests/kselftest_module.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
#define KSTM_MODULE_GLOBALS() \
1313
static unsigned int total_tests __initdata; \
14-
static unsigned int failed_tests __initdata
14+
static unsigned int failed_tests __initdata; \
15+
static unsigned int skipped_tests __initdata
1516

1617
#define KSTM_CHECK_ZERO(x) do { \
1718
total_tests++; \
@@ -21,11 +22,16 @@ static unsigned int failed_tests __initdata
2122
} \
2223
} while (0)
2324

24-
static inline int kstm_report(unsigned int total_tests, unsigned int failed_tests)
25+
static inline int kstm_report(unsigned int total_tests, unsigned int failed_tests,
26+
unsigned int skipped_tests)
2527
{
26-
if (failed_tests == 0)
27-
pr_info("all %u tests passed\n", total_tests);
28-
else
28+
if (failed_tests == 0) {
29+
if (skipped_tests) {
30+
pr_info("skipped %u tests\n", skipped_tests);
31+
pr_info("remaining %u tests passed\n", total_tests);
32+
} else
33+
pr_info("all %u tests passed\n", total_tests);
34+
} else
2935
pr_warn("failed %u out of %u tests\n", failed_tests, total_tests);
3036

3137
return failed_tests ? -EINVAL : 0;
@@ -36,7 +42,7 @@ static int __init __module##_init(void) \
3642
{ \
3743
pr_info("loaded.\n"); \
3844
selftest(); \
39-
return kstm_report(total_tests, failed_tests); \
45+
return kstm_report(total_tests, failed_tests, skipped_tests); \
4046
} \
4147
static void __exit __module##_exit(void) \
4248
{ \

0 commit comments

Comments
 (0)