Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2289530pxp; Mon, 21 Mar 2022 16:01:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh1f0SBTaldik65EbmO+3TMOJAboo+H+ptcvxd1S/5o4Owtun++vSG0u6jJfcBChEazvRM X-Received: by 2002:a63:3688:0:b0:382:8bf0:aad7 with SMTP id d130-20020a633688000000b003828bf0aad7mr4906129pga.602.1647903686207; Mon, 21 Mar 2022 16:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647903686; cv=none; d=google.com; s=arc-20160816; b=xjmwvyUbXXVxNDlC7HuRzBFPWnhdr3fvGRfVMdie3sE+X+ShFbU4uts8vR1r8W0Tao VJSxhOO4ZKIW1E6UarlJjQksi3pFiao2M+D9fd4WUw5MkM0CUhqliEfBYSx+Stw5N04Y DqPIctpXTqZS058UzQb4fHQ975kEtWIJrgoSz6yEDMkKWkeais5xXhJq2/Qb9/5OO5bS pYGDgOG+6finKemRJ7CKA7+vogF7oMXmv16G0NQiCfCvUPfMQBof7X6kHFJVkHnplQk+ aeXOWxQ1/2wl/shH6oQawWobv+l/Y9u2ZF4bhPDdl8Kx0L+aBg6aK6Vl0QJ1faXAwVfJ 0k1g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Cs7fih+2NAtp0xFF08L/NcPU9BPnyqmghwu/nal0aSs=; b=Ult+ySACMO6amPgGI6mz1AktgsOywWEJAAGpYyVMefXLJzMdwW57QcgwcYx6CwxPyI G0DfpQvQcKvaPyQQvZRnwOMnNibEaLKgO17LrX5UZ2KWpGHjI38cNYfosnvdt+bRBYNg xIo1bYkh97XcGQVx3Ckpm03coax3l2XbGEfPmvp69GuWhMMOY8D3xU/aRPyUg+6LnaA2 iICwccpzRjXW8WZa5b/9wT04mpkvcp1u2c5niKaXjuKp+WTSat/dVJAxTkpfucfU4hpd h2Z4ULRwU2DfoV9N3N3Mtj78Nz+LVvqrz8OBqOWhy1BcBE23yRHH6G/yzhkhhzARQptF I7eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RkyvNdpU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j22-20020a17090a7e9600b001c64d4aebf8si496570pjl.97.2022.03.21.16.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:01:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RkyvNdpU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D08EC404870; Mon, 21 Mar 2022 15:00:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350980AbiCUOKb (ORCPT + 99 others); Mon, 21 Mar 2022 10:10:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349380AbiCUODl (ORCPT ); Mon, 21 Mar 2022 10:03:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D34C17F3FC; Mon, 21 Mar 2022 07:00:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3A63CB816D8; Mon, 21 Mar 2022 14:00:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9934FC340E8; Mon, 21 Mar 2022 14:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647871254; bh=pApDzt38GhzWwzmU3F/B28vg6zW1m34oDcityxP6B0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RkyvNdpUHimIY/MU29JmlDRthgUinRmSTV2gdUbOnQWtwc9D2yeGLLvEKmdEd6fLv 2EOFmxVKTG07Y0fdKbp7nbbPFgPYvUJLA7E4nkma1KQP/yxX6IkMieKiCaPCU+0bdO fr1+VpbmoJ9yZqFtJtV8YfSHQYSctqrTz0PUh8y8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , syzbot+a48e3d1a875240cab5de@syzkaller.appspotmail.com Subject: [PATCH 5.15 28/32] usb: usbtmc: Fix bug in pipe direction for control transfers Date: Mon, 21 Mar 2022 14:53:04 +0100 Message-Id: <20220321133221.375827088@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321133220.559554263@linuxfoundation.org> References: <20220321133220.559554263@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Alan Stern commit e9b667a82cdcfe21d590344447d65daed52b353b upstream. The syzbot fuzzer reported a minor bug in the usbtmc driver: usb 5-1: BOGUS control dir, pipe 80001e80 doesn't match bRequestType 0 WARNING: CPU: 0 PID: 3813 at drivers/usb/core/urb.c:412 usb_submit_urb+0x13a5/0x1970 drivers/usb/core/urb.c:410 Modules linked in: CPU: 0 PID: 3813 Comm: syz-executor122 Not tainted 5.17.0-rc5-syzkaller-00306-g2293be58d6a1 #0 ... Call Trace: usb_start_wait_urb+0x113/0x530 drivers/usb/core/message.c:58 usb_internal_control_msg drivers/usb/core/message.c:102 [inline] usb_control_msg+0x2a5/0x4b0 drivers/usb/core/message.c:153 usbtmc_ioctl_request drivers/usb/class/usbtmc.c:1947 [inline] The problem is that usbtmc_ioctl_request() uses usb_rcvctrlpipe() for all of its transfers, whether they are in or out. It's easy to fix. CC: Reported-and-tested-by: syzbot+a48e3d1a875240cab5de@syzkaller.appspotmail.com Signed-off-by: Alan Stern Link: https://lore.kernel.org/r/YiEsYTPEE6lOCOA5@rowland.harvard.edu Signed-off-by: Greg Kroah-Hartman --- drivers/usb/class/usbtmc.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c @@ -1919,6 +1919,7 @@ static int usbtmc_ioctl_request(struct u struct usbtmc_ctrlrequest request; u8 *buffer = NULL; int rv; + unsigned int is_in, pipe; unsigned long res; res = copy_from_user(&request, arg, sizeof(struct usbtmc_ctrlrequest)); @@ -1928,12 +1929,14 @@ static int usbtmc_ioctl_request(struct u if (request.req.wLength > USBTMC_BUFSIZE) return -EMSGSIZE; + is_in = request.req.bRequestType & USB_DIR_IN; + if (request.req.wLength) { buffer = kmalloc(request.req.wLength, GFP_KERNEL); if (!buffer) return -ENOMEM; - if ((request.req.bRequestType & USB_DIR_IN) == 0) { + if (!is_in) { /* Send control data to device */ res = copy_from_user(buffer, request.data, request.req.wLength); @@ -1944,8 +1947,12 @@ static int usbtmc_ioctl_request(struct u } } + if (is_in) + pipe = usb_rcvctrlpipe(data->usb_dev, 0); + else + pipe = usb_sndctrlpipe(data->usb_dev, 0); rv = usb_control_msg(data->usb_dev, - usb_rcvctrlpipe(data->usb_dev, 0), + pipe, request.req.bRequest, request.req.bRequestType, request.req.wValue, @@ -1957,7 +1964,7 @@ static int usbtmc_ioctl_request(struct u goto exit; } - if (rv && (request.req.bRequestType & USB_DIR_IN)) { + if (rv && is_in) { /* Read control data from device */ res = copy_to_user(request.data, buffer, rv); if (res)