Message ID | 20240709105511.64266-1-flyingpeng@tencent.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | scsi/mpt3sas: fix a KASAN report | expand |
On 7/9/24 3:55 AM, flyingpenghao@gmail.com wrote:
> Although it appears to be a KASAN report, it is actually a concurrency issue.
Please explain the concurrency issue. Please also explain why the
introduction of WRITE_ONCE() / READ_ONCE() solves the concurrency issue
rather than papering over it. Note: I expect the latter rather than the
former.
Thanks,
Bart.
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 1320e06727df..c738bdd79f94 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -8577,7 +8577,8 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc) /* ctl module internal command bits */ ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); - ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); + void *sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); + WRITE_ONCE(ioc->ctl_cmds.sense, sense); ioc->ctl_cmds.status = MPT3_CMD_NOT_USED; mutex_init(&ioc->ctl_cmds.mutex); diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c index 1c9fd26195b8..dec19670cdff 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c @@ -1096,7 +1096,7 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg, MPI2_FUNCTION_NVME_ENCAPSULATED) ? NVME_ERROR_RESPONSE_SIZE : SCSI_SENSE_BUFFERSIZE; sz = min_t(u32, karg.max_sense_bytes, sz_arg); - if (copy_to_user(karg.sense_data_ptr, ioc->ctl_cmds.sense, + if (copy_to_user(karg.sense_data_ptr, READ_ONCE(ioc->ctl_cmds.sense), sz)) { pr_err("failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__);