linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Levin" <sashal@kernel.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH AUTOSEL 6.18-5.10] scsi: pm8001: Reject firmware update in fatal error state
Date: Mon, 31 Aug 2026 17:05:07 +0000	[thread overview]
Message-ID: <20260831170507.AEF391F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831133314.4125787-555-sashal@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] TOCTOU race in fw_status check allows concurrent firmware updates, leading to a double free and Use-After-Free (UAF) of pm8001_ha->fw_image.
--

commit 0afa89048afde066ccd69e2cb178118dd117d047
Author: Kumar Meiyappan <kumar.meiyappan@microchip.com>

scsi: pm8001: Reject firmware update in fatal error state

pm8001_store_update_fw() allows a firmware update request even when the
controller has already entered a fatal error state. This commit rejects the
request early by checking controller_fatal_error to avoid a call trace.

Link: https://patch.msgid.link/20260416153757.414896-1-sagar.biradar@microchip.com

> diff --git a/drivers/scsi/pm8001/pm8001_ctl.c b/drivers/scsi/pm8001/pm8001_ctl.c
> index cbfda8c04e956..bb38b2d63acb8 100644
> --- a/drivers/scsi/pm8001/pm8001_ctl.c
> +++ b/drivers/scsi/pm8001/pm8001_ctl.c
> @@ -826,6 +826,14 @@ static ssize_t pm8001_store_update_fw(struct device *cdev,
>  		goto out;
>  	}
>  
> +	if (pm8001_ha->controller_fatal_error) {
> +		pm8001_dbg(pm8001_ha, FAIL,
> +			   "controller in fatal error state, firmware update rejected\n");
> +		pm8001_ha->fw_status = FAIL_PARAMETERS;
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +

[Severity: High]
This isn't a bug introduced by this patch, but could this sysfs write handler
be subject to a TOCTOU race condition if multiple threads with CAP_SYS_ADMIN
privileges write to the update_fw sysfs attribute concurrently?

Because kernfs does not serialize concurrent writes to the same sysfs file,
the check earlier in pm8001_store_update_fw():

	if (pm8001_ha->fw_status == FLASH_IN_PROGRESS)
		return -EINPROGRESS;
	pm8001_ha->fw_status = FLASH_IN_PROGRESS;

lacks lock protection. If two threads pass this check simultaneously, they will
both proceed and later call request_firmware() on the same pointer:

	ret = request_firmware(&pm8001_ha->fw_image,
			       filename_ptr,
			       pm8001_ha->dev);

This would leak the first firmware allocation. Furthermore, both threads will
eventually call:

	release_firmware(pm8001_ha->fw_image);

Does this sequence result in a double free of pm8001_ha->fw_image?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260831133314.4125787-555-sashal@kernel.org?part=1

      reply	other threads:[~2026-08-31 17:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260831133314.4125787-1-sashal@kernel.org>
2026-08-31 13:20 ` [PATCH AUTOSEL 6.18-6.1] scsi: core: Do not block on tag allocation in scsi_eh_lock_door() Sasha Levin
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18-5.10] scsi: bfa: Reduce kernel stack usage in bfa_fcs_lport_fdmi_build_portattr_block() Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-5.10] scsi: pm8001: Reject non-fatal dump when controller is crashed Sasha Levin
2026-08-31 16:47   ` sashiko-bot
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18-5.10] scsi: pm8001: Reject firmware update in fatal error state Sasha Levin
2026-08-31 17:05   ` sashiko-bot [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=20260831170507.AEF391F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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;
as well as URLs for NNTP newsgroup(s).