s390/dasd: Fix BIODASDCHECKFMT issues and RCD retry handling
Subsystems (2)
Stefan Haberland
maintainercover s390/dasd: Fix BIODASDCHECKFMT issues and RCD retry handling
The BIODASDCHECKFMT ioctl gained several fixes as a result of issues reported by Sashiko. Two patches address bugs introduced with the original ioctl implementation: one prevents userspace from influencing internal evaluation state through output-only fields, avoiding a kernel heap information leak, and another fixes an error path that could crash the kernel and leak request references.
The third patch fixes a longstanding z/VM-specific issue in RCD processing. The Read Configuration Data request requires a special buffer initialization before every start, but several restart paths bypassed the existing reinitialization logic. As a result, successful retries could return incomplete configuration data and lead to false "Not all channel paths lead to the same device" reports for otherwise identical minidisks.
Stefan Haberland (3):
s390/dasd: Re-initialize RCD buffer with "V1.0" before every start s390/dasd: Fix wrong free and refcount leak in build_check_tcw error
path
s390/dasd: Don't trust userspace-supplied result field in format check
drivers/s390/block/dasd.c | 1 + drivers/s390/block/dasd_eckd.c | 55 ++++++++++++--------------------- drivers/s390/block/dasd_int.h | 15 +++++++++ drivers/s390/block/dasd_ioctl.c | 4 ++- 4 files changed, 39 insertions(+), 36 deletions(-)
Signature · 1 line
2.53.0
Stefan Haberland
maintainerPATCH 1/3 s390/dasd: Re-initialize RCD buffer with "V1.0" before every start
Under z/VM the Read Configuration Data (RCD) buffer has to start with EBCDIC "V1.0" to request the virtual device SNEQ that carries the minidisk UIT. The request and the response share the same buffer:
CP evaluates the magic on the way out and the RCD data is written into the same buffer on the way back.
The magic is only written when the request is built and again in read_conf_cb() when the original request fails.
Several restart paths do not run that callback:
- ERP use the same buffer and if the same error occurs again, the ERP restarts the existing ERP request;
if a different error occurs, it adds another ERP request. Neither re-initializes the magic.
- Terminated (timed out) ERP requests, killed requests and requests requeued after the last path was gone are restarted without it.
- dasd_sleep_on_immediately() overwrites cqr->callback, so read_conf_cb() never ran for dasd_eckd_read_conf_immediately(), and its fastpath retries in dasd_int_handler() do not call a callback either.
If such a restart succeeds, z/VM omits the virtual device SNEQ, the UID of that path is built without the UIT and the paths are reported as "Not all channel paths lead to the same device" although they lead to the same minidisk.
Every start of a request, whatever path led to it, goes through dasd_start_IO(). Add an optional prepare_io function to the request that dasd_start_IO() calls before every start of the request and of its ERP requests, and use it to write the magic for RCD requests.
The ERP handling stays unchanged. read_conf_cb() is no longer needed and is removed, which also gets rid of its memset() that only cleared a single byte.
--- drivers/s390/block/dasd.c | 1 + drivers/s390/block/dasd_eckd.c | 52 ++++++++++++---------------------- drivers/s390/block/dasd_int.h | 15 ++++++++++ 3 files changed, 34 insertions(+), 34 deletions(-)
drivers/s390/block/dasd.c +1 -0
@@ -1396,6 +1396,7 @@ int dasd_start_IO(struct dasd_ccw_req *cqr) cqr->status =DASD_CQR_ERROR ;return -EIO ; } +dasd_start_IO_prepare (cqr); cqr->startclk =get_tod_clock (); cqr->starttime = jiffies; cqr->retries--;
drivers/s390/block/dasd_eckd.c +18 -34
85 lines not on this page · raw message
drivers/s390/block/dasd_int.h +15 -0
@@ -147,6 +147,8 @@ struct dasd_ccw_req {void *data;/* pointer to data area */ struct irb irb;/* device status in case of an error */ struct dasd_ccw_req *refers;/* ERP-chain queueing. */ +/* optional prepare function called before every start_io, must not sleep */ +void (*prepare_io)(struct dasd_ccw_req *cqr);void *function;/* originating ERP action */ void *mem_chunk;
@@ -891,6 +893,19 @@ static inline void *dasd_get_callback_data(struct dasd_ccw_req *cqr)return cqr->callback_data; } +/* +* Walk down the ERP chain to the original CQR and call its +* prepare_io function if set. +*/ +static inline void dasd_start_IO_prepare (struct dasd_ccw_req *cqr) +{ +/* ERP requests use the prepare function of the original request */ +while (cqr->refers) + cqr = cqr->refers; +if (cqr->prepare_io) + cqr->prepare_io (cqr); +} +static inline bool dasd_req_conflict (struct dasd_ccw_req *cqr1,struct dasd_ccw_req *cqr2) {
Signature · 1 line
2.53.0
Stefan Haberland
maintainerPATCH 2/3 s390/dasd: Fix wrong free and refcount leak in build_check_tcw error path
In reply to Stefan Haberlanddasd_eckd_build_check_tcw() allocates its request with dasd_fmalloc_request(), but its out_err path frees it with dasd_sfree_request(). The latter uses a different pool and therefor, leading to invalid pointer arithmetic and a crash.
Use the matching dasd_ffree_request() instead.
The same error path also leaves start_priv->count incremented without ever decrementing it again.
This leaks a permanent reference on every build failure. Decrement it before freeing the request.
--- drivers/s390/block/dasd_eckd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/s390/block/dasd_eckd.c +2 -1
@@ -2764,7 +2764,8 @@ dasd_eckd_build_check_tcw(struct dasd_device *base, struct format_data_t *fdata,return cqr; out_err: -dasd_sfree_request (cqr, startdev); + start_priv->count--; +dasd_ffree_request (cqr, startdev);return ERR_PTR (rc); }
Signature · 1 line
2.53.0
Stefan Haberland
maintainerPATCH 3/3 s390/dasd: Don't trust userspace-supplied result field in format check
In reply to Stefan HaberlandBIODASDCHECKFMT used to copy the entire format_check_t struct from userspace, including the result/unit/rec/num_records/blksize/ key_length fields that are output fields only. dasd_eckd_format_evaluate_tracks() relies on cdata->result being zero to decide whether to apply an index correction (i--/pos--) after a successful check. A caller that pre-sets result to a non-zero value can suppress that correction, leaving pos advanced past the last valid entry; the (partially out-of-bounds) fmt_buffer[pos] fields are then copied back to userspace, leaking heap contents.
Only expect is an Input field; copy just that member in and zero the rest of cdata.
--- drivers/s390/block/dasd_ioctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/s390/block/dasd_ioctl.c +3 -1
@@ -303,7 +303,9 @@ static int dasd_ioctl_check_format(struct block_device *bdev, void __user *argp) goto out_err; } -if (copy_from_user (&cdata, argp,sizeof (cdata))) { +/* copy only input fields, clear the rest */ +memset (&cdata,0 ,sizeof (cdata)); +if (copy_from_user (&cdata.expect, argp,sizeof (cdata.expect))) { rc = -EFAULT ; goto out_err; }
Signature · 1 line
2.53.0