* [PATCH] staging: vchiq_arm: fix compat VCHIQ_IOC_AWAIT_COMPLETION
@ 2018-11-03 22:30 Ben Wolsieffer
2018-11-03 23:07 ` Stefan Wahren
0 siblings, 1 reply; 4+ messages in thread
From: Ben Wolsieffer @ 2018-11-03 22:30 UTC (permalink / raw)
To: linux-arm-kernel
The compatibility ioctl wrapper for VCHIQ_IOC_AWAIT_COMPLETION assumes that
the native ioctl always uses a message buffer and decrements msgbufcount.
Certain message types do not use a message buffer and in this case
msgbufcount is not decremented, and completion->header for the message is
NULL. Because the wrapper unconditionally decrements msgbufcount, the
calling process may assume that a message buffer has been used even when
it has not.
This results in a memory leak in the userspace code that interfaces with
this driver. When msgbufcount is decremented, the userspace code assumes
that the buffer can be freed though the reference in completion->header,
which cannot happen when the reference is NULL.
This patch causes the wrapper to only decrement msgbufcount when the
native ioctl decrements it. Note that we cannot simply copy the native
ioctl's value of msgbufcount, because the wrapper only retrieves messages
from the native ioctl one at a time, while userspace may request multiple
messages.
Fixes: 5569a12 ("staging: vchiq_arm: Add compatibility wrappers for ioctls")
Signed-off-by: Ben Wolsieffer <benwolsieffer@gmail.com>
---
.../staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index d67987fbf25e..8ff0e7e860f3 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1461,6 +1461,7 @@ vchiq_compat_ioctl_await_completion(struct file *file,
struct vchiq_await_completion32 args32;
struct vchiq_completion_data32 completion32;
unsigned int *msgbufcount32;
+ unsigned int msgbufcount_native;
compat_uptr_t msgbuf32;
void *msgbuf;
void **msgbufptr;
@@ -1572,7 +1573,11 @@ vchiq_compat_ioctl_await_completion(struct file *file,
sizeof(completion32)))
return -EFAULT;
- args32.msgbufcount--;
+ if (get_user(msgbufcount_native, &args->msgbufcount))
+ return -EFAULT;
+
+ if (!msgbufcount_native)
+ args32.msgbufcount--;
msgbufcount32 =
&((struct vchiq_await_completion32 __user *)arg)->msgbufcount;
--
2.19.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] staging: vchiq_arm: fix compat VCHIQ_IOC_AWAIT_COMPLETION
2018-11-03 22:30 [PATCH] staging: vchiq_arm: fix compat VCHIQ_IOC_AWAIT_COMPLETION Ben Wolsieffer
@ 2018-11-03 23:07 ` Stefan Wahren
2018-11-03 23:32 ` [PATCH v2] " Ben Wolsieffer
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Wahren @ 2018-11-03 23:07 UTC (permalink / raw)
To: linux-arm-kernel
Hi Ben,
> Ben Wolsieffer <benwolsieffer@gmail.com> hat am 3. November 2018 um 23:30 geschrieben:
>
>
> The compatibility ioctl wrapper for VCHIQ_IOC_AWAIT_COMPLETION assumes that
> the native ioctl always uses a message buffer and decrements msgbufcount.
> Certain message types do not use a message buffer and in this case
> msgbufcount is not decremented, and completion->header for the message is
> NULL. Because the wrapper unconditionally decrements msgbufcount, the
> calling process may assume that a message buffer has been used even when
> it has not.
>
> This results in a memory leak in the userspace code that interfaces with
> this driver. When msgbufcount is decremented, the userspace code assumes
> that the buffer can be freed though the reference in completion->header,
> which cannot happen when the reference is NULL.
>
> This patch causes the wrapper to only decrement msgbufcount when the
> native ioctl decrements it. Note that we cannot simply copy the native
> ioctl's value of msgbufcount, because the wrapper only retrieves messages
> from the native ioctl one at a time, while userspace may request multiple
> messages.
>
> Fixes: 5569a12 ("staging: vchiq_arm: Add compatibility wrappers for ioctls")
>
> Signed-off-by: Ben Wolsieffer <benwolsieffer@gmail.com>
thanks for sending this patch. Unfortunately you missed some necessary recipients from scripts/get_maintainters.pl:
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
devel at driverdev.osuosl.org
Btw please add a link to your pull request into the commit log to provide more background info:
Link: https://github.com/raspberrypi/linux/pull/2703
Thanks
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] staging: vchiq_arm: fix compat VCHIQ_IOC_AWAIT_COMPLETION
2018-11-03 23:07 ` Stefan Wahren
@ 2018-11-03 23:32 ` Ben Wolsieffer
2018-11-10 16:41 ` Stefan Wahren
0 siblings, 1 reply; 4+ messages in thread
From: Ben Wolsieffer @ 2018-11-03 23:32 UTC (permalink / raw)
To: linux-arm-kernel
The compatibility ioctl wrapper for VCHIQ_IOC_AWAIT_COMPLETION assumes that
the native ioctl always uses a message buffer and decrements msgbufcount.
Certain message types do not use a message buffer and in this case
msgbufcount is not decremented, and completion->header for the message is
NULL. Because the wrapper unconditionally decrements msgbufcount, the
calling process may assume that a message buffer has been used even when
it has not.
This results in a memory leak in the userspace code that interfaces with
this driver. When msgbufcount is decremented, the userspace code assumes
that the buffer can be freed though the reference in completion->header,
which cannot happen when the reference is NULL.
This patch causes the wrapper to only decrement msgbufcount when the
native ioctl decrements it. Note that we cannot simply copy the native
ioctl's value of msgbufcount, because the wrapper only retrieves messages
from the native ioctl one at a time, while userspace may request multiple
messages.
See https://github.com/raspberrypi/linux/pull/2703 for more discussion of
this patch.
Fixes: 5569a12 ("staging: vchiq_arm: Add compatibility wrappers for ioctls")
Signed-off-by: Ben Wolsieffer <benwolsieffer@gmail.com>
---
I added the missing recipients and a link to the GitHub PR in the commit
message.
.../staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index d67987fbf25e..8ff0e7e860f3 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1461,6 +1461,7 @@ vchiq_compat_ioctl_await_completion(struct file *file,
struct vchiq_await_completion32 args32;
struct vchiq_completion_data32 completion32;
unsigned int *msgbufcount32;
+ unsigned int msgbufcount_native;
compat_uptr_t msgbuf32;
void *msgbuf;
void **msgbufptr;
@@ -1572,7 +1573,11 @@ vchiq_compat_ioctl_await_completion(struct file *file,
sizeof(completion32)))
return -EFAULT;
- args32.msgbufcount--;
+ if (get_user(msgbufcount_native, &args->msgbufcount))
+ return -EFAULT;
+
+ if (!msgbufcount_native)
+ args32.msgbufcount--;
msgbufcount32 =
&((struct vchiq_await_completion32 __user *)arg)->msgbufcount;
--
2.19.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2] staging: vchiq_arm: fix compat VCHIQ_IOC_AWAIT_COMPLETION
2018-11-03 23:32 ` [PATCH v2] " Ben Wolsieffer
@ 2018-11-10 16:41 ` Stefan Wahren
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Wahren @ 2018-11-10 16:41 UTC (permalink / raw)
To: linux-arm-kernel
> Ben Wolsieffer <benwolsieffer@gmail.com> hat am 4. November 2018 um 00:32 geschrieben:
>
>
> The compatibility ioctl wrapper for VCHIQ_IOC_AWAIT_COMPLETION assumes that
> the native ioctl always uses a message buffer and decrements msgbufcount.
> Certain message types do not use a message buffer and in this case
> msgbufcount is not decremented, and completion->header for the message is
> NULL. Because the wrapper unconditionally decrements msgbufcount, the
> calling process may assume that a message buffer has been used even when
> it has not.
>
> This results in a memory leak in the userspace code that interfaces with
> this driver. When msgbufcount is decremented, the userspace code assumes
> that the buffer can be freed though the reference in completion->header,
> which cannot happen when the reference is NULL.
>
> This patch causes the wrapper to only decrement msgbufcount when the
> native ioctl decrements it. Note that we cannot simply copy the native
> ioctl's value of msgbufcount, because the wrapper only retrieves messages
> from the native ioctl one at a time, while userspace may request multiple
> messages.
>
> See https://github.com/raspberrypi/linux/pull/2703 for more discussion of
> this patch.
>
> Fixes: 5569a12 ("staging: vchiq_arm: Add compatibility wrappers for ioctls")
>
> Signed-off-by: Ben Wolsieffer <benwolsieffer@gmail.com>
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-11-10 16:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-03 22:30 [PATCH] staging: vchiq_arm: fix compat VCHIQ_IOC_AWAIT_COMPLETION Ben Wolsieffer
2018-11-03 23:07 ` Stefan Wahren
2018-11-03 23:32 ` [PATCH v2] " Ben Wolsieffer
2018-11-10 16:41 ` Stefan Wahren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox