1 From 6e9df95b76cad18f7b217bdad7bb8a26d63b8c47 Mon Sep 17 00:00:00 2001
2 From: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
3 Date: Fri, 20 Jul 2018 15:16:42 +0530
4 Subject: livepatch: Validate module/old func name length
6 From: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
8 commit 6e9df95b76cad18f7b217bdad7bb8a26d63b8c47 upstream.
10 livepatch module author can pass module name/old function name with more
11 than the defined character limit. With obj->name length greater than
12 MODULE_NAME_LEN, the livepatch module gets loaded but waits forever on
13 the module specified by obj->name to be loaded. It also populates a /sys
14 directory with an untruncated object name.
16 In the case of funcs->old_name length greater then KSYM_NAME_LEN, it
17 would not match against any of the symbol table entries. Instead loop
18 through the symbol table comparing them against a nonexisting function,
21 The same issues apply, to misspelled/incorrect names. At least gatekeep
22 the modules with over the limit string length, by checking for their
23 length during livepatch module registration.
25 Cc: stable@vger.kernel.org
26 Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
27 Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
28 Signed-off-by: Jiri Kosina <jkosina@suse.cz>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
32 kernel/livepatch/core.c | 6 ++++++
33 1 file changed, 6 insertions(+)
35 --- a/kernel/livepatch/core.c
36 +++ b/kernel/livepatch/core.c
37 @@ -605,6 +605,9 @@ static int klp_init_func(struct klp_obje
38 if (!func->old_name || !func->new_func)
41 + if (strlen(func->old_name) >= KSYM_NAME_LEN)
44 INIT_LIST_HEAD(&func->stack_node);
45 func->patched = false;
46 func->transition = false;
47 @@ -678,6 +681,9 @@ static int klp_init_object(struct klp_pa
51 + if (klp_is_module(obj) && strlen(obj->name) >= MODULE_NAME_LEN)