Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp405466imi; Fri, 22 Jul 2022 01:27:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sq3ifK6uLBPhmri9Yh3vUi+cTA/+6qGRRQvG90QDTv/LbtUtSCuolaTputXi8Y4NCxulge X-Received: by 2002:a17:906:8475:b0:72b:12c7:effe with SMTP id hx21-20020a170906847500b0072b12c7effemr2222264ejc.337.1658478449319; Fri, 22 Jul 2022 01:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658478449; cv=none; d=google.com; s=arc-20160816; b=nayxqzyKhUADTqGhOi59II8Cc9c4CMYD80anAgZuM+921byGNbtoYKx0BwssPlwIUe x+9nQvLHLWC6OBPnoLODx5BFs4JqSVUfxxEwcbCoMqulzWhAr2eVwbchgkdrbNCDlhMM f0RxaIJmzek+w796Jh7rgvqjjnFjfepRXMwaLMrqoA+z72AGlMN7rQhDIpzRN2J2G/hi aAzyWc91uH+0D7ekzLDJ/TBW9C2wsKhWs92u+P20NfrDs4R6GLwPFeIMSiDZ4oZG7dxH nOwVWS98nLgPY/lZ62VTJhrv/savfli1SStRAQYi31g4hk0TAuZzWsPNdZ/HJvZJ7mcJ XDdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=N+KB8Mo0yN3eUbhLN8EnTBjVYJxopJuFXCJ9Snu7VvQ=; b=LQoD7wETo1f04SNU16gdlmcTYjNY047DqzH/vtEOYVoiXLFYgA0apoEHFO2T3YNZOD 8iDhMusBrJb3O08fQ2z5LJLLzf5t2btHIWGNqp1w1dlPaO7WEqYf9dp+VJpOrR3qa91E pqKSPnLqldDOfscWy4nYlFpdzYJxF6qg/Sk91n3cQXRIueqnn3R4AiiF66SswF8xUVw7 am7lV3e03FhLtoE+Rm/PHaN264MpGzEU4LLQwzc8NCW6S3JF8RCwOPs5Jlpi1xiUbCsw 4YFpXt9syo0XEgfax2pAcTEMxR3dHXfDbEuPz0m8RzZSUIzySENt9N/TeX13r/J4m2EW iggw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht17-20020a170907609100b00715790f718dsi5531359ejc.318.2022.07.22.01.26.50; Fri, 22 Jul 2022 01:27:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234834AbiGVIYm (ORCPT + 99 others); Fri, 22 Jul 2022 04:24:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234001AbiGVIYl (ORCPT ); Fri, 22 Jul 2022 04:24:41 -0400 Received: from giacobini.uberspace.de (giacobini.uberspace.de [185.26.156.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 944799E2B5 for ; Fri, 22 Jul 2022 01:24:38 -0700 (PDT) Received: (qmail 14264 invoked by uid 990); 22 Jul 2022 08:24:36 -0000 Authentication-Results: giacobini.uberspace.de; auth=pass (plain) Message-ID: <14882455-c7c4-8e70-09d0-780308cf67f9@eknoes.de> Date: Fri, 22 Jul 2022 10:24:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [BUG] Null pointer deref in aosp_do_open/msft_do_open Content-Language: en-US To: Luiz Augusto von Dentz Cc: Johan Hedberg , Marcel Holtmann , "linux-bluetooth@vger.kernel.org" References: <01bb77a3-f138-7488-9ca9-71ec4f7d21a7@eknoes.de> From: =?UTF-8?Q?S=c3=b6nke_Huster?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Bar: / X-Rspamd-Report: MIME_GOOD(-0.1) BAYES_HAM(-0.718156) SUSPICIOUS_RECIPS(1.5) X-Rspamd-Score: 0.681843 Received: from unknown (HELO unkown) (::1) by giacobini.uberspace.de (Haraka/2.8.28) with ESMTPSA; Fri, 22 Jul 2022 10:24:36 +0200 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, MSGID_FROM_MTA_HEADER,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, On 21.07.22 19:52, Luiz Augusto von Dentz wrote: > Hi Sönke, > > On Thu, Jul 21, 2022 at 3:16 AM Sönke Huster wrote: >> >> Hi, >> >> My fuzzer found two null pointer exceptions in aosp_do_open and msft_do_open, both triggered by the >> same frame sequence on the current bluetooth-next master. >> >> BUG: kernel NULL pointer dereference, address: 0000000000000070 >> #PF: supervisor read access in kernel mode >> #PF: error_code(0x0000) - not-present page >> PGD 0 P4D 0 >> Oops: 0000 [#1] PREEMPT SMP NOPTI >> CPU: 0 PID: 41 Comm: kworker/u3:0 Not tainted 5.18.0-rc7-00850-g33b44d809538 #1 >> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 >> Workqueue: hci0 hci_power_on >> RIP: 0010:aosp_do_open+0x7e/0x230 >> Call Trace: >> >> hci_dev_open_sync+0x98b/0x1060 >> hci_power_on+0x84/0x350 >> process_one_work+0x2a6/0x5d0 >> worker_thread+0x4a/0x3d0 >> ? process_one_work+0x5d0/0x5d0 >> kthread+0xed/0x120 >> ? kthread_complete_and_exit+0x20/0x20 >> ret_from_fork+0x22/0x30 >> >> >> The null pointer deref occurs in the skb length check (net/bluetooth/aosp.c:64), the skb returned >> previously by __hci_cmd_sync is null: >> >> /* LE Get Vendor Capabilities Command */ >> skb = __hci_cmd_sync(hdev, hci_opcode_pack(0x3f, 0x153), 0, NULL, >> HCI_CMD_TIMEOUT); >> if (IS_ERR(skb)) { >> bt_dev_err(hdev, "AOSP get vendor capabilities (%ld)", >> PTR_ERR(skb)); >> return; >> } >> >> /* A basic length check */ >> if (skb->len < VENDOR_CAPA_BASE_SIZE) >> >> Bisected to: [d0b137062b2de75b264b84143d21c98abc5f5ad2] Bluetooth: hci_sync: Rework init stages >> >> It occurs when an AOSP resp. MSFT capable controller sends the following two different >> Command Status (0x0f) for Reset (0x0c03) on initialization: >> >> Status Octet: Unknown HCI Command (0x01) >> 0000 04 0f 04 01 02 03 0c >> >> Status Octet: Pending (0x00) >> 0000 04 0f 04 00 02 03 0c >> >> The problem seems to be that __hci_cmd_sync returns null, and not an PTR_ERR. The affected code >> for msft_do_open is similar (msft.c:128ff): >> >> skb = __hci_cmd_sync(hdev, hdev->msft_opcode, sizeof(cp), &cp, >> HCI_CMD_TIMEOUT); >> if (IS_ERR(skb)) { >> bt_dev_err(hdev, "Failed to read MSFT supported features (%ld)", >> PTR_ERR(skb)); >> return false; >> } >> >> if (skb->len < sizeof(*rp)) { >> >> Which one is triggered depends on the device reporting itself as either AOSP or MSFT capable. >> If it indicates both, it depends on timing. >> >> I think that can only be triggered by a malicious or broken Bluetooth controller, but there >> might be an underlying issue with __hci_cmd_sync returning null instead of an ERR_PTR. > > Yep that is most likely a Command Status being returned which isn't > expected for the commands above: > > /* If command return a status event skb will be set to NULL as there are > * no parameters, in case of failure IS_ERR(skb) would have be set to > * the actual error would be found with PTR_ERR(skb). > */ > if (!skb) > return 0; > Sorry, I could not reconstruct the contents of this comment from the code and did not see that comment. Thus, I thought there is an underlying error in the command response handling. > So perhaps we should convert these checks to IS_ERR_OR_NULL. OK, I'll submit a patch today. > >> Best >> Sönke > > >