Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3289965pxp; Tue, 8 Mar 2022 11:10:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqHGYWYl/8nKOSkFUVi6ZwLGo6lF/v8AVNxitWUG9ukx+CaSVePAaYzMtzaC8ELkwHx074 X-Received: by 2002:a17:907:7e9c:b0:6db:4788:66ab with SMTP id qb28-20020a1709077e9c00b006db478866abmr4562188ejc.112.1646766608063; Tue, 08 Mar 2022 11:10:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646766608; cv=none; d=google.com; s=arc-20160816; b=j8Sbb9zrQZkzCUZNqqJYXrLiPammSZkkPI9t20zpezc7efFtQ3p5LaFNQKoTQcmQUT 9H2n3XXRa5+0UWa5nn3p6N7+A9le1+0niLRcE9NVZBZ7CpQH7XBkBCa+CuDkhdDwUeG3 cVXwT5e5EPgneovtFtXl63e+L2nbMkDt2SS2U5HekcRAeUJT9+08XZhw9ErB21/WMFDK ICgC4FsOW8H+PC2/I/oGK3kZRbms1J2r50xFeLRz55udCSIxkOh+oHf8ELEpRRsb0zHN rjCjFaidFohAQvkS+XB3FSS0JN2A72y36aQnbT7uIWzM0CmzoyhnZ8VgE9V2uVzeXPQU N49w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=FS0ydfMarLV9kbW6AqtneKVvUqNm/uGFXcWK+i/U9Mw=; b=xYwwVfSXpPxaxnv/R8+kZZ91Hkd61FK6rj6XXUPuFKjYNra2BkeiPG2YEZ2L4NlFNF 3H1XW6sMv+ldhA9ZuhxErEiRp4aQe2ySMU25ojovLF6/EXVlzA8g9sTF2Zop/8xxbIhb mz1vD5Svy18rWPegeJsHI9YZ+Q0jHNLh5of7cEgzEMHvzRw5Ee/svzy5RECjzxUcT+V3 7NowhEGTUT5Kcg4RFzs2I+G2Co7DEMMKUoCEVTTWsONd8nPHC5cWJ5nis563s0zpj3v+ V6UThp2m4X1K0TEVHfMf1yVRtN2+IVyZuVrd1mupsbxtZ9OuLBzMQUDNymkj09qUiwTo AS9A== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a170906505000b006d1288a564asi10207758ejk.120.2022.03.08.11.09.41; Tue, 08 Mar 2022 11:10:08 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345230AbiCHIz2 (ORCPT + 99 others); Tue, 8 Mar 2022 03:55:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238848AbiCHIzZ (ORCPT ); Tue, 8 Mar 2022 03:55:25 -0500 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E25DF2B19D; Tue, 8 Mar 2022 00:54:28 -0800 (PST) Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-2db2add4516so193796647b3.1; Tue, 08 Mar 2022 00:54:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FS0ydfMarLV9kbW6AqtneKVvUqNm/uGFXcWK+i/U9Mw=; b=66I1+dHuIo8mlKOOeHv8Vw/gFvFzjuxO6MeGHpjjfEqUrPVRRxBLnAKCL7dXHBaz8t Jw08XGb3p2HFF3M86DHfI8nheHWZ2/JraA16EOn0YmZPUaq/PtQngk2EgIqjDWA2UOmb B3HrrZjF4H+wgPCS7um38IRsHwuTBlJG/wDRDFmLr/QzUG0+DGHRQYYDIu+P1Fpfjp/c ZqLXP5nNP3jX/mVv/L1+SAF+p6OLgJdgyfmY0SwgOXgiEza4haXpbyXjYrlB7VsGcv2s cbc6P6nmbPof7qQfzS0E4yrYM7REowMZqq9tR0pfMLB/L+3kAp0zl78bcb714DnjDhd4 BxIg== X-Gm-Message-State: AOAM5324UTlwtuLhSJbYMs2B3Ex9QFouD6IItwkh8f+ZaGLanN9IH12q +sPSKIQL5shmksa1qU/vuvbI6A7m8347t/N05Co= X-Received: by 2002:a81:c443:0:b0:2d0:dfa3:9ed9 with SMTP id s3-20020a81c443000000b002d0dfa39ed9mr12067363ywj.220.1646729664636; Tue, 08 Mar 2022 00:54:24 -0800 (PST) MIME-Version: 1.0 References: <20220308081608.3243-1-paskripkin@gmail.com> In-Reply-To: <20220308081608.3243-1-paskripkin@gmail.com> From: Vincent MAILHOL Date: Tue, 8 Mar 2022 17:54:13 +0900 Message-ID: Subject: Re: [PATCH v2] can: mcba_usb: properly check endpoint type To: Pavel Skripkin Cc: yashi@spacecubics.com, wg@grandegger.com, mkl@pengutronix.de, davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+3bc1dce0cc0052d60fde@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 On Tue. 8 Mar 2022 at 17:16, Pavel Skripkin wrote: > Syzbot reported warning in usb_submit_urb() which is caused by wrong > endpoint type. We should check that in endpoint is actually present to > prevent this warning > > Found pipes are now saved to struct mcba_priv and code uses them directly > instead of making pipes in place. > > Fail log: > > usb 5-1: BOGUS urb xfer, pipe 3 != type 1 > WARNING: CPU: 1 PID: 49 at drivers/usb/core/urb.c:502 usb_submit_urb+0xed2/0x18a0 drivers/usb/core/urb.c:502 > Modules linked in: > CPU: 1 PID: 49 Comm: kworker/1:2 Not tainted 5.17.0-rc6-syzkaller-00184-g38f80f42147f #0 > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014 > Workqueue: usb_hub_wq hub_event > RIP: 0010:usb_submit_urb+0xed2/0x18a0 drivers/usb/core/urb.c:502 > ... > Call Trace: > > mcba_usb_start drivers/net/can/usb/mcba_usb.c:662 [inline] > mcba_usb_probe+0x8a3/0xc50 drivers/net/can/usb/mcba_usb.c:858 > usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396 > call_driver_probe drivers/base/dd.c:517 [inline] > > Reported-and-tested-by: syzbot+3bc1dce0cc0052d60fde@syzkaller.appspotmail.com > Fixes: 51f3baad7de9 ("can: mcba_usb: Add support for Microchip CAN BUS Analyzer") > Signed-off-by: Pavel Skripkin > --- > > Changes from RFT(RFC): > - Add missing out pipe check > - Use found pipes instead of making pipes in place > - Do not hide usb_find_common_endpoints() error > > --- > drivers/net/can/usb/mcba_usb.c | 22 +++++++++++++++------- > 1 file changed, 15 insertions(+), 7 deletions(-) > > diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c > index 77bddff86252..91e79a2d5ae5 100644 > --- a/drivers/net/can/usb/mcba_usb.c > +++ b/drivers/net/can/usb/mcba_usb.c > @@ -33,10 +33,6 @@ > #define MCBA_USB_RX_BUFF_SIZE 64 > #define MCBA_USB_TX_BUFF_SIZE (sizeof(struct mcba_usb_msg)) > > -/* MCBA endpoint numbers */ > -#define MCBA_USB_EP_IN 1 > -#define MCBA_USB_EP_OUT 1 > - > /* Microchip command id */ > #define MBCA_CMD_RECEIVE_MESSAGE 0xE3 > #define MBCA_CMD_I_AM_ALIVE_FROM_CAN 0xF5 > @@ -83,6 +79,8 @@ struct mcba_priv { > atomic_t free_ctx_cnt; > void *rxbuf[MCBA_MAX_RX_URBS]; > dma_addr_t rxbuf_dma[MCBA_MAX_RX_URBS]; > + int rx_pipe; > + int tx_pipe; > }; > > /* CAN frame */ > @@ -269,7 +267,7 @@ static netdev_tx_t mcba_usb_xmit(struct mcba_priv *priv, > memcpy(buf, usb_msg, MCBA_USB_TX_BUFF_SIZE); > > usb_fill_bulk_urb(urb, priv->udev, > - usb_sndbulkpipe(priv->udev, MCBA_USB_EP_OUT), buf, > + priv->tx_pipe, buf, Nitpick: you might want to put more arguments per line (up to the 80 characters limit). > MCBA_USB_TX_BUFF_SIZE, mcba_usb_write_bulk_callback, > ctx); > > @@ -608,7 +606,7 @@ static void mcba_usb_read_bulk_callback(struct urb *urb) > resubmit_urb: > > usb_fill_bulk_urb(urb, priv->udev, > - usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_OUT), > + priv->rx_pipe, > urb->transfer_buffer, MCBA_USB_RX_BUFF_SIZE, > mcba_usb_read_bulk_callback, priv); > > @@ -653,7 +651,7 @@ static int mcba_usb_start(struct mcba_priv *priv) > urb->transfer_dma = buf_dma; > > usb_fill_bulk_urb(urb, priv->udev, > - usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_IN), > + priv->rx_pipe, > buf, MCBA_USB_RX_BUFF_SIZE, > mcba_usb_read_bulk_callback, priv); > urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; > @@ -807,6 +805,13 @@ static int mcba_usb_probe(struct usb_interface *intf, > struct mcba_priv *priv; > int err; > struct usb_device *usbdev = interface_to_usbdev(intf); > + struct usb_endpoint_descriptor *in, *out; > + > + err = usb_find_common_endpoints(intf->cur_altsetting, &in, &out, NULL, NULL); > + if (err) { > + dev_err(&intf->dev, "Can't find endpoints\n"); > + return err; > + } > > netdev = alloc_candev(sizeof(struct mcba_priv), MCBA_MAX_TX_URBS); > if (!netdev) { > @@ -852,6 +857,9 @@ static int mcba_usb_probe(struct usb_interface *intf, > goto cleanup_free_candev; > } > > + priv->rx_pipe = usb_rcvbulkpipe(priv->udev, in->bEndpointAddress); > + priv->tx_pipe = usb_sndbulkpipe(priv->udev, out->bEndpointAddress); > + > devm_can_led_init(netdev); > > /* Start USB dev only if we have successfully registered CAN device */ Aside from the nitpick, it looks good to me. Reviewed-by: Vincent Mailhol Yours sincerely, Vincent Mailhol