]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.69/livepatch-validate-module-old-func-name-length.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.14.69 / livepatch-validate-module-old-func-name-length.patch
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
5
6 From: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
7
8 commit 6e9df95b76cad18f7b217bdad7bb8a26d63b8c47 upstream.
9
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.
15
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,
19 which can be avoided.
20
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.
24
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>
30
31 ---
32 kernel/livepatch/core.c | 6 ++++++
33 1 file changed, 6 insertions(+)
34
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)
39 return -EINVAL;
40
41 + if (strlen(func->old_name) >= KSYM_NAME_LEN)
42 + return -EINVAL;
43 +
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
48 if (!obj->funcs)
49 return -EINVAL;
50
51 + if (klp_is_module(obj) && strlen(obj->name) >= MODULE_NAME_LEN)
52 + return -EINVAL;
53 +
54 obj->patched = false;
55 obj->mod = NULL;
56