Skip to content

Commit

Permalink
kobject_uevent: Fix OOB access within zap_modalias_env()
Browse files Browse the repository at this point in the history
zap_modalias_env() wrongly calculates size of memory block to move, so
will cause OOB memory access issue if variable MODALIAS is not the last
one within its @env parameter, fixed by correcting size to memmove.

Fixes: 9b3fa47 ("kobject: fix suppressing modalias in uevents delivered over netlink")
Cc: [email protected]
Signed-off-by: Zijun Hu <[email protected]>
Reviewed-by: Lk Sii <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
zijun-hu authored and gregkh committed Jun 12, 2024
1 parent 880f5f5 commit dd6e989
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/kobject_uevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,23 @@ static void zap_modalias_env(struct kobj_uevent_env *env)
len = strlen(env->envp[i]) + 1;

if (i != env->envp_idx - 1) {
/* @env->envp[] contains pointers to @env->buf[]
* with @env->buflen chars, and we are removing
* variable MODALIAS here pointed by @env->envp[i]
* with length @len as shown below:
*
* 0 @env->buf[] @env->buflen
* ---------------------------------------------
* ^ ^ ^ ^
* | |-> @len <-| target block |
* @env->envp[0] @env->envp[i] @env->envp[i + 1]
*
* so the "target block" indicated above is moved
* backward by @len, and its right size is
* @env->buflen - (@env->envp[i + 1] - @env->envp[0]).
*/
memmove(env->envp[i], env->envp[i + 1],
env->buflen - len);
env->buflen - (env->envp[i + 1] - env->envp[0]));

for (j = i; j < env->envp_idx - 1; j++)
env->envp[j] = env->envp[j + 1] - len;
Expand Down

0 comments on commit dd6e989

Please sign in to comment.