All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main()
@ 2019-05-27  0:57 Gen Zhang
  2019-05-28  6:14 ` Suganath Prabu Subramani
  0 siblings, 1 reply; 5+ messages in thread
From: Gen Zhang @ 2019-05-27  0:57 UTC (permalink / raw)
  To: sathya.prakash, chaitra.basappa, suganath-prabu.subramani, jejb,
	martin.petersen
  Cc: MPT-FusionLinux.pdl, linux-scsi, linux-kernel

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 <blackgod016574@gmail.com>
---
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index b2bb47c..5181c03 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -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);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main()
  2019-05-27  0:57 [PATCH] mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main() Gen Zhang
@ 2019-05-28  6:14 ` Suganath Prabu Subramani
  2019-05-28  7:05   ` Gen Zhang
  0 siblings, 1 reply; 5+ messages in thread
From: Suganath Prabu Subramani @ 2019-05-28  6:14 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Sathya Prakash, James E.J. Bottomley, PDL-MPT-FUSIONLINUX,
	Gen Zhang, linux-scsi, linux-kernel

Please consider this patch as Ack-by: Suganath Prabu S
<suganath-prabu.subramani@broadcom.com>

Thanks,
Suganath.


On Mon, May 27, 2019 at 6:27 AM Gen Zhang <blackgod016574@gmail.com> wrote:
>
> 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 <blackgod016574@gmail.com>
> ---
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> index b2bb47c..5181c03 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> @@ -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);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main()
  2019-05-28  6:14 ` Suganath Prabu Subramani
@ 2019-05-28  7:05   ` Gen Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Gen Zhang @ 2019-05-28  7:05 UTC (permalink / raw)
  To: Suganath Prabu Subramani
  Cc: Martin K. Petersen, Sathya Prakash, James E.J. Bottomley,
	PDL-MPT-FUSIONLINUX, linux-scsi, linux-kernel

On Tue, May 28, 2019 at 11:44:35AM +0530, Suganath Prabu Subramani wrote:
> Please consider this patch as Ack-by: Suganath Prabu S
> <suganath-prabu.subramani@broadcom.com>
> 
> Thanks,
> Suganath.
> 
> 
> On Mon, May 27, 2019 at 6:27 AM Gen Zhang <blackgod016574@gmail.com> wrote:
> >
> > 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 <blackgod016574@gmail.com>
> > ---
> > diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> > index b2bb47c..5181c03 100644
> > --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> > +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
> > @@ -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);
Thanks for your reply, Suganath.

Thanks
Gen

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main()
  2019-05-30  1:10 Gen Zhang
@ 2019-05-30  2:22 ` Martin K. Petersen
  0 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2019-05-30  2:22 UTC (permalink / raw)
  To: Gen Zhang
  Cc: sathya.prakash, chaitra.basappa, jejb, martin.petersen,
	suganath-prabu.subramani, MPT-FusionLinux.pdl, linux-scsi,
	linux-kernel


Gen,

> 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.

Applied to 5.3/scsi-queue, thanks.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main()
@ 2019-05-30  1:10 Gen Zhang
  2019-05-30  2:22 ` Martin K. Petersen
  0 siblings, 1 reply; 5+ messages in thread
From: Gen Zhang @ 2019-05-30  1:10 UTC (permalink / raw)
  To: sathya.prakash, chaitra.basappa, jejb, martin.petersen
  Cc: suganath-prabu.subramani, MPT-FusionLinux.pdl, linux-scsi, linux-kernel

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 <blackgod016574@gmail.com>
Ack-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
---
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index b2bb47c..5181c03 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -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);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-05-30  2:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-27  0:57 [PATCH] mpt3sas_ctl: fix double-fetch bug in _ctl_ioctl_main() Gen Zhang
2019-05-28  6:14 ` Suganath Prabu Subramani
2019-05-28  7:05   ` Gen Zhang
2019-05-30  1:10 Gen Zhang
2019-05-30  2:22 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.