mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main()
Subsystems (2)
PATCH 1/1 mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main()
In _ctl_ioctl_main(), 'ioctl_header' is fetched the first time from userspace. 'ioctl_header.ioc_number' is then checked. The legal result is saved to 'ioc'. Then, in condition MPT3COMMAND, the whole struct is fetched again from the userspace. Then _ctl_do_mpt_command() is called, 'ioc' and 'karg' as inputs.
However, a malicious user can change the 'ioc_number' between the two fetches, which will cause a potential security issues. Moreover, a malicious user can provide a valid 'ioc_number' to pass the check in first fetch, and then modify it in the second fetch.
To fix this, we need to recheck the 'ioc_number' in the second fetch.
---
drivers/scsi/mpt3sas/mpt3sas_ctl.c +4 -0
@@ -2319,6 +2319,10 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,break ; } +if (karg.hdr.ioc_number != ioctl_header.ioc_number) { + ret = -EINVAL ; +break ; + }if (_IOC_SIZE (cmd) ==sizeof (struct mpt3_ioctl_command )) { uarg = arg; ret =_ctl_do_mpt_command (ioc, karg, &uarg->mf);
Suganath Prabu Subramani
maintainerPlease consider this patch as Ack-by: Suganath Prabu S <[email protected]>
Thanks,
Suganath.
Quoted 31 lines · Gen Zhang
In
_ctl_ioctl_main(), 'ioctl_header' is fetched the first time from userspace. 'ioctl_header.ioc_number' is then checked. The legal result is saved to 'ioc'. Then, in condition MPT3COMMAND, the whole struct is fetched again from the userspace. Then_ctl_do_mpt_command()is called, 'ioc' and 'karg' as inputs.However, a malicious user can change the '
ioc_number' between the two fetches, which will cause a potential security issues. Moreover, a malicious user can provide a valid 'ioc_number' to pass the check in first fetch, and then modify it in the second fetch.To fix this, we need to recheck the '
ioc_number' in the second fetch.Signed-off-by Gen Zhang <[email protected]>---
drivers/scsi/mpt3sas/mpt3sas_ctl.c +4
-0@@ -2319,6 +2319,10 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,break ; } +if (karg.hdr.ioc_number != ioctl_header.ioc_number) { + ret = -EINVAL ; +break ; + }if (_IOC_SIZE (cmd) ==sizeof (struct mpt3_ioctl_command )) { uarg = arg; ret =_ctl_do_mpt_command (ioc, karg, &uarg->mf);
Quoted 32 lines · Suganath Prabu Subramani
Please consider this patch as Ack-by: Suganath Prabu S <[email protected]>
Thanks,
Suganath.Quoted 24 lines · Gen Zhang
In
_ctl_ioctl_main(), 'ioctl_header' is fetched the first time from userspace. 'ioctl_header.ioc_number' is then checked. The legal result is saved to 'ioc'. Then, in condition MPT3COMMAND, the whole struct is fetched again from the userspace. Then_ctl_do_mpt_command()is called, 'ioc' and 'karg' as inputs.However, a malicious user can change the '
ioc_number' between the two fetches, which will cause a potential security issues. Moreover, a malicious user can provide a valid 'ioc_number' to pass the check in first fetch, and then modify it in the second fetch.To fix this, we need to recheck the '
ioc_number' in the second fetch.Signed-off-by Gen Zhang <[email protected]>---
drivers/scsi/mpt3sas/mpt3sas_ctl.c +0
-0@@ -2319,6 +2319,10 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,break ; }
Quoted 7 lines
drivers/scsi/mpt3sas/mpt3sas_ctl.c _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg, · line 2328
Quoted 7 lines
drivers/scsi/mpt3sas/mpt3sas_ctl.c +4
-0+if (karg.hdr.ioc_number != ioctl_header.ioc_number) { + ret = -EINVAL ; +break ; + }if (_IOC_SIZE (cmd) ==sizeof (struct mpt3_ioctl_command )) { uarg = arg; ret =_ctl_do_mpt_command (ioc, karg, &uarg->mf);
Thanks for your reply, Suganath.
Thanks
Gen