Skip to content

Commit

Permalink
gpio: sim: fix memory corruption when adding named lines and unnamed …
Browse files Browse the repository at this point in the history
…hogs

[ Upstream commit 95ae997 ]

When constructing the sim, gpio-sim constructs an array of named lines,
sized based on the largest offset of any named line, and then initializes
that array with the names of all lines, including unnamed hogs with higher
offsets.  In doing so it writes NULLs beyond the extent of the array.

Add a check that only named lines are used to initialize the array.

Fixes: cb8c474 ("gpio: sim: new testing module")
Signed-off-by: Kent Gibson<warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
warthog618 authored and gregkh committed Jun 14, 2023
1 parent 2ac1d1f commit 2a13736
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/gpio/gpio-sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,10 @@ static char **gpio_sim_make_line_names(struct gpio_sim_bank *bank,
if (!line_names)
return ERR_PTR(-ENOMEM);

list_for_each_entry(line, &bank->line_list, siblings)
line_names[line->offset] = line->name;
list_for_each_entry(line, &bank->line_list, siblings) {
if (line->name && (line->offset <= max_offset))
line_names[line->offset] = line->name;
}

return line_names;
}
Expand Down

0 comments on commit 2a13736

Please sign in to comment.