mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/
synced 2026-04-05 00:07:48 -04:00
gpiolib: fix invalid pointer access in debugfs
If the memory allocation in gpiolib_seq_start() fails, the s->private
field remains uninitialized and is later dereferenced without checking
in gpiolib_seq_stop(). Initialize s->private to NULL before calling
kzalloc() and check it before dereferencing it.
Fixes: e348544f79 ("gpio: protect the list of GPIO devices with SRCU")
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20251103141132.53471-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
@@ -5296,6 +5296,8 @@ static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos)
|
||||
struct gpio_device *gdev;
|
||||
loff_t index = *pos;
|
||||
|
||||
s->private = NULL;
|
||||
|
||||
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return NULL;
|
||||
@@ -5329,7 +5331,11 @@ static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos)
|
||||
|
||||
static void gpiolib_seq_stop(struct seq_file *s, void *v)
|
||||
{
|
||||
struct gpiolib_seq_priv *priv = s->private;
|
||||
struct gpiolib_seq_priv *priv;
|
||||
|
||||
priv = s->private;
|
||||
if (!priv)
|
||||
return;
|
||||
|
||||
srcu_read_unlock(&gpio_devices_srcu, priv->idx);
|
||||
kfree(priv);
|
||||
|
||||
Reference in New Issue
Block a user