Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp919680rwb; Sat, 3 Sep 2022 05:27:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR4S+kyqrGQV/94IRbc7WVP9QafheQyi4+qnyYwRBVm+F25wBpo+qU8hMxw3no6Cnl8gQUYi X-Received: by 2002:a63:170d:0:b0:415:f76d:45e1 with SMTP id x13-20020a63170d000000b00415f76d45e1mr34291438pgl.171.1662208026552; Sat, 03 Sep 2022 05:27:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662208026; cv=none; d=google.com; s=arc-20160816; b=zhyiIzuPIOWce9UbsUpBJKHzRb+g8v3xZLmWDQlFvyMW5CJi2aEDoJhuuIqvpBFJu5 +XptwTSNjLYWzJ40VmEhiZa/71pLL6GfzI2e6rI6DtL6J/n3/uZIm9bt0QVbXIWBwP+Q 3cqC7fLEGvN8E6iQwWlqAwvbkJQyDg8kx0faQK7g3piFfx9dC+9qFhZRzMxsN3zqecod mgdZukFAzMo76XkER+3KLhsRj5ycnZJgusOX+4/034mffQvcsRYOOw7pv/eboksBYwRe Q5XOAB99w1mY9ck82PZPGGobIRflnuANlGHBGjyuaAA9aC6uOhvKHtAeb4KBEPGd2qK1 XvGA== 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 :message-id:date:subject:cc:to:from; bh=E5slWc9mF000exoagQDpQc8Kt/Kb4OrSBcT3MewBY7E=; b=xx2uQO9wiGquaRxBzHDS+14nJkNWFjDJIqI04GcWeZXa40UbIMm/M+2/2whEa9texW Mf9KGRxOkl1RQumW42KGCM4XmcpNY1b16KftSjivk+7MfYUQPcF2j29xgw7JviVVS9Wq 4lQuVPPDO2RlDF4bFX+6qmmyPBkTtMeKW4HsBOVWsEYG5Mb0Ci9ULqcV51WRQtMTdcjm PkkFeGzZDmvWxTd09WVAXs4lT8aAeXqhoKX56rqaCetT9aLlaiorQ02yf6ixMko45nlV aBUul8bxhv1TEuL7SaC2h2pNZR6a6piHKEKXJ0aKbDosrsfZGGY6aj7UuFV3J+Wao/0u 139A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (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 136-20020a63008e000000b00430671e497asi1171880pga.687.2022.09.03.05.26.28; Sat, 03 Sep 2022 05:27:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230285AbiICMFG (ORCPT + 99 others); Sat, 3 Sep 2022 08:05:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbiICMFE (ORCPT ); Sat, 3 Sep 2022 08:05:04 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FC03275C8; Sat, 3 Sep 2022 05:05:00 -0700 (PDT) Received: from localhost.localdomain (unknown [46.242.14.200]) by mail.ispras.ru (Postfix) with ESMTPSA id 8850440737B2; Sat, 3 Sep 2022 12:04:54 +0000 (UTC) From: Fedor Pchelkin To: QCA ath9k Development , Kalle Valo Cc: Fedor Pchelkin , "David S. Miller" , Jakub Kicinski , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , ldv-project@linuxtesting.org, Alan Stern Subject: [PATCH] ath9k: verify the expected usb_endpoints are present Date: Sat, 3 Sep 2022 15:04:24 +0300 Message-Id: <20220903120424.12472-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-kernel@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 --- 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..2b26acf409fc 100644 --- a/drivers/net/wireless/ath/ath9k/hif_usb.c +++ b/drivers/net/wireless/ath/ath9k/hif_usb.c @@ -1332,6 +1332,20 @@ static int ath9k_hif_usb_probe(struct usb_interface *interface, struct usb_device *udev = interface_to_usbdev(interface); struct hif_device_usb *hif_dev; int ret = 0; + struct usb_host_interface *alt; + struct usb_endpoint_descriptor *bulk_in, *bulk_out, *int_in, *int_out; + + /* 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