Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2791772rwb; Sat, 8 Oct 2022 14:35:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ngdnc8ygfwYvyHwaDhASMCVlSEr1z/Dk8JHE6FJmrDpLB8AP+b4ga6Q6UHYHckljIBAVl X-Received: by 2002:a17:907:a0c6:b0:780:bc37:2552 with SMTP id hw6-20020a170907a0c600b00780bc372552mr8915972ejc.314.1665264944112; Sat, 08 Oct 2022 14:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665264944; cv=none; d=google.com; s=arc-20160816; b=ML9H31LUo/nOzR6VaFrQGSdkXSZxYv+iENZhOxojHbHuI8c9pmZvk/3MI62512i7G8 cY/WPumZbFbypRGJV9YOnmGrm7WjkUaGhIEI9Q/TurMgNVJMHL8yZpsrvfjzI4oY1564 jNFD7OBaMhJ/4gap8HaiQInJ2SpBPrOtJnuyv+99BCJFHKkMZJBoZJgChhz7XWq1NVb9 BG9haluZENxG3n7ZexHEJGGcrbtQlK3CLamBQezvRtfgvvsaVrhPGs0RjTWDuI1Z14S6 gvcSkxpLapOKXuiLILpyqAOrGTyHi21Py5RRCFu9QAGw7Fgne88mnRICmwArSO3F1/2K vHoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=bZdcjiB27MoUxn+8zOiq4szSjnTS6QpmehnqllTRkrc=; b=Hzk9iWisVCAu497On2nxAKoDFmU6FpSB/VIv2VXa2gloPm9picmxPij+sOtIKzYThz pTxGxSTM+rpgWi70Zz/qPsBkEK4MK1ZGIr6lfpNyEL369PqO1t+I+CIrKxlPgviVUplJ mPqWzB3KWB5yBp304+CIXnkLfppE3r+pFH70OrNcAY/HrQQxLcOkvPj1BACCqK4OHQIV 1SnPh1PyHmzR3g4w0F+ia+ykFP+DtiYWI203QYlxEc1M6nEr2uTwyDNnzSZdYUxxYGuQ KmR5pybtsrSSHpPdslYHIEoPjdeKltVzHR7U7Qo7E86R3h/wCyEt2uaIOpd/1t3i3dhX 3SOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=QJOaG9p8; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g6-20020a1709061e0600b00781df71dbc1si4725890ejj.174.2022.10.08.14.35.20; Sat, 08 Oct 2022 14:35:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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; dkim=pass header.i=@ispras.ru header.s=default header.b=QJOaG9p8; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229720AbiJHVP5 (ORCPT + 61 others); Sat, 8 Oct 2022 17:15:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbiJHVPz (ORCPT ); Sat, 8 Oct 2022 17:15:55 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A2AD38690; Sat, 8 Oct 2022 14:15:53 -0700 (PDT) Received: from localhost.localdomain (unknown [46.242.14.200]) by mail.ispras.ru (Postfix) with ESMTPSA id 4B03840755EC; Sat, 8 Oct 2022 21:15:46 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 4B03840755EC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1665263746; bh=bZdcjiB27MoUxn+8zOiq4szSjnTS6QpmehnqllTRkrc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QJOaG9p8YJUps4aehfztiOoeC4kltL5BIYkJrNjDIUQxauFK/UJ+erAP/C0JoAiEh 9bM4//M1wcWK3G474jNln7YNLmlygfFE2JJ9tz8yGTPV7BQLTmrxxVaHuZBhHifgOx lYok5uvx0pxMUVPZYEIsZaASrUsi4fOHJl218l64= From: Fedor Pchelkin To: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Kalle Valo Cc: Fedor Pchelkin , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org, Johannes Berg , Alan Stern Subject: [PATCH v5] ath9k: verify the expected usb_endpoints are present Date: Sun, 9 Oct 2022 00:15:32 +0300 Message-Id: <20221008211532.74583-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <3acec81e863aa5f184bc5a74916f1470b77552cb.camel@sipsolutions.net> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-wireless@vger.kernel.org The bug arises when a USB device claims to be an ATH9K but doesn't have the expected endpoints. (In this case there was an interrupt endpoint where the driver expected a bulk endpoint.) The kernel needs to be able to handle such devices without getting an internal error. usb 1-1: BOGUS urb xfer, pipe 3 != type 1 WARNING: CPU: 3 PID: 500 at drivers/usb/core/urb.c:493 usb_submit_urb+0xce2/0x1430 drivers/usb/core/urb.c:493 Modules linked in: CPU: 3 PID: 500 Comm: kworker/3:2 Not tainted 5.10.135-syzkaller #0 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 Workqueue: events request_firmware_work_func RIP: 0010:usb_submit_urb+0xce2/0x1430 drivers/usb/core/urb.c:493 Call Trace: ath9k_hif_usb_alloc_rx_urbs drivers/net/wireless/ath/ath9k/hif_usb.c:908 [inline] ath9k_hif_usb_alloc_urbs+0x75e/0x1010 drivers/net/wireless/ath/ath9k/hif_usb.c:1019 ath9k_hif_usb_dev_init drivers/net/wireless/ath/ath9k/hif_usb.c:1109 [inline] ath9k_hif_usb_firmware_cb+0x142/0x530 drivers/net/wireless/ath/ath9k/hif_usb.c:1242 request_firmware_work_func+0x12e/0x240 drivers/base/firmware_loader/main.c:1097 process_one_work+0x9af/0x1600 kernel/workqueue.c:2279 worker_thread+0x61d/0x12f0 kernel/workqueue.c:2425 kthread+0x3b4/0x4a0 kernel/kthread.c:313 ret_from_fork+0x22/0x30 arch/x86/entry/entry_64.S:299 Found by Linux Verification Center (linuxtesting.org) with Syzkaller. Suggested-by: Alan Stern Signed-off-by: Fedor Pchelkin Signed-off-by: Alexey Khoroshilov --- v1->v2: use reverse x-mas tree ordering of the variable definitions v2->v3: fix tab v3->v4: fix patch apply error v4->v5: fix tab problem drivers/net/wireless/ath/ath9k/hif_usb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c index 4d9002a9d082..1ffd6cd5dceb 100644 --- a/drivers/net/wireless/ath/ath9k/hif_usb.c +++ b/drivers/net/wireless/ath/ath9k/hif_usb.c @@ -1329,10 +1329,24 @@ static int send_eject_command(struct usb_interface *interface) static int ath9k_hif_usb_probe(struct usb_interface *interface, const struct usb_device_id *id) { + struct usb_endpoint_descriptor *bulk_in, *bulk_out, *int_in, *int_out; struct usb_device *udev = interface_to_usbdev(interface); + struct usb_host_interface *alt; struct hif_device_usb *hif_dev; int ret = 0; + /* Verify the expected endpoints are present */ + alt = interface->cur_altsetting; + if (usb_find_common_endpoints(alt, &bulk_in, &bulk_out, &int_in, &int_out) < 0 || + usb_endpoint_num(bulk_in) != USB_WLAN_RX_PIPE || + usb_endpoint_num(bulk_out) != USB_WLAN_TX_PIPE || + usb_endpoint_num(int_in) != USB_REG_IN_PIPE || + usb_endpoint_num(int_out) != USB_REG_OUT_PIPE) { + dev_err(&udev->dev, + "ath9k_htc: Device endpoint numbers are not the expected ones\n"); + return -ENODEV; + } + if (id->driver_info == STORAGE_DEVICE) return send_eject_command(interface); -- 2.25.1