mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Chad Aldreda <ca@modelmiser.com>
Cc: linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Johan Hovold <johan@kernel.org>,
	driver-core@lists.linux.dev, linux-media@vger.kernel.org,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	Nick Faro <yux50000@hotmail.com>
Subject: Re: [RFC PATCH 0/4] devres: warn about managed memory still held by open files at unbind
Date: Thu, 5 Nov 2026 00:41:25 +0200	[thread overview]
Message-ID: <20261104224125.GB3976471@killaraus.ideasonboard.com> (raw)
In-Reply-To: <20261104223146.4012287-1-ca@modelmiser.com>

On Wed, Nov 04, 2026 at 10:31:51PM +0000, Chad Aldreda wrote:
> > Are you really expecting anyone to read all that ?
> 
> Fair enough. The short version:

I think you forgot about the second part of my reply.

> A struct cdev, miscdevice or video_device embedded in devm_kzalloc()'d
> driver state outlives the unbind through any open file, and the next
> operation on that file, usually close(), is a use-after-free. It keeps
> getting fixed one driver at a time (44f3468a0aef, 7d6358ab0286), and
> cx231xx in 7.4-rc1 still has the shape.
> 
> CONFIG_DEBUG_DEVRES_REFS, off by default: in device_unbind_cleanup(),
> before devres_release_all(), walk every task's fd table once and WARN
> when a file's private_data, i_private or i_cdev, or an object a
> subsystem names (patch 3: V4L2's video_device), points into an
> allocation about to be freed. A debugfs file still live during the walk
> is judged after release, since drivers often remove those through a
> devres action. Cost: one walk per unbind or failed probe.
> 
> Patch 4 is a test driver: unbind with its nodes open gives two WARNs,
> and KASAN then reports the use-after-frees on close. vivid, as a
> control, is silent.
> 
> The open problem (question 5 in the cover): the walk holds a reference
> on each file it inspects, so a racing close can leave it the last
> holder. It runs on a kthread so that release goes to delayed_fput
> rather than task work queued behind the unbind, but the delayed-fput
> worker is serialized, so a release there that needs a lock unbind
> holds stalls the ones behind it.

-- 
Regards,

Laurent Pinchart

      reply	other threads:[~2026-11-04 22:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 21:55 Chad Aldreda
2026-11-04 21:55 ` [RFC PATCH 1/4] debugfs: add debugfs_file_revoked() for debugging aids Chad Aldreda
2026-11-04 22:00 ` [RFC PATCH 2/4] devres: add DEBUG_DEVRES_REFS to warn about managed memory still held by open files Chad Aldreda
2026-11-04 22:00 ` [RFC PATCH 3/4] media: v4l2-dev: name the video_device behind an open file for DEBUG_DEVRES_REFS Chad Aldreda
2026-11-04 22:00 ` [RFC PATCH 4/4] drivers: base: test: add a vehicle " Chad Aldreda
2026-11-04 22:07 ` [RFC PATCH 0/4] devres: warn about managed memory still held by open files at unbind Laurent Pinchart
2026-11-04 22:31   ` Chad Aldreda
2026-11-04 22:41     ` Laurent Pinchart [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=20261104224125.GB3976471@killaraus.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=ca@modelmiser.com \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=hverkuil+cisco@kernel.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rafael@kernel.org \
    --cc=yux50000@hotmail.com \
    /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®