* [PATCH] macintosh:fix oob read in do_adb_query function
@ 2022-07-13 15:37 Ning Qiang
2022-07-13 16:43 ` Greg KH
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Ning Qiang @ 2022-07-13 15:37 UTC (permalink / raw)
To: benh, sohu0106; +Cc: greg, security, linuxppc-dev
In do_adb_query function of drivers/macintosh/adb.c, req->data is copy
form userland. the parameter "req->data[2]" is Missing check, the
array size of adb_handler[] is 16, so "adb_handler[
req->data[2]].original_address" and "adb_handler[
req->data[2]].handler_id" will lead to oob read.
Signed-off-by: Ning Qiang <sohu0106@126.com>
---
drivers/macintosh/adb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 439fab4eaa85..1bbb9ca08d40 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -647,7 +647,7 @@ do_adb_query(struct adb_request *req)
switch(req->data[1]) {
case ADB_QUERY_GETDEVINFO:
- if (req->nbytes < 3)
+ if (req->nbytes < 3 || req->data[2] >= 16)
break;
mutex_lock(&adb_handler_mutex);
req->reply[0] = adb_handler[req->data[2]].original_address;
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] macintosh:fix oob read in do_adb_query function
2022-07-13 15:37 [PATCH] macintosh:fix oob read in do_adb_query function Ning Qiang
@ 2022-07-13 16:43 ` Greg KH
2022-07-13 18:53 ` Kees Cook
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2022-07-13 16:43 UTC (permalink / raw)
To: Ning Qiang; +Cc: security, linuxppc-dev
On Wed, Jul 13, 2022 at 11:37:34PM +0800, Ning Qiang wrote:
> In do_adb_query function of drivers/macintosh/adb.c, req->data is copy
> form userland. the parameter "req->data[2]" is Missing check, the
> array size of adb_handler[] is 16, so "adb_handler[
> req->data[2]].original_address" and "adb_handler[
> req->data[2]].handler_id" will lead to oob read.
>
> Signed-off-by: Ning Qiang <sohu0106@126.com>
Cc: stable <stable@kernel.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] macintosh:fix oob read in do_adb_query function
2022-07-13 15:37 [PATCH] macintosh:fix oob read in do_adb_query function Ning Qiang
2022-07-13 16:43 ` Greg KH
@ 2022-07-13 18:53 ` Kees Cook
2022-07-14 22:33 ` Benjamin Herrenschmidt
2022-07-14 22:33 ` Benjamin Herrenschmidt
2022-07-29 13:01 ` Michael Ellerman
3 siblings, 1 reply; 8+ messages in thread
From: Kees Cook @ 2022-07-13 18:53 UTC (permalink / raw)
To: Ning Qiang; +Cc: security, linuxppc-dev, greg
On Wed, Jul 13, 2022 at 11:37:34PM +0800, Ning Qiang wrote:
> In do_adb_query function of drivers/macintosh/adb.c, req->data is copy
> form userland. the parameter "req->data[2]" is Missing check, the
> array size of adb_handler[] is 16, so "adb_handler[
> req->data[2]].original_address" and "adb_handler[
> req->data[2]].handler_id" will lead to oob read.
>
> Signed-off-by: Ning Qiang <sohu0106@126.com>
Thanks for catching this!
Do you have a reproducer for this? I'd expect CONFIG_UBSAN_BOUNDS=y to
notice this at runtime, at least.
> ---
> drivers/macintosh/adb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
> index 439fab4eaa85..1bbb9ca08d40 100644
> --- a/drivers/macintosh/adb.c
> +++ b/drivers/macintosh/adb.c
> @@ -647,7 +647,7 @@ do_adb_query(struct adb_request *req)
>
> switch(req->data[1]) {
> case ADB_QUERY_GETDEVINFO:
> - if (req->nbytes < 3)
> + if (req->nbytes < 3 || req->data[2] >= 16)
I'd prefer this was:
+ if (req->nbytes < 3 || req->data[2] >= ARRAY_SIZE(adb_handler))
so it's tied to the actual variable (if its size ever changes).
With that:
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
> break;
> mutex_lock(&adb_handler_mutex);
> req->reply[0] = adb_handler[req->data[2]].original_address;
> --
> 2.25.1
>
--
Kees Cook
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] macintosh:fix oob read in do_adb_query function
2022-07-13 18:53 ` Kees Cook
@ 2022-07-14 22:33 ` Benjamin Herrenschmidt
0 siblings, 0 replies; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2022-07-14 22:33 UTC (permalink / raw)
To: Kees Cook, Ning Qiang; +Cc: greg, security, linuxppc-dev
On Wed, 2022-07-13 at 11:53 -0700, Kees Cook wrote:
> On Wed, Jul 13, 2022 at 11:37:34PM +0800, Ning Qiang wrote:
> > In do_adb_query function of drivers/macintosh/adb.c, req->data is
> > copy
> > form userland. the parameter "req->data[2]" is Missing check, the
> > array size of adb_handler[] is 16, so "adb_handler[
> > req->data[2]].original_address" and "adb_handler[
> > req->data[2]].handler_id" will lead to oob read.
> >
> > Signed-off-by: Ning Qiang <sohu0106@126.com>
>
> Thanks for catching this!
>
> Do you have a reproducer for this? I'd expect CONFIG_UBSAN_BOUNDS=y
> to notice this at runtime, at least.
For that you would need an ancient Mac with an ADB bus which might be
tricky ... I have some in the basement that could possibly be revived
if you really insist but I'd rather not waste the time...
Cheers,
Ben.
>
> > ---
> > drivers/macintosh/adb.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
> > index 439fab4eaa85..1bbb9ca08d40 100644
> > --- a/drivers/macintosh/adb.c
> > +++ b/drivers/macintosh/adb.c
> > @@ -647,7 +647,7 @@ do_adb_query(struct adb_request *req)
> >
> > switch(req->data[1]) {
> > case ADB_QUERY_GETDEVINFO:
> > - if (req->nbytes < 3)
> > + if (req->nbytes < 3 || req->data[2] >= 16)
>
> I'd prefer this was:
>
> + if (req->nbytes < 3 || req->data[2] >=
> ARRAY_SIZE(adb_handler))
>
> so it's tied to the actual variable (if its size ever changes).
>
> With that:
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
>
> -Kees
>
> > break;
> > mutex_lock(&adb_handler_mutex);
> > req->reply[0] = adb_handler[req-
> > >data[2]].original_address;
> > --
> > 2.25.1
> >
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] macintosh:fix oob read in do_adb_query function
2022-07-13 15:37 [PATCH] macintosh:fix oob read in do_adb_query function Ning Qiang
2022-07-13 16:43 ` Greg KH
2022-07-13 18:53 ` Kees Cook
@ 2022-07-14 22:33 ` Benjamin Herrenschmidt
2022-07-29 13:01 ` Michael Ellerman
3 siblings, 0 replies; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2022-07-14 22:33 UTC (permalink / raw)
To: Ning Qiang; +Cc: greg, security, linuxppc-dev
On Wed, 2022-07-13 at 23:37 +0800, Ning Qiang wrote:
> In do_adb_query function of drivers/macintosh/adb.c, req->data is
> copy
> form userland. the parameter "req->data[2]" is Missing check, the
> array size of adb_handler[] is 16, so "adb_handler[
> req->data[2]].original_address" and "adb_handler[
> req->data[2]].handler_id" will lead to oob read.
>
> Signed-off-by: Ning Qiang <sohu0106@126.com>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
> drivers/macintosh/adb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
> index 439fab4eaa85..1bbb9ca08d40 100644
> --- a/drivers/macintosh/adb.c
> +++ b/drivers/macintosh/adb.c
> @@ -647,7 +647,7 @@ do_adb_query(struct adb_request *req)
>
> switch(req->data[1]) {
> case ADB_QUERY_GETDEVINFO:
> - if (req->nbytes < 3)
> + if (req->nbytes < 3 || req->data[2] >= 16)
> break;
> mutex_lock(&adb_handler_mutex);
> req->reply[0] = adb_handler[req-
> >data[2]].original_address;
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] macintosh:fix oob read in do_adb_query function
2022-07-13 15:37 [PATCH] macintosh:fix oob read in do_adb_query function Ning Qiang
` (2 preceding siblings ...)
2022-07-14 22:33 ` Benjamin Herrenschmidt
@ 2022-07-29 13:01 ` Michael Ellerman
3 siblings, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2022-07-29 13:01 UTC (permalink / raw)
To: benh, Ning Qiang; +Cc: greg, security, linuxppc-dev
On Wed, 13 Jul 2022 23:37:34 +0800, Ning Qiang wrote:
> In do_adb_query function of drivers/macintosh/adb.c, req->data is copy
> form userland. the parameter "req->data[2]" is Missing check, the
> array size of adb_handler[] is 16, so "adb_handler[
> req->data[2]].original_address" and "adb_handler[
> req->data[2]].handler_id" will lead to oob read.
>
>
> [...]
Applied to powerpc/next.
[1/1] macintosh:fix oob read in do_adb_query function
https://git.kernel.org/powerpc/c/fd97e4ad6d3b0c9fce3bca8ea8e6969d9ce7423b
cheers
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] macintosh:fix oob read in do_adb_query function
@ 2022-07-13 13:40 NAME
2022-07-13 14:03 ` Greg KH
0 siblings, 1 reply; 8+ messages in thread
From: NAME @ 2022-07-13 13:40 UTC (permalink / raw)
To: benh, sohu0106; +Cc: security, linuxppc-dev
From: sohu0106 <sohu0106@126.com>
In do_adb_query function of drivers/macintosh/adb.c,
req->data is copy form userland. The parameter
"req->data[2]" is Missing check, the array size of
adb_handler[] is 16, so "adb_handler[req->data[2]].
original_address" and "adb_handler[req->data[2]].
handler_id" will lead to oob read.
Signed-off-by: sohu0106 <sohu0106@126.com>
---
drivers/macintosh/adb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 439fab4eaa85..1bbb9ca08d40 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -647,7 +647,7 @@ do_adb_query(struct adb_request *req)
switch(req->data[1]) {
case ADB_QUERY_GETDEVINFO:
- if (req->nbytes < 3)
+ if (req->nbytes < 3 || req->data[2] >= 16)
break;
mutex_lock(&adb_handler_mutex);
req->reply[0] = adb_handler[req->data[2]].original_address;
--
2.25.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] macintosh:fix oob read in do_adb_query function
2022-07-13 13:40 NAME
@ 2022-07-13 14:03 ` Greg KH
0 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2022-07-13 14:03 UTC (permalink / raw)
To: NAME; +Cc: security, linuxppc-dev
On Wed, Jul 13, 2022 at 09:40:37PM +0800, NAME wrote:
> From: sohu0106 <sohu0106@126.com>
For obvious reasons, we need a real name here, and in the signed-off-by
line.
> In do_adb_query function of drivers/macintosh/adb.c,
> req->data is copy form userland. The parameter
> "req->data[2]" is Missing check, the array size of
> adb_handler[] is 16, so "adb_handler[req->data[2]].
> original_address" and "adb_handler[req->data[2]].
> handler_id" will lead to oob read.
You can use all 72 columns, if you want to re-wrap these lines when you
resend.
>
> Signed-off-by: sohu0106 <sohu0106@126.com>
> ---
> drivers/macintosh/adb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
> index 439fab4eaa85..1bbb9ca08d40 100644
> --- a/drivers/macintosh/adb.c
> +++ b/drivers/macintosh/adb.c
> @@ -647,7 +647,7 @@ do_adb_query(struct adb_request *req)
>
> switch(req->data[1]) {
> case ADB_QUERY_GETDEVINFO:
> - if (req->nbytes < 3)
> + if (req->nbytes < 3 || req->data[2] >= 16)
Shouldn't 16 be the array size instead of having this hard coded to a
magic number?
Something like "sizeof(adb_handler) / sizeof(struct adb_handler)"?
Maybe not, that's messy, your choice.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-07-29 13:23 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-13 15:37 [PATCH] macintosh:fix oob read in do_adb_query function Ning Qiang
2022-07-13 16:43 ` Greg KH
2022-07-13 18:53 ` Kees Cook
2022-07-14 22:33 ` Benjamin Herrenschmidt
2022-07-14 22:33 ` Benjamin Herrenschmidt
2022-07-29 13:01 ` Michael Ellerman
-- strict thread matches above, loose matches on Subject: below --
2022-07-13 13:40 NAME
2022-07-13 14:03 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox