Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Damien Le Moal" <dlemoal@kernel.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 2/7] block: introduce storage element management
Date: Wed, 07 Oct 2026 08:34:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-162749@kernel.org> (raw)
In-Reply-To: <20261007082344.1049179-3-dlemoal@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] block: NULL pointer dereference if optional se_ops methods are not implemented
- [Medium] block: disk_wait_for_se_mgmt_completion() ignores hardware errors and falsely reports success
- [Medium] block: disk_wait_for_se_mgmt_completion() overwrites successful completion with -EINTR
--

commit d3d300e29a3d6ef944841ecbfddc83f5a8fabe94
Author: Damien Le Moal <dlemoal@kernel.org>

block: introduce storage element management

Recent SCSI (SBC) and ATA (ACS) standards define the storage element
depopulation feature. This feature is intended for managing hard-disks
heads, either combined read-write heads or pairs of read and write heads.

> diff --git a/block/blk-zoned.c b/block/blk-zoned.c
> index 131c9f50b3da5..6a4c6a3f2060b 100644
> --- a/block/blk-zoned.c
> +++ b/block/blk-zoned.c

[ ... ]

> +static int disk_wait_for_se_mgmt_completion(struct gendisk *disk)
> +{
> +	struct blk_storage_element *elements, *e;
> +	unsigned int i, nr_se, nr_elements = 0;
> +	unsigned int noio_flag;
> +	int ret;
> +
> +	/* The callers already checked that disk->fops->se_ops is set. */
> +	ret = disk->fops->se_ops->report_elements(disk, NULL, &nr_elements);

[Severity: High]
Does this cause a NULL pointer dereference if the device driver provides
se_ops but leaves the optional report_elements method as NULL?

[ ... ]

> +		e = elements;
> +		for (i = 0; i < nr_se; i++, e++) {
> +			if (e->status == BLK_SE_STS_REMOVE_IN_PROGRESS ||
> +			    e->status == BLK_SE_STS_RESTORE_IN_PROGRESS)
> +				break;
> +		}
> +		if (i >= nr_se)
> +			break;

[Severity: Medium]
Will this loop falsely report success if a hardware operation fails?

If the hardware encounters an error and updates the element's status to
BLK_SE_STS_REMOVE_ERROR or BLK_SE_STS_RESTORE_ERROR, the status is no
longer IN_PROGRESS. As a result, the loop terminates successfully
(i >= nr_se) and the function returns 0. Will the caller then assume the
element was successfully depopulated or restored, masking the hardware
failure?

> +
> +		/* Not done yet: wait and retry. */
> +		msleep(1000);
> +	}
> +
> +	if (!ret && fatal_signal_pending(current))
> +		ret = -EINTR;

[Severity: Medium]
Does this logic mistakenly overwrite a successful completion with an
error if a signal arrives concurrently?

If the polling loop detects the operation finished successfully and breaks
out, but a fatal signal is delivered at the exact same time, this will set
ret = -EINTR.

Since the callers bdev_remove_storage_element() and
bdev_restore_storage_elements() abort on an error return, won't this
cause them to skip the mandatory blk_revalidate_disk_zones() step, leaving
the kernel's zone state permanently out-of-sync with the physical hardware
geometry?

[ ... ]

> +int bdev_report_storage_elements(struct block_device *bdev,
> +				 struct blk_storage_element *elements,
> +				 unsigned int *nr_elements)
> +{
> +	struct gendisk *disk = bdev->bd_disk;
> +
> +	if (!bdev_is_zoned(bdev) || !disk->fops->se_ops)
> +		return -EOPNOTSUPP;
> +
> +	if (!nr_elements)
> +		return -EINVAL;
> +
> +	if (*nr_elements && !elements)
> +		return -EINVAL;
> +
> +	return disk->fops->se_ops->report_elements(disk, elements, nr_elements);

[Severity: High]
Can this code cause a NULL pointer dereference if report_elements is not
implemented by the driver?

> +}
> +EXPORT_SYMBOL_GPL(bdev_report_storage_elements);

