From: Dan Carpenter <error27@gmail.com>
To: Alexandru Hossu <hossu.alexandru@gmail.com>
Cc: linux-tegra@vger.kernel.org, marvin24@gmx.de,
gregkh@linuxfoundation.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/5] staging: nvec: fix use-after-free in nvec_rx_completed()
Date: Mon, 13 Apr 2026 11:08:47 +0300 [thread overview]
Message-ID: <adykjx57doahzkWH@stanley.mountain> (raw)
In-Reply-To: <20260412205117.387125-1-hossu.alexandru@gmail.com>
On Sun, Apr 12, 2026 at 10:51:16PM +0200, Alexandru Hossu wrote:
> In nvec_rx_completed(), when an incomplete RX transfer is detected,
> nvec_msg_free() is called to return the message back to the pool by
> clearing its 'used' atomic flag. Immediately after this, the code
> accesses nvec->rx->data[0] to check the message type.
>
> Since nvec_msg_free() marks the pool slot as available via atomic_set(),
> any concurrent or subsequent call to nvec_msg_alloc() could claim that
> same slot and overwrite its data[] array. Reading nvec->rx->data[0] after
> freeing the message is therefore a use-after-free.
>
> Fix this by saving the message type byte before calling nvec_msg_free(),
> then using the saved value for the battery quirk check.
>
> Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>
Add a Fixes tag.
> ---
> drivers/staging/nvec/nvec.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
> index 952c5a849a56..75877038847f 100644
> --- a/drivers/staging/nvec/nvec.c
> +++ b/drivers/staging/nvec/nvec.c
> @@ -498,11 +498,14 @@ static void nvec_rx_completed(struct nvec_chip *nvec)
> (uint)nvec_msg_size(nvec->rx),
> (uint)nvec->rx->pos);
>
> + /* Save before freeing to avoid use-after-free */
Delete this comment. (Obvious).
> + unsigned char msg_type = nvec->rx->data[0];
Move this declaration to the start of the block.
Otherwise, it looks good.
regards,
dan carpenter
> +
> nvec_msg_free(nvec, nvec->rx);
> nvec->state = 0;
>
> /* Battery quirk - Often incomplete, and likes to crash */
> - if (nvec->rx->data[0] == NVEC_BAT)
> + if (msg_type == NVEC_BAT)
> complete(&nvec->ec_transfer);
>
> return;
next prev parent reply other threads:[~2026-04-13 8:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-12 20:51 [PATCH 3/5] staging: nvec: fix use-after-free in nvec_rx_completed() Alexandru Hossu
2026-04-12 20:51 ` [PATCH 4/5] staging: nvec: fix pm_power_off teardown in tegra_nvec_remove() Alexandru Hossu
2026-04-13 8:21 ` Dan Carpenter
2026-04-13 8:08 ` Dan Carpenter [this message]
[not found] <20260412205057.386856-3-hossu.alexandru@gmail.com>
2026-04-13 10:02 ` [PATCH 3/5] staging: nvec: fix use-after-free in nvec_rx_completed() Alexandru Hossu
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=adykjx57doahzkWH@stanley.mountain \
--to=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hossu.alexandru@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux-tegra@vger.kernel.org \
--cc=marvin24@gmx.de \
/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