All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stefan Haberland" <sth@linux.ibm.com>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
	linux-s390@vger.kernel.org,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v7 03/19] s390/dasd: Guard sysfs discipline callbacks against unallocated private data
Date: Sat, 01 Aug 2026 18:29:51 +0000	[thread overview]
Message-ID: <20260801182952.2EAE51F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260801180033.3679412-4-sth@linux.ibm.com>

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

New issues:
- [Medium] Lockless reads of `device->private` lack `READ_ONCE()`, leaving them vulnerable to compiler reloading and TOCTOU races.
- [Low] A race condition between reading `private->lcu` and `private->features` allows unsupported I/O on HYPER PAV alias devices.

Pre-existing issues:
- [High] The patch misses a NULL pointer dereference in `dasd_eckd_pprc_enabled()` reachable via the `copy_pair` sysfs attribute.
- [High] Asynchronous path event handlers unconditionally dereference `device->private` and are not canceled on initialization failure.
- [High] Lockless access to `device->private` in sysfs handlers allows a use-after-free if device initialization fails.
--

--- Patch [3]: [PATCH v7 03/19] s390/dasd: Guard sysfs discipline callbacks against unallocated private data ---
commit ef202481581d23c8dd03c5042f532b8675ad8998
Author: Stefan Haberland <sth@linux.ibm.com>

s390/dasd: Guard sysfs discipline callbacks against unallocated private data

This commit guards several sysfs show/store handlers against unallocated
device->private pointers during device initialization.

Fixes: c729696bcf8b ("s390/dasd: Recognise data for ESE volumes")
Cc: stable@vger.kernel.org

> diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
> index 74fe73b5738ab..6e2fd445688cb 100644
> --- a/drivers/s390/block/dasd_eckd.c
> +++ b/drivers/s390/block/dasd_eckd.c

[Severity: High]
This is a pre-existing issue, but does this patch miss guarding
dasd_eckd_pprc_enabled()?