[ ... ]

> +int bdev_remove_storage_element(struct block_device *bdev,
> +				unsigned int element_id)
> +{
> +	struct gendisk *disk = bdev->bd_disk;
> +	unsigned int memflags;
> +	int ret;
> +
> +	if (!bdev_is_zoned(bdev) || !disk->fops->se_ops)
> +		return -EOPNOTSUPP;
> +
> +	/* Zero is not a valid storage element ID. */
> +	if (!element_id)
> +		return -EINVAL;
> +
> +	/*
> +	 * Freeze and unfreeze the queue to flush any outstanding command.
> +	 * The caller is responsible for not queuing up more I/Os by higher
> +	 * level means.
> +	 */
> +	memflags = blk_mq_freeze_queue(disk->queue);
> +	blk_mq_unfreeze_queue(disk->queue, memflags);
> +
> +	ret = disk->fops->se_ops->remove_element(disk, element_id);

[Severity: High]
Can this trigger a NULL pointer dereference if the driver provides se_ops
but omits the remove_element method?

[ ... ]

> +int bdev_restore_storage_elements(struct block_device *bdev)
> +{
> +	struct gendisk *disk = bdev->bd_disk;
> +	unsigned int memflags;
> +	int ret;
> +
> +	if (!bdev_is_zoned(bdev) || !disk->fops->se_ops)
> +		return -EOPNOTSUPP;
> +
> +	/*
> +	 * Freeze and unfreeze the queue to flush any outstanding commands.
> +	 * The caller is responsible for not queuing up more I/O by higher
> +	 * level means.
> +	 */
> +	memflags = blk_mq_freeze_queue(disk->queue);
> +	blk_mq_unfreeze_queue(disk->queue, memflags);
> +
> +	ret = disk->fops->se_ops->restore_elements(disk);

[Severity: High]
Does this code trigger a NULL pointer dereference if the driver provides
se_ops but leaves restore_elements as NULL?

The commit message notes that "Repopulating defective storage elements
is generally not allowed by devices", suggesting drivers will commonly
omit restore_elements.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261007082344.1049179-1-dlemoal@kernel.org?part=2

  reply	other threads:[~2026-10-07  8:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07  8:23 [PATCH v3 0/7] Add support for storage element depopulation Damien Le Moal
2026-10-07  8:23 ` [PATCH v3 1/7] block: fail reads to offline zones early Damien Le Moal
2026-10-07  8:41   ` sashiko-bot
2026-10-07 13:29   ` Christoph Hellwig
2026-10-07 14:31     ` Damien Le Moal
2026-10-07  8:23 ` [PATCH v3 2/7] block: introduce storage element management Damien Le Moal
2026-10-07  8:34   ` sashiko-bot [this message]
2026-10-07 13:35   ` Christoph Hellwig
2026-10-07 14:35     ` Damien Le Moal
2026-10-07  8:23 ` [PATCH v3 3/7] block: add storage element management ioctls Damien Le Moal
2026-10-07  8:39   ` sashiko-bot
2026-10-07 13:39   ` Christoph Hellwig
2026-10-07 14:37     ` Damien Le Moal
2026-10-07 15:28       ` Christoph Hellwig
2026-10-07  8:23 ` [PATCH v3 4/7] zloop: add storage element emulation Damien Le Moal
2026-10-07  8:35   ` sashiko-bot
2026-10-07 13:40   ` Christoph Hellwig
2026-10-07  8:23 ` [PATCH v3 5/7] zloop: add degrade_element control command Damien Le Moal
2026-10-07  8:39   ` sashiko-bot
2026-10-07  8:23 ` [PATCH v3 6/7] scsi: sd_zbc: always revalidate zones for disks supporting head depopulation Damien Le Moal
2026-10-07  8:35   ` sashiko-bot
2026-10-07  8:23 ` [PATCH v3 7/7] scsi: sd_zbc: define storage element management operations Damien Le Moal
2026-10-07  8:40   ` sashiko-bot

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=sashiko-outbox-162749@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-scsi@vger.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