From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24BF9C433EF for ; Thu, 14 Jul 2022 22:36:13 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4LkTqH6900z3dxK for ; Fri, 15 Jul 2022 08:36:11 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.crashing.org (client-ip=63.228.1.57; helo=gate.crashing.org; envelope-from=benh@kernel.crashing.org; receiver=) Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by lists.ozlabs.org (Postfix) with ESMTP id 4LkTpf4hnGz3cDR for ; Fri, 15 Jul 2022 08:35:38 +1000 (AEST) Received: from ip6-localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 26EMXI0t022136; Thu, 14 Jul 2022 17:33:19 -0500 Message-ID: Subject: Re: [PATCH] macintosh:fix oob read in do_adb_query function From: Benjamin Herrenschmidt To: Kees Cook , Ning Qiang Date: Fri, 15 Jul 2022 08:33:18 +1000 In-Reply-To: <202207131149.606A481BD8@keescook> References: <20220713153734.2248-1-sohu0106@126.com> <202207131149.606A481BD8@keescook> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: greg@kroah.com, security@kernel.org, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "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 > > 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 > > -Kees > > > break; > > mutex_lock(&adb_handler_mutex); > > req->reply[0] = adb_handler[req- > > >data[2]].original_address; > > -- > > 2.25.1 > >