Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2262527pxp; Mon, 21 Mar 2022 15:16:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcBS1iwH4+gig5xx5DKLyl5MnZIOw8QXRtRhtd095I3BlZWNrHp4BcjehhBOi4wbtipBV4 X-Received: by 2002:a17:90b:3a86:b0:1c6:5971:5980 with SMTP id om6-20020a17090b3a8600b001c659715980mr1400626pjb.68.1647900965989; Mon, 21 Mar 2022 15:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647900965; cv=none; d=google.com; s=arc-20160816; b=EFkkzokx3rrZA3weegGemJ7JQeOCTdNaI4yLQsBbOwTJVajQFPE7K9+89AIvxUfPMG A3u4/jTIOE87hSphQtE1a896kpoWy/4JF1xe59F8qI9R2GsDxxxG4CGdiJsmT1qFmI4e IK9WMD8h4iDa0tIIOQIMf750CtaqbTy99DBMThxkr7xiSY/S+dZJejeG/CoeNN98eH77 5XBLlr9ioQIbkDRu6QRA9GbUbzKdn3dIMoAyZLr6ER5neWsndGBE/mKFgt+Th4BLum1N nRx9ZwfMDSU70KiTMwZHzJtQqoxtoeABk7RtXNh9C7mXIlupV374NzFX6UTZ1stv5MG3 309A== 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=hQ72qmVvnKGMGBTlQPhGv2yTzOMr3naB0EXhQnT67Q0=; b=H9NZcuBiv7Mq+g/VmlGd9PzPtX6woYPhuvFc9SCddBPYEoxa9jeSn0kP3EokI1yLWv l7CXzSSxOHcVZz/y1jUqJd+NAR+eR/pG4v5glkTrQmcx37UnZqWVtpVTQLFWU6I9/YGY wz5cxuAOraslDPVOHXufbfrYk9ygQwtSO1zX/zTCCn80s9KkbmXEo1Aose7KSNL3pG6X kp23CKpFTIyzqcKkgkn5R+6hzPCLekUd45I3DDqm0wOl0aXS2wp6Z8at3aAZI56q6gIC i/2AeA9qdQ7NZKD44BTA2/988e2o5r0C5HUEGM6S4IaENfY1h0HsKvioEFhCz3YvZ6Fd 02Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xS5HMhVB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id x15-20020a63db4f000000b003816043f0e8si13570809pgi.733.2022.03.21.15.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:16:05 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xS5HMhVB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 B91F437B8CF; Mon, 21 Mar 2022 14:35:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242810AbiCUOFS (ORCPT + 99 others); Mon, 21 Mar 2022 10:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349134AbiCUN7U (ORCPT ); Mon, 21 Mar 2022 09:59:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC72BC34; Mon, 21 Mar 2022 06:57:55 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 3FA0E611D5; Mon, 21 Mar 2022 13:57:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BE6CC340E8; Mon, 21 Mar 2022 13:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647871074; bh=B2PwWKJauXDFQuvSQYT/EWCzPk39Vbs2uYKXUVD7pOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xS5HMhVBtD9nxfy03qiSWqnTICjoDP8NJmk6Zm/Q1iqt+3icHv0N4fJclSxxkvvm4 z1bx6NpTJsfKtu7E+8ImxGqhOCihWbwEiM93/baeUWj2pSGmIdJaQdPM9UZZNzr5yu drF+xrT4L6ghZv8Qt8rJG5ITpSjGjqVwkVFMzh/8= 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.4 14/17] usb: usbtmc: Fix bug in pipe direction for control transfers Date: Mon, 21 Mar 2022 14:52:50 +0100 Message-Id: <20220321133217.568942903@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321133217.148831184@linuxfoundation.org> References: <20220321133217.148831184@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 @@ -1889,6 +1889,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)); @@ -1898,12 +1899,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); @@ -1914,8 +1917,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, @@ -1927,7 +1934,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)