mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Breno Leitao <leitao@debian.org>
Cc: Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	catalin.marinas@arm.com, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH] gpiolib: fix leaked descriptor labels in gpiodev_release()
Date: Fri, 13 Nov 2026 17:29:53 +0200	[thread overview]
Message-ID: <avcs8emo3oWpYGBG@ashevche-desk.local> (raw)
In-Reply-To: <20261113-gpio-label-leak-v1-1-c6c00f8ebfff@debian.org>

On Fri, Nov 13, 2026 at 06:38:28AM -0800, Breno Leitao wrote:
> We are seeing kmemleak report a leaked descriptor label on linux-next.
> 
>   unreferenced object 0xffff0005d420f280 (size 32):
>     comm "gpio-cdev-uaf", pid 21987, jiffies 4297166145
>     backtrace (crc 7ff222d9):

>       kmemleak_alloc+0x40/0xd0
>       __kmalloc_noprof+0x300/0x670

Unneeded in the report

>       desc_set_label+0x50/0x190
>       gpiod_request_commit+0x1e8/0x358
>       gpiod_request+0x88/0x290
>       gpio_ioctl+0x7e4/0x1b48

>       __arm64_sys_ioctl+0xc10/0x1360

Ditto.

As documented in Submitting Patches, leave only significant lines in
the backtrace.

> The test requests a line, removes the gpio-sim chip under it, and only
> then closes the request. By that time gpiochip_remove() has cleared
> gdev->chip, so gpiod_free_commit() skips desc_set_label(desc, NULL), and
> gpiodev_release() frees the descriptor array without the labels still
> attached to it.
> 
> Free those labels in gpiodev_release(). No reader can reach the
> descriptors once the device is released, so they can be freed directly
> rather than through call_srcu(). gdev->descs is NULL there when
> gpiochip_add_data_with_key() failed to allocate it.

Hmm... There are so many patches are flying in this area. Can you for the
starter elaborate which Linux Next tag you are using?

...

> +	unsigned int i;

It's okay do define it inside the for-loop.

...

> +	/* Lines released after the chip was removed still hold their label. */
> +	for (i = 0; gdev->descs && i < gdev->ngpio; i++)
> +		kfree(rcu_access_pointer(gdev->descs[i].label));

Sounds to me like something that Bart addressed very recently.

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-11-13 15:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 14:38 Breno Leitao
2026-11-13 15:29 ` Andy Shevchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avcs8emo3oWpYGBG@ashevche-desk.local \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=brgl@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=kernel-team@meta.com \
    --cc=leitao@debian.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®