linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] livepatch: Validate module/old func name length
@ 2018-07-20  9:46 Kamalesh Babulal
  2018-07-20 17:20 ` Josh Poimboeuf
  2018-07-23 10:12 ` Jiri Kosina
  0 siblings, 2 replies; 3+ messages in thread
From: Kamalesh Babulal @ 2018-07-20  9:46 UTC (permalink / raw)
  To: Josh Poimboeuf, Petr Mladek, Miroslav Benes
  Cc: Kamalesh Babulal, Jiri Kosina, live-patching, linux-kernel

livepatch module author can pass module name/old function name with more
than the defined character limit. With obj->name length greater than
MODULE_NAME_LEN, the livepatch module gets loaded but waits forever on
the module specified by obj->name to be loaded. It also populates a /sys
directory with an untruncated object name.

In the case of funcs->old_name length greater then KSYM_NAME_LEN, it
would not match against any of the symbol table entries. Instead loop
through the symbol table comparing them against a nonexisting function,
which can be avoided.

The same issues apply, to misspelled/incorrect names. At least gatekeep
the modules with over the limit string length, by checking for their
length during livepatch module registration.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
---
 kernel/livepatch/core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 3a4656fb7047..5b77a7314e01 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -678,6 +678,9 @@ static int klp_init_func(struct klp_object *obj, struct klp_func *func)
 	if (!func->old_name || !func->new_func)
 		return -EINVAL;
 
+	if (strlen(func->old_name) >= KSYM_NAME_LEN)
+		return -EINVAL;
+
 	INIT_LIST_HEAD(&func->stack_node);
 	func->patched = false;
 	func->transition = false;
@@ -751,6 +754,9 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
 	if (!obj->funcs)
 		return -EINVAL;
 
+	if (klp_is_module(obj) && strlen(obj->name) >= MODULE_NAME_LEN)
+		return -EINVAL;
+
 	obj->patched = false;
 	obj->mod = NULL;
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] livepatch: Validate module/old func name length
  2018-07-20  9:46 [PATCH] livepatch: Validate module/old func name length Kamalesh Babulal
@ 2018-07-20 17:20 ` Josh Poimboeuf
  2018-07-23 10:12 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Josh Poimboeuf @ 2018-07-20 17:20 UTC (permalink / raw)
  To: Kamalesh Babulal
  Cc: Petr Mladek, Miroslav Benes, Jiri Kosina, live-patching, linux-kernel

On Fri, Jul 20, 2018 at 03:16:42PM +0530, Kamalesh Babulal wrote:
> livepatch module author can pass module name/old function name with more
> than the defined character limit. With obj->name length greater than
> MODULE_NAME_LEN, the livepatch module gets loaded but waits forever on
> the module specified by obj->name to be loaded. It also populates a /sys
> directory with an untruncated object name.
> 
> In the case of funcs->old_name length greater then KSYM_NAME_LEN, it
> would not match against any of the symbol table entries. Instead loop
> through the symbol table comparing them against a nonexisting function,
> which can be avoided.
> 
> The same issues apply, to misspelled/incorrect names. At least gatekeep
> the modules with over the limit string length, by checking for their
> length during livepatch module registration.
> 
> Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>

Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>

> ---
>  kernel/livepatch/core.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> index 3a4656fb7047..5b77a7314e01 100644
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> @@ -678,6 +678,9 @@ static int klp_init_func(struct klp_object *obj, struct klp_func *func)
>  	if (!func->old_name || !func->new_func)
>  		return -EINVAL;
>  
> +	if (strlen(func->old_name) >= KSYM_NAME_LEN)
> +		return -EINVAL;
> +
>  	INIT_LIST_HEAD(&func->stack_node);
>  	func->patched = false;
>  	func->transition = false;
> @@ -751,6 +754,9 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
>  	if (!obj->funcs)
>  		return -EINVAL;
>  
> +	if (klp_is_module(obj) && strlen(obj->name) >= MODULE_NAME_LEN)
> +		return -EINVAL;
> +
>  	obj->patched = false;
>  	obj->mod = NULL;
>  
> -- 
> 2.7.4
> 

-- 
Josh

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] livepatch: Validate module/old func name length
  2018-07-20  9:46 [PATCH] livepatch: Validate module/old func name length Kamalesh Babulal
  2018-07-20 17:20 ` Josh Poimboeuf
@ 2018-07-23 10:12 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2018-07-23 10:12 UTC (permalink / raw)
  To: Kamalesh Babulal
  Cc: Josh Poimboeuf, Petr Mladek, Miroslav Benes, live-patching, linux-kernel

On Fri, 20 Jul 2018, Kamalesh Babulal wrote:

> livepatch module author can pass module name/old function name with more
> than the defined character limit. With obj->name length greater than
> MODULE_NAME_LEN, the livepatch module gets loaded but waits forever on
> the module specified by obj->name to be loaded. It also populates a /sys
> directory with an untruncated object name.
> 
> In the case of funcs->old_name length greater then KSYM_NAME_LEN, it
> would not match against any of the symbol table entries. Instead loop
> through the symbol table comparing them against a nonexisting function,
> which can be avoided.
> 
> The same issues apply, to misspelled/incorrect names. At least gatekeep
> the modules with over the limit string length, by checking for their
> length during livepatch module registration.
> 
> Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-23 10:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-20  9:46 [PATCH] livepatch: Validate module/old func name length Kamalesh Babulal
2018-07-20 17:20 ` Josh Poimboeuf
2018-07-23 10:12 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).