diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-04-30 20:37:43 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-04-30 20:37:43 -0400 |
| commit | 5f56886521d6ddd3648777fae44d82382dd8c87f (patch) | |
| tree | aa0db6331cdb01c23f1884439840aadd31bbcca4 /lib | |
| parent | f1e9a236e5ddab6c349611ee86f54291916f226c (diff) | |
| parent | e2a8b0a779787314eca1061308a8182e6c5bfabd (diff) | |
Merge branch 'akpm' (incoming from Andrew)
Merge third batch of fixes from Andrew Morton:
"Most of the rest. I still have two large patchsets against AIO and
IPC, but they're a bit stuck behind other trees and I'm about to
vanish for six days.
- random fixlets
- inotify
- more of the MM queue
- show_stack() cleanups
- DMI update
- kthread/workqueue things
- compat cleanups
- epoll udpates
- binfmt updates
- nilfs2
- hfs
- hfsplus
- ptrace
- kmod
- coredump
- kexec
- rbtree
- pids
- pidns
- pps
- semaphore tweaks
- some w1 patches
- relay updates
- core Kconfig changes
- sysrq tweaks"
* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (109 commits)
Documentation/sysrq: fix inconstistent help message of sysrq key
ethernet/emac/sysrq: fix inconstistent help message of sysrq key
sparc/sysrq: fix inconstistent help message of sysrq key
powerpc/xmon/sysrq: fix inconstistent help message of sysrq key
ARM/etm/sysrq: fix inconstistent help message of sysrq key
power/sysrq: fix inconstistent help message of sysrq key
kgdb/sysrq: fix inconstistent help message of sysrq key
lib/decompress.c: fix initconst
notifier-error-inject: fix module names in Kconfig
kernel/sys.c: make prctl(PR_SET_MM) generally available
UAPI: remove empty Kbuild files
menuconfig: print more info for symbol without prompts
init/Kconfig: re-order CONFIG_EXPERT options to fix menuconfig display
kconfig menu: move Virtualization drivers near other virtualization options
Kconfig: consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
relay: use macro PAGE_ALIGN instead of FIX_SIZE
kernel/relay.c: move FIX_SIZE macro into relay.c
kernel/relay.c: remove unused function argument actor
drivers/w1/slaves/w1_ds2760.c: fix the error handling in w1_ds2760_add_slave()
drivers/w1/slaves/w1_ds2781.c: fix the error handling in w1_ds2781_add_slave()
...
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Kconfig.debug | 25 | ||||
| -rw-r--r-- | lib/Makefile | 5 | ||||
| -rw-r--r-- | lib/decompress.c | 2 | ||||
| -rw-r--r-- | lib/dump_stack.c | 11 | ||||
| -rw-r--r-- | lib/dynamic_debug.c | 48 | ||||
| -rw-r--r-- | lib/rbtree_test.c | 9 | ||||
| -rw-r--r-- | lib/string_helpers.c | 133 | ||||
| -rw-r--r-- | lib/test-string_helpers.c | 103 | ||||
| -rw-r--r-- | lib/usercopy.c | 9 |
9 files changed, 291 insertions, 54 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 28be08c09bab..566cf2bc08ea 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
| @@ -1192,7 +1192,7 @@ config MEMORY_NOTIFIER_ERROR_INJECT | |||
| 1192 | bash: echo: write error: Cannot allocate memory | 1192 | bash: echo: write error: Cannot allocate memory |
| 1193 | 1193 | ||
| 1194 | To compile this code as a module, choose M here: the module will | 1194 | To compile this code as a module, choose M here: the module will |
| 1195 | be called pSeries-reconfig-notifier-error-inject. | 1195 | be called memory-notifier-error-inject. |
| 1196 | 1196 | ||
| 1197 | If unsure, say N. | 1197 | If unsure, say N. |
| 1198 | 1198 | ||
| @@ -1209,7 +1209,7 @@ config OF_RECONFIG_NOTIFIER_ERROR_INJECT | |||
| 1209 | notified, write the error code to "actions/<notifier event>/error". | 1209 | notified, write the error code to "actions/<notifier event>/error". |
| 1210 | 1210 | ||
| 1211 | To compile this code as a module, choose M here: the module will | 1211 | To compile this code as a module, choose M here: the module will |
| 1212 | be called memory-notifier-error-inject. | 1212 | be called of-reconfig-notifier-error-inject. |
| 1213 | 1213 | ||
| 1214 | If unsure, say N. | 1214 | If unsure, say N. |
| 1215 | 1215 | ||
| @@ -1292,6 +1292,24 @@ config LATENCYTOP | |||
| 1292 | Enable this option if you want to use the LatencyTOP tool | 1292 | Enable this option if you want to use the LatencyTOP tool |
| 1293 | to find out which userspace is blocking on what kernel operations. | 1293 | to find out which userspace is blocking on what kernel operations. |
| 1294 | 1294 | ||
| 1295 | config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS | ||
| 1296 | bool | ||
| 1297 | |||
| 1298 | config DEBUG_STRICT_USER_COPY_CHECKS | ||
| 1299 | bool "Strict user copy size checks" | ||
| 1300 | depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS | ||
| 1301 | depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING | ||
| 1302 | help | ||
| 1303 | Enabling this option turns a certain set of sanity checks for user | ||
| 1304 | copy operations into compile time failures. | ||
| 1305 | |||
| 1306 | The copy_from_user() etc checks are there to help test if there | ||
| 1307 | are sufficient security checks on the length argument of | ||
| 1308 | the copy operation, by having gcc prove that the argument is | ||
| 1309 | within bounds. | ||
| 1310 | |||
| 1311 | If unsure, say N. | ||
| 1312 | |||
| 1295 | source mm/Kconfig.debug | 1313 | source mm/Kconfig.debug |
| 1296 | source kernel/trace/Kconfig | 1314 | source kernel/trace/Kconfig |
| 1297 | 1315 | ||
| @@ -1463,5 +1481,8 @@ source "lib/Kconfig.kgdb" | |||
| 1463 | 1481 | ||
| 1464 | source "lib/Kconfig.kmemcheck" | 1482 | source "lib/Kconfig.kmemcheck" |
| 1465 | 1483 | ||
| 1484 | config TEST_STRING_HELPERS | ||
| 1485 | tristate "Test functions located in the string_helpers module at runtime" | ||
| 1486 | |||
| 1466 | config TEST_KSTRTOX | 1487 | config TEST_KSTRTOX |
| 1467 | tristate "Test kstrto*() family of functions at runtime" | 1488 | tristate "Test kstrto*() family of functions at runtime" |
diff --git a/lib/Makefile b/lib/Makefile index 6e2cc561f761..e9c52e1b853a 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
| @@ -15,6 +15,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ | |||
| 15 | is_single_threaded.o plist.o decompress.o kobject_uevent.o \ | 15 | is_single_threaded.o plist.o decompress.o kobject_uevent.o \ |
| 16 | earlycpio.o | 16 | earlycpio.o |
| 17 | 17 | ||
| 18 | obj-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o | ||
| 18 | lib-$(CONFIG_MMU) += ioremap.o | 19 | lib-$(CONFIG_MMU) += ioremap.o |
| 19 | lib-$(CONFIG_SMP) += cpumask.o | 20 | lib-$(CONFIG_SMP) += cpumask.o |
| 20 | 21 | ||
| @@ -22,8 +23,10 @@ lib-y += kobject.o klist.o | |||
| 22 | 23 | ||
| 23 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 24 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
| 24 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 25 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
| 25 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ | 26 | gcd.o lcm.o list_sort.o uuid.o flex_array.o \ |
| 26 | bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o | 27 | bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o |
| 28 | obj-y += string_helpers.o | ||
| 29 | obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o | ||
| 27 | obj-y += kstrtox.o | 30 | obj-y += kstrtox.o |
| 28 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | 31 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o |
| 29 | 32 | ||
diff --git a/lib/decompress.c b/lib/decompress.c index 31a804277282..f8fdedaf7b3d 100644 --- a/lib/decompress.c +++ b/lib/decompress.c | |||
| @@ -38,7 +38,7 @@ struct compress_format { | |||
| 38 | decompress_fn decompressor; | 38 | decompress_fn decompressor; |
| 39 | }; | 39 | }; |
| 40 | 40 | ||
| 41 | static const struct compress_format compressed_formats[] __initdata = { | 41 | static const struct compress_format compressed_formats[] __initconst = { |
| 42 | { {037, 0213}, "gzip", gunzip }, | 42 | { {037, 0213}, "gzip", gunzip }, |
| 43 | { {037, 0236}, "gzip", gunzip }, | 43 | { {037, 0236}, "gzip", gunzip }, |
| 44 | { {0x42, 0x5a}, "bzip2", bunzip2 }, | 44 | { {0x42, 0x5a}, "bzip2", bunzip2 }, |
diff --git a/lib/dump_stack.c b/lib/dump_stack.c index 42f4f55c9458..53bad099ebd6 100644 --- a/lib/dump_stack.c +++ b/lib/dump_stack.c | |||
| @@ -5,11 +5,16 @@ | |||
| 5 | 5 | ||
| 6 | #include <linux/kernel.h> | 6 | #include <linux/kernel.h> |
| 7 | #include <linux/export.h> | 7 | #include <linux/export.h> |
| 8 | #include <linux/sched.h> | ||
| 8 | 9 | ||
| 10 | /** | ||
| 11 | * dump_stack - dump the current task information and its stack trace | ||
| 12 | * | ||
| 13 | * Architectures can override this implementation by implementing its own. | ||
| 14 | */ | ||
| 9 | void dump_stack(void) | 15 | void dump_stack(void) |
| 10 | { | 16 | { |
| 11 | printk(KERN_NOTICE | 17 | dump_stack_print_info(KERN_DEFAULT); |
| 12 | "This architecture does not implement dump_stack()\n"); | 18 | show_stack(NULL, NULL); |
| 13 | } | 19 | } |
| 14 | |||
| 15 | EXPORT_SYMBOL(dump_stack); | 20 | EXPORT_SYMBOL(dump_stack); |
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 46032453abd5..99fec3ae405a 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include <linux/sysctl.h> | 24 | #include <linux/sysctl.h> |
| 25 | #include <linux/ctype.h> | 25 | #include <linux/ctype.h> |
| 26 | #include <linux/string.h> | 26 | #include <linux/string.h> |
| 27 | #include <linux/string_helpers.h> | ||
| 27 | #include <linux/uaccess.h> | 28 | #include <linux/uaccess.h> |
| 28 | #include <linux/dynamic_debug.h> | 29 | #include <linux/dynamic_debug.h> |
| 29 | #include <linux/debugfs.h> | 30 | #include <linux/debugfs.h> |
| @@ -276,47 +277,6 @@ static inline int parse_lineno(const char *str, unsigned int *val) | |||
| 276 | return 0; | 277 | return 0; |
| 277 | } | 278 | } |
| 278 | 279 | ||
| 279 | /* | ||
| 280 | * Undo octal escaping in a string, inplace. This is useful to | ||
| 281 | * allow the user to express a query which matches a format | ||
| 282 | * containing embedded spaces. | ||
| 283 | */ | ||
| 284 | static char *unescape(char *str) | ||
| 285 | { | ||
| 286 | char *in = str; | ||
| 287 | char *out = str; | ||
| 288 | |||
| 289 | while (*in) { | ||
| 290 | if (*in == '\\') { | ||
| 291 | if (in[1] == '\\') { | ||
| 292 | *out++ = '\\'; | ||
| 293 | in += 2; | ||
| 294 | continue; | ||
| 295 | } else if (in[1] == 't') { | ||
| 296 | *out++ = '\t'; | ||
| 297 | in += 2; | ||
| 298 | continue; | ||
| 299 | } else if (in[1] == 'n') { | ||
| 300 | *out++ = '\n'; | ||
| 301 | in += 2; | ||
| 302 | continue; | ||
| 303 | } else if (isodigit(in[1]) && | ||
| 304 | isodigit(in[2]) && | ||
| 305 | isodigit(in[3])) { | ||
| 306 | *out++ = (((in[1] - '0') << 6) | | ||
| 307 | ((in[2] - '0') << 3) | | ||
| 308 | (in[3] - '0')); | ||
| 309 | in += 4; | ||
| 310 | continue; | ||
| 311 | } | ||
| 312 | } | ||
| 313 | *out++ = *in++; | ||
| 314 | } | ||
| 315 | *out = '\0'; | ||
| 316 | |||
| 317 | return str; | ||
| 318 | } | ||
| 319 | |||
| 320 | static int check_set(const char **dest, char *src, char *name) | 280 | static int check_set(const char **dest, char *src, char *name) |
| 321 | { | 281 | { |
| 322 | int rc = 0; | 282 | int rc = 0; |
| @@ -370,8 +330,10 @@ static int ddebug_parse_query(char *words[], int nwords, | |||
| 370 | } else if (!strcmp(words[i], "module")) { | 330 | } else if (!strcmp(words[i], "module")) { |
| 371 | rc = check_set(&query->module, words[i+1], "module"); | 331 | rc = check_set(&query->module, words[i+1], "module"); |
| 372 | } else if (!strcmp(words[i], "format")) { | 332 | } else if (!strcmp(words[i], "format")) { |
| 373 | rc = check_set(&query->format, unescape(words[i+1]), | 333 | string_unescape_inplace(words[i+1], UNESCAPE_SPACE | |
| 374 | "format"); | 334 | UNESCAPE_OCTAL | |
| 335 | UNESCAPE_SPECIAL); | ||
| 336 | rc = check_set(&query->format, words[i+1], "format"); | ||
| 375 | } else if (!strcmp(words[i], "line")) { | 337 | } else if (!strcmp(words[i], "line")) { |
| 376 | char *first = words[i+1]; | 338 | char *first = words[i+1]; |
| 377 | char *last = strchr(first, '-'); | 339 | char *last = strchr(first, '-'); |
diff --git a/lib/rbtree_test.c b/lib/rbtree_test.c index af38aedbd874..122f02f9941b 100644 --- a/lib/rbtree_test.c +++ b/lib/rbtree_test.c | |||
| @@ -117,8 +117,7 @@ static int black_path_count(struct rb_node *rb) | |||
| 117 | static void check(int nr_nodes) | 117 | static void check(int nr_nodes) |
| 118 | { | 118 | { |
| 119 | struct rb_node *rb; | 119 | struct rb_node *rb; |
| 120 | int count = 0; | 120 | int count = 0, blacks = 0; |
| 121 | int blacks = 0; | ||
| 122 | u32 prev_key = 0; | 121 | u32 prev_key = 0; |
| 123 | 122 | ||
| 124 | for (rb = rb_first(&root); rb; rb = rb_next(rb)) { | 123 | for (rb = rb_first(&root); rb; rb = rb_next(rb)) { |
| @@ -134,7 +133,9 @@ static void check(int nr_nodes) | |||
| 134 | prev_key = node->key; | 133 | prev_key = node->key; |
| 135 | count++; | 134 | count++; |
| 136 | } | 135 | } |
| 136 | |||
| 137 | WARN_ON_ONCE(count != nr_nodes); | 137 | WARN_ON_ONCE(count != nr_nodes); |
| 138 | WARN_ON_ONCE(count < (1 << black_path_count(rb_last(&root))) - 1); | ||
| 138 | } | 139 | } |
| 139 | 140 | ||
| 140 | static void check_augmented(int nr_nodes) | 141 | static void check_augmented(int nr_nodes) |
| @@ -148,7 +149,7 @@ static void check_augmented(int nr_nodes) | |||
| 148 | } | 149 | } |
| 149 | } | 150 | } |
| 150 | 151 | ||
| 151 | static int rbtree_test_init(void) | 152 | static int __init rbtree_test_init(void) |
| 152 | { | 153 | { |
| 153 | int i, j; | 154 | int i, j; |
| 154 | cycles_t time1, time2, time; | 155 | cycles_t time1, time2, time; |
| @@ -221,7 +222,7 @@ static int rbtree_test_init(void) | |||
| 221 | return -EAGAIN; /* Fail will directly unload the module */ | 222 | return -EAGAIN; /* Fail will directly unload the module */ |
| 222 | } | 223 | } |
| 223 | 224 | ||
| 224 | static void rbtree_test_exit(void) | 225 | static void __exit rbtree_test_exit(void) |
| 225 | { | 226 | { |
| 226 | printk(KERN_ALERT "test exit\n"); | 227 | printk(KERN_ALERT "test exit\n"); |
| 227 | } | 228 | } |
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 1cffc223bff5..ed5c1454dd62 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c | |||
| @@ -2,10 +2,12 @@ | |||
| 2 | * Helpers for formatting and printing strings | 2 | * Helpers for formatting and printing strings |
| 3 | * | 3 | * |
| 4 | * Copyright 31 August 2008 James Bottomley | 4 | * Copyright 31 August 2008 James Bottomley |
| 5 | * Copyright (C) 2013, Intel Corporation | ||
| 5 | */ | 6 | */ |
| 6 | #include <linux/kernel.h> | 7 | #include <linux/kernel.h> |
| 7 | #include <linux/math64.h> | 8 | #include <linux/math64.h> |
| 8 | #include <linux/export.h> | 9 | #include <linux/export.h> |
| 10 | #include <linux/ctype.h> | ||
| 9 | #include <linux/string_helpers.h> | 11 | #include <linux/string_helpers.h> |
| 10 | 12 | ||
| 11 | /** | 13 | /** |
| @@ -66,3 +68,134 @@ int string_get_size(u64 size, const enum string_size_units units, | |||
| 66 | return 0; | 68 | return 0; |
| 67 | } | 69 | } |
| 68 | EXPORT_SYMBOL(string_get_size); | 70 | EXPORT_SYMBOL(string_get_size); |
| 71 | |||
| 72 | static bool unescape_space(char **src, char **dst) | ||
| 73 | { | ||
| 74 | char *p = *dst, *q = *src; | ||
| 75 | |||
| 76 | switch (*q) { | ||
| 77 | case 'n': | ||
| 78 | *p = '\n'; | ||
| 79 | break; | ||
| 80 | case 'r': | ||
| 81 | *p = '\r'; | ||
| 82 | break; | ||
| 83 | case 't': | ||
| 84 | *p = '\t'; | ||
| 85 | break; | ||
| 86 | case 'v': | ||
| 87 | *p = '\v'; | ||
| 88 | break; | ||
| 89 | case 'f': | ||
| 90 | *p = '\f'; | ||
| 91 | break; | ||
| 92 | default: | ||
| 93 | return false; | ||
| 94 | } | ||
| 95 | *dst += 1; | ||
| 96 | *src += 1; | ||
| 97 | return true; | ||
| 98 | } | ||
| 99 | |||
| 100 | static bool unescape_octal(char **src, char **dst) | ||
| 101 | { | ||
| 102 | char *p = *dst, *q = *src; | ||
| 103 | u8 num; | ||
| 104 | |||
| 105 | if (isodigit(*q) == 0) | ||
| 106 | return false; | ||
| 107 | |||
| 108 | num = (*q++) & 7; | ||
| 109 | while (num < 32 && isodigit(*q) && (q - *src < 3)) { | ||
| 110 | num <<= 3; | ||
| 111 | num += (*q++) & 7; | ||
| 112 | } | ||
| 113 | *p = num; | ||
| 114 | *dst += 1; | ||
| 115 | *src = q; | ||
| 116 | return true; | ||
| 117 | } | ||
| 118 | |||
| 119 | static bool unescape_hex(char **src, char **dst) | ||
| 120 | { | ||
| 121 | char *p = *dst, *q = *src; | ||
| 122 | int digit; | ||
| 123 | u8 num; | ||
| 124 | |||
| 125 | if (*q++ != 'x') | ||
| 126 | return false; | ||
| 127 | |||
| 128 | num = digit = hex_to_bin(*q++); | ||
| 129 | if (digit < 0) | ||
| 130 | return false; | ||
| 131 | |||
| 132 | digit = hex_to_bin(*q); | ||
| 133 | if (digit >= 0) { | ||
| 134 | q++; | ||
| 135 | num = (num << 4) | digit; | ||
| 136 | } | ||
| 137 | *p = num; | ||
| 138 | *dst += 1; | ||
| 139 | *src = q; | ||
| 140 | return true; | ||
| 141 | } | ||
| 142 | |||
| 143 | static bool unescape_special(char **src, char **dst) | ||
| 144 | { | ||
| 145 | char *p = *dst, *q = *src; | ||
| 146 | |||
| 147 | switch (*q) { | ||
| 148 | case '\"': | ||
| 149 | *p = '\"'; | ||
| 150 | break; | ||
| 151 | case '\\': | ||
| 152 | *p = '\\'; | ||
| 153 | break; | ||
| 154 | case 'a': | ||
| 155 | *p = '\a'; | ||
| 156 | break; | ||
| 157 | case 'e': | ||
| 158 | *p = '\e'; | ||
| 159 | break; | ||
| 160 | default: | ||
| 161 | return false; | ||
| 162 | } | ||
| 163 | *dst += 1; | ||
| 164 | *src += 1; | ||
| 165 | return true; | ||
| 166 | } | ||
| 167 | |||
| 168 | int string_unescape(char *src, char *dst, size_t size, unsigned int flags) | ||
| 169 | { | ||
| 170 | char *out = dst; | ||
| 171 | |||
| 172 | while (*src && --size) { | ||
| 173 | if (src[0] == '\\' && src[1] != '\0' && size > 1) { | ||
| 174 | src++; | ||
| 175 | size--; | ||
| 176 | |||
| 177 | if (flags & UNESCAPE_SPACE && | ||
| 178 | unescape_space(&src, &out)) | ||
| 179 | continue; | ||
| 180 | |||
| 181 | if (flags & UNESCAPE_OCTAL && | ||
| 182 | unescape_octal(&src, &out)) | ||
| 183 | continue; | ||
| 184 | |||
| 185 | if (flags & UNESCAPE_HEX && | ||
| 186 | unescape_hex(&src, &out)) | ||
| 187 | continue; | ||
| 188 | |||
| 189 | if (flags & UNESCAPE_SPECIAL && | ||
| 190 | unescape_special(&src, &out)) | ||
| 191 | continue; | ||
| 192 | |||
| 193 | *out++ = '\\'; | ||
| 194 | } | ||
| 195 | *out++ = *src++; | ||
| 196 | } | ||
| 197 | *out = '\0'; | ||
| 198 | |||
| 199 | return out - dst; | ||
| 200 | } | ||
| 201 | EXPORT_SYMBOL(string_unescape); | ||
diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c new file mode 100644 index 000000000000..6ac48de04c0e --- /dev/null +++ b/lib/test-string_helpers.c | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | /* | ||
| 2 | * Test cases for lib/string_helpers.c module. | ||
| 3 | */ | ||
| 4 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 5 | |||
| 6 | #include <linux/init.h> | ||
| 7 | #include <linux/kernel.h> | ||
| 8 | #include <linux/module.h> | ||
| 9 | #include <linux/random.h> | ||
| 10 | #include <linux/string.h> | ||
| 11 | #include <linux/string_helpers.h> | ||
| 12 | |||
| 13 | struct test_string { | ||
| 14 | const char *in; | ||
| 15 | const char *out; | ||
| 16 | unsigned int flags; | ||
| 17 | }; | ||
| 18 | |||
| 19 | static const struct test_string strings[] __initconst = { | ||
| 20 | { | ||
| 21 | .in = "\\f\\ \\n\\r\\t\\v", | ||
| 22 | .out = "\f\\ \n\r\t\v", | ||
| 23 | .flags = UNESCAPE_SPACE, | ||
| 24 | }, | ||
| 25 | { | ||
| 26 | .in = "\\40\\1\\387\\0064\\05\\040\\8a\\110\\777", | ||
| 27 | .out = " \001\00387\0064\005 \\8aH?7", | ||
| 28 | .flags = UNESCAPE_OCTAL, | ||
| 29 | }, | ||
| 30 | { | ||
| 31 | .in = "\\xv\\xa\\x2c\\xD\\x6f2", | ||
| 32 | .out = "\\xv\n,\ro2", | ||
| 33 | .flags = UNESCAPE_HEX, | ||
| 34 | }, | ||
| 35 | { | ||
| 36 | .in = "\\h\\\\\\\"\\a\\e\\", | ||
| 37 | .out = "\\h\\\"\a\e\\", | ||
| 38 | .flags = UNESCAPE_SPECIAL, | ||
| 39 | }, | ||
| 40 | }; | ||
| 41 | |||
| 42 | static void __init test_string_unescape(unsigned int flags, bool inplace) | ||
| 43 | { | ||
| 44 | char in[256]; | ||
| 45 | char out_test[256]; | ||
| 46 | char out_real[256]; | ||
| 47 | int i, p = 0, q_test = 0, q_real = sizeof(out_real); | ||
| 48 | |||
| 49 | for (i = 0; i < ARRAY_SIZE(strings); i++) { | ||
| 50 | const char *s = strings[i].in; | ||
| 51 | int len = strlen(strings[i].in); | ||
| 52 | |||
| 53 | /* Copy string to in buffer */ | ||
| 54 | memcpy(&in[p], s, len); | ||
| 55 | p += len; | ||
| 56 | |||
| 57 | /* Copy expected result for given flags */ | ||
| 58 | if (flags & strings[i].flags) { | ||
| 59 | s = strings[i].out; | ||
| 60 | len = strlen(strings[i].out); | ||
| 61 | } | ||
| 62 | memcpy(&out_test[q_test], s, len); | ||
| 63 | q_test += len; | ||
| 64 | } | ||
| 65 | in[p++] = '\0'; | ||
| 66 | |||
| 67 | /* Call string_unescape and compare result */ | ||
| 68 | if (inplace) { | ||
| 69 | memcpy(out_real, in, p); | ||
| 70 | if (flags == UNESCAPE_ANY) | ||
| 71 | q_real = string_unescape_any_inplace(out_real); | ||
| 72 | else | ||
| 73 | q_real = string_unescape_inplace(out_real, flags); | ||
| 74 | } else if (flags == UNESCAPE_ANY) { | ||
| 75 | q_real = string_unescape_any(in, out_real, q_real); | ||
| 76 | } else { | ||
| 77 | q_real = string_unescape(in, out_real, q_real, flags); | ||
| 78 | } | ||
| 79 | |||
| 80 | if (q_real != q_test || memcmp(out_test, out_real, q_test)) { | ||
| 81 | pr_warn("Test failed: flags = %u\n", flags); | ||
| 82 | print_hex_dump(KERN_WARNING, "Input: ", | ||
| 83 | DUMP_PREFIX_NONE, 16, 1, in, p - 1, true); | ||
| 84 | print_hex_dump(KERN_WARNING, "Expected: ", | ||
| 85 | DUMP_PREFIX_NONE, 16, 1, out_test, q_test, true); | ||
| 86 | print_hex_dump(KERN_WARNING, "Got: ", | ||
| 87 | DUMP_PREFIX_NONE, 16, 1, out_real, q_real, true); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | static int __init test_string_helpers_init(void) | ||
| 92 | { | ||
| 93 | unsigned int i; | ||
| 94 | |||
| 95 | pr_info("Running tests...\n"); | ||
| 96 | for (i = 0; i < UNESCAPE_ANY + 1; i++) | ||
| 97 | test_string_unescape(i, false); | ||
| 98 | test_string_unescape(get_random_int() % (UNESCAPE_ANY + 1), true); | ||
| 99 | |||
| 100 | return -EINVAL; | ||
| 101 | } | ||
| 102 | module_init(test_string_helpers_init); | ||
| 103 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/lib/usercopy.c b/lib/usercopy.c new file mode 100644 index 000000000000..4f5b1ddbcd25 --- /dev/null +++ b/lib/usercopy.c | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #include <linux/export.h> | ||
| 2 | #include <linux/bug.h> | ||
| 3 | #include <linux/uaccess.h> | ||
| 4 | |||
| 5 | void copy_from_user_overflow(void) | ||
| 6 | { | ||
| 7 | WARN(1, "Buffer overflow detected!\n"); | ||
| 8 | } | ||
| 9 | EXPORT_SYMBOL(copy_from_user_overflow); | ||
