From: Dan Carpenter <error27@gmail.com>
To: Alexandru Hossu <hossu.alexandru@gmail.com>
Cc: linux-media@vger.kernel.org, sakari.ailus@linux.intel.com,
bingbu.cao@intel.com, mchehab@kernel.org,
gregkh@linuxfoundation.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] staging: media: ipu7: fix double-free and use-after-free in error paths
Date: Mon, 13 Apr 2026 13:27:50 +0300 [thread overview]
Message-ID: <adzFJnr6Ru9RjqoP@stanley.mountain> (raw)
In-Reply-To: <20260413101533.496090-1-hossu.alexandru@gmail.com>
On Mon, Apr 13, 2026 at 12:15:33PM +0200, Alexandru Hossu wrote:
> In both ipu7_isys_init() and ipu7_psys_init(), pdata is allocated and
> then passed to ipu7_bus_initialize_device(), which stores it in
> adev->pdata. The ipu7_bus_release() function frees adev->pdata when the
> device's reference count drops to zero.
>
> Two error paths incorrectly call kfree(pdata) after the device teardown
> has already freed it:
>
> 1. When ipu7_mmu_init() fails: put_device() is called, which drops the
> reference count to zero and triggers ipu7_bus_release() ->
> kfree(pdata). The subsequent kfree(pdata) is a double-free.
>
> 2. When ipu7_bus_add_device() fails: it calls auxiliary_device_uninit()
> internally, which calls put_device() -> ipu7_bus_release() ->
> kfree(pdata). The subsequent kfree(pdata) is again a double-free.
>
> Note that the kfree(pdata) when ipu7_bus_initialize_device() itself
> fails is correct, because in that case auxiliary_device_init() failed
> and the release function was never set up, so pdata must be freed
> manually.
>
> Additionally, the error code was not saved before calling put_device(),
> causing ERR_CAST() to dereference the already-freed adev pointer when
> constructing the return value. Fix this by saving the error from
> dev_err_probe() before put_device() and returning ERR_PTR() instead.
>
> Remove the redundant kfree(pdata) calls and fix the use-after-free in
> the return values of the two affected error paths.
>
> Fixes: b7fe4c0019b1 ("media: staging/ipu7: add Intel IPU7 PCI device driver")
> Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>
> ---
Both the resent patches are fine now.
Reviewed-by: Dan Carpenter <error27@gmail.com>
However, please could you resend the whole patch series as a new thread
(with the first two or whatever dropped)?
regards,
dan carpenter
prev parent reply other threads:[~2026-04-13 10:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260412205057.386856-5-hossu.alexandru@gmail.com>
2026-04-13 10:02 ` [PATCH 5/5] staging: media: ipu7: fix double-free of pdata in error paths Alexandru Hossu
2026-04-13 10:15 ` [PATCH v2] staging: media: ipu7: fix double-free and use-after-free " Alexandru Hossu
2026-04-13 10:27 ` Dan Carpenter [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=adzFJnr6Ru9RjqoP@stanley.mountain \
--to=error27@gmail.com \
--cc=bingbu.cao@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hossu.alexandru@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.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