Re: [PATCH v4 2/4] scsi: core: release legacy ioctl request before user copyback

From: Bart Van Assche

Date: Thu Nov 19 2026 - 16:36:57 EST


On 11/18/26 12:33 AM, Yingjie Wang wrote:
> + blk_mq_free_request(rq);
>
> - if (!copy_to_user(hdr->sbp, scmd->sense_buffer, len))
> - hdr->sb_len_wr = len;
> + if (sense_len) {
> + if (!copy_to_user(hdr->sbp, sense_buffer, sense_len))
> + hdr->sb_len_wr = sense_len;
> else
> ret = -EFAULT;
> }

[ ... ]

> - ret = scsi_complete_sghdr_rq(rq, hdr, bio);
> + return scsi_complete_sghdr_rq(rq, hdr, bio);
>
> out_put_request:
> blk_mq_free_request(rq);

With this patch applied scsi_complete_sghdr_rq() frees the request that
has been allocated by its caller. Nothing in the name of that function
nor in the code of sg_io() makes that clear. Please either add a comment
above scsi_complete_sghdr_rq() that explains that it frees @rq or keep
the blk_mq_free_request() call in sg_io(), e.g. by splitting
scsi_complete_sghdr_rq() into a function that saves the request state
and a function that copies that state to user space.

Thanks,

Bart.