When a device is set online, device->discipline is assigned before
check_device() allocates device->private. If the copy_pair sysfs attribute
is written during this window, dasd_copy_pair_store() locklessly invokes
device->discipline->pprc_enabled(device):

    if (device->discipline->pprc_enabled) {
        pprc_enabled = device->discipline->pprc_enabled(device);

The callback unconditionally dereferences
private->rdc_data.facilities.PPRC_enabled, which seems like it could still
cause a NULL pointer dereference.

[Severity: High]
This is also a pre-existing issue, but are asynchronous path event handlers
safe from this same NULL pointer dereference?

If a path event occurs while device->private is unallocated, the CIO layer
triggers dasd_eckd_pe_handler() which schedules do_pe_handler_work().
Functions like dasd_eckd_read_fc_security() then unconditionally dereference
private:

    rc = chsc_scud(private->uid.ssid, (u64 *)esm, &esm_valid);

Additionally, if dasd_eckd_check_characteristics() encounters an error, its
out_err1 path frees device->private but does not appear to cancel the pending
pe_handler_worker workqueue, which could lead to a panic later.

[Severity: High]
This is another pre-existing issue, but is the lockless access to
device->private safe from use-after-free if device initialization fails?

While the new guards prevent NULL pointer dereferences, device->private is
accessed locklessly in these handlers. If dasd_eckd_check_characteristics()
encounters an error, it calls kfree(device->private). If a concurrent sysfs
reader has just passed the if (!private) check, could it proceed to
dereference the freed memory?

[ ... ]

> @@ -1831,7 +1848,11 @@ static int dasd_eckd_read_ext_pool_info(struct dasd_device *device)
>  static int dasd_eckd_ext_size(struct dasd_device *device)
>  {
>  	struct dasd_eckd_private *private = device->private;
> -	struct dasd_ext_pool_sum eps = private->eps;
> +	struct dasd_ext_pool_sum eps;
> +
> +	if (!private)
> +		return 0;
> +	eps = private->eps;

[Severity: Medium]
Should we use READ_ONCE() when assigning private from device->private?

Because device->private is accessed locklessly and can be set to NULL
concurrently by the error path, could the compiler optimize this by
reloading the pointer from device->private after the NULL check? This might
allow a TOCTOU NULL pointer dereference if it gets set to NULL between the
check and the reload.

>  
>  	if (!eps.flags.extent_size_valid)
>  		return 0;

[ ... ]

> @@ -5935,8 +5965,11 @@ static int dasd_eckd_query_host_access(struct dasd_device *device,
>  	struct ccw1 *ccw;
>  	int rc;
>  
> +	if (!private)
> +		return -ENODEV;
> +
>  	/* not available for HYPER PAV alias devices */
> -	if (!device->block && private->lcu->pav == HYPER_PAV)
> +	if (!device->block && private->lcu && private->lcu->pav == HYPER_PAV)

[Severity: Low]
Could checking private->lcu here introduce a race with the subsequent
private->features check?

A sysfs reader thread could read private->lcu as NULL before it is populated
and bypass this abort. If preempted, check_device() could finish populating
both lcu and features. When the reader resumes, it could evaluate the newly
initialized features and proceed to issue the PSF command. Would this allow
an unsupported command on HYPER PAV aliases?

>  		return -EOPNOTSUPP;
>  
>  	/* may not be supported by the storage server */

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260801180033.3679412-1-sth@linux.ibm.com?part=3

  reply	other threads:[~2026-08-01 18:29 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-01 18:00 [PATCH v7 00/19] s390/dasd: ESE thin-provisioning performance improvements Stefan Haberland
2026-08-01 18:00 ` [PATCH v7 01/19] s390/dasd: Do not complete a failed ESE read as successful Stefan Haberland
2026-08-01 18:30   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 02/19] s390/dasd: Propagate partial completion length across ERP recovery Stefan Haberland
2026-08-01 18:21   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 03/19] s390/dasd: Guard sysfs discipline callbacks against unallocated private data Stefan Haberland
2026-08-01 18:29   ` sashiko-bot [this message]
2026-08-01 18:00 ` [PATCH v7 04/19] s390/dasd: Snapshot intrc before freeing the request block Stefan Haberland
2026-08-01 18:18   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 05/19] s390/dasd: Optimize max blocks per request for track alignment Stefan Haberland
2026-08-01 18:05   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 06/19] s390/dasd: Use GFP_KERNEL in dasd_alloc_device() Stefan Haberland
2026-08-01 18:15   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 07/19] s390/dasd: Add defines for the Extended Address Volume track address Stefan Haberland
2026-08-01 18:05   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 08/19] s390/dasd: Add infrastructure for ESE full-track write Stefan Haberland
2026-08-01 18:21   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 09/19] s390/dasd: Add range-based format-track collision detection Stefan Haberland
2026-08-01 18:23   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 10/19] s390/dasd: Extend prepare_itcw() to support WRITE_FULL_TRACK Stefan Haberland
2026-08-01 18:28   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 11/19] s390/dasd: Add dasd_eckd_build_cp_tpm_writefulltrack() Stefan Haberland
2026-08-01 18:17   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 12/19] s390/dasd: Use WRITE_FULL_TRACK in ESE format handler Stefan Haberland
2026-08-01 18:33   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 13/19] s390/dasd: Add full_track_bias to control fulltrack write mode Stefan Haberland
2026-08-01 18:20   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 14/19] s390/dasd: Derive adaptive ESE fulltrack heuristic from ft_bias Stefan Haberland
2026-08-01 18:17   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 15/19] s390/dasd: Stamp a format label into newly formatted volumes Stefan Haberland
2026-08-01 18:26   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 16/19] s390/dasd: Detect ESE volumes from the on-disk format label Stefan Haberland
2026-08-01 18:39   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 17/19] s390/dasd: Report ESE capability and format mode at device online Stefan Haberland
2026-08-01 18:22   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 18/19] s390/dasd: Re-enable discard support for ESE volumes Stefan Haberland
2026-08-01 18:46   ` sashiko-bot
2026-08-01 18:00 ` [PATCH v7 19/19] s390/dasd: Read cached unit address and LSS in the CCW build path Stefan Haberland
2026-08-01 18:50   ` 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=20260801182952.2EAE51F00AC4@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sth@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.