Commit 403efb44 authored by Todd Kjos's avatar Todd Kjos Committed by Greg Kroah-Hartman
Browse files

PCI: Fix reset_method_store() memory leak

[ Upstream commit 2985b184 ]

In reset_method_store(), a string is allocated via kstrndup() and assigned
to the local "options". options is then used in with strsep() to find
spaces:

  while ((name = strsep(&options, " ")) != NULL) {

If there are no remaining spaces, then options is set to NULL by strsep(),
so the subsequent kfree(options) doesn't free the memory allocated via
kstrndup().

Fix by using a separate tmp_options to iterate with strsep() so options is
preserved.

Link: https://lore.kernel.org/r/20241001231147.3583649-1-tkjos@google.com


Fixes: d88f521d ("PCI: Allow userspace to query and set device reset mechanism")
Signed-off-by: default avatarTodd Kjos <tkjos@google.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 656af7b3
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment