From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Kees Cook <keescook@chromium.org>, Ning Qiang <sohu0106@126.com>
Cc: greg@kroah.com, security@kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] macintosh:fix oob read in do_adb_query function
Date: Fri, 15 Jul 2022 08:33:18 +1000 [thread overview]
Message-ID: <c890a74032803137d319f5b56f6dbe6190018c40.camel@kernel.crashing.org> (raw)
In-Reply-To: <202207131149.606A481BD8@keescook>
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
> >
next prev parent reply other threads:[~2022-07-14 22:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c890a74032803137d319f5b56f6dbe6190018c40.camel@kernel.crashing.org \
--to=benh@kernel.crashing.org \
--cc=greg@kroah.com \
--cc=keescook@chromium.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=security@kernel.org \
--cc=sohu0106@126.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox