Message ID | 20250220142039.250992-1-arthur.simchaev@sandisk.com (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | [v3] ufs: core: bsg: Fix memory crash in case arpmb command failed | expand |
On 2/20/25 6:20 AM, Arthur Simchaev wrote: > In case the device doesn't support arpmb, the kernel get memory crash > due to copy user data in bsg_transport_sg_io_fn level. So in case > ufs_bsg_exec_advanced_rpmb_req returned error, do not set the job's > reply_len. Reviewed-by: Bart Van Assche <bvanassche@acm.org>
On Thu, 20 Feb 2025 16:20:39 +0200, Arthur Simchaev wrote: > In case the device doesn't support arpmb, the kernel get memory crash > due to copy user data in bsg_transport_sg_io_fn level. So in case > ufs_bsg_exec_advanced_rpmb_req returned error, do not set the job's > reply_len. > > Memory crash backtrace: > 3,1290,531166405,-;ufshcd 0000:00:12.5: ARPMB OP failed: error code -22 > > [...] Applied to 6.14/scsi-fixes, thanks! [1/1] ufs: core: bsg: Fix memory crash in case arpmb command failed https://git.kernel.org/mkp/scsi/c/f27a95845b01
diff --git a/drivers/ufs/core/ufs_bsg.c b/drivers/ufs/core/ufs_bsg.c index 8d4ad0a3f2cf..252186124669 100644 --- a/drivers/ufs/core/ufs_bsg.c +++ b/drivers/ufs/core/ufs_bsg.c @@ -194,10 +194,12 @@ static int ufs_bsg_request(struct bsg_job *job) ufshcd_rpm_put_sync(hba); kfree(buff); bsg_reply->result = ret; - job->reply_len = !rpmb ? sizeof(struct ufs_bsg_reply) : sizeof(struct ufs_rpmb_reply); /* complete the job here only if no error */ - if (ret == 0) + if (ret == 0) { + job->reply_len = rpmb ? sizeof(struct ufs_rpmb_reply) : + sizeof(struct ufs_bsg_reply); bsg_job_done(job, ret, bsg_reply->reply_payload_rcv_len); + } return ret; }