Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp589296iog; Mon, 13 Jun 2022 08:41:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKL6bDhusUDIhXm1FCbiN28xkuAhlFkSSgV/ju+n+h0SxoOltk8/tgwPrfttTLSptrspGY X-Received: by 2002:a63:b55:0:b0:3fd:a384:bd10 with SMTP id a21-20020a630b55000000b003fda384bd10mr203466pgl.534.1655134916475; Mon, 13 Jun 2022 08:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134916; cv=none; d=google.com; s=arc-20160816; b=Io9LFcyiigaLDmGNZK6XW92afCSoVhTozd2Zj0yLWXEAU2Gr6pd3QaBKPBKChi4ITZ v/a/7pUTK0f8k5bNgwhV32bQfKZaqxz8xwQZkK1gaCtZ2CXhGl6wZiAFx/mB4pkBVcOB nX/5PVQmYq17I25c6gdjvcIEdgCZLG+mRhWhm9p2qLCWf4+ruyU8cAJ9R5jzt2wEFbZg w1f/A+uqZuwvZAIUXI1BWCDBSqoZKmMclVTjxf88gR5GU/tSx/oPcOHRAPcbyiFhAmd1 hYahHSho1UOoSRsA+mgNjtnqfeibnxg3AfPVpKglS11LPcxEVtz7ul8rjBvMDItCE3RW n62Q== 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=n19CVWhhHJbRSEDiJmj7B1Jwvp7+9jaga/wsMGUPeEU=; b=emC8LfOY9+qp84WuOaKs2kZ+Gt7YBM5VUmhXCb8R75jkHX5/yCEyP79qODeyh4ziz7 hI0AxktB9sRYzQCWCa7v/XF4VWNiqA4bvjLcRppLjJNG11qmZwsyktygUfa4Db1vG/Zo VPFRcVS7pZ+j5mfOoT/yBvayar5IgLPUPyVQPyRbUvcZ+zDK7oh2Csx77klA23qGkQaA U2/cEJZXbZLe5n4hCCum9fZRJ5G29Vo/5rFQF5j6v8WrGjtoU2VhVvJXeKnwJgQIt+z5 ilfPJa2qvTD1rsiqlWxk0XtcaiPnAScqN+F13BN0NxNT1cthI1MLg7BR2HGSUZvUuzbP NLVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JwMdFRrn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j6-20020a62b606000000b0050fac0168c6si8201373pff.49.2022.06.13.08.41.43; Mon, 13 Jun 2022 08:41:56 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JwMdFRrn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354969AbiFMMzM (ORCPT + 99 others); Mon, 13 Jun 2022 08:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354733AbiFMMwq (ORCPT ); Mon, 13 Jun 2022 08:52:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7579162EC; Mon, 13 Jun 2022 04:12:36 -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 BBDC9B80EB2; Mon, 13 Jun 2022 11:12:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B062C3411C; Mon, 13 Jun 2022 11:12:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655118746; bh=pl/Mo2zTG3iyAG3IF2rzNQ79wq94PhZgwe/irXGYYwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JwMdFRrnd4GBEWofFgXXHN2fRC2PeZqcrZeD5JUhtsFWeXOAMRyjz5ej054iNyGNw zliDyEFy6luD8e1w94Unvtub8bKr3pNUxB/bfVjqw9yXFKegJb0wMQYg5fW8sAZeJ5 24LeOEJEhOz28V96MJNlUZknUsZ5uSjHF9Rw20Lo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuah Khan , Niels Dossche , Sasha Levin Subject: [PATCH 5.15 013/247] usb: usbip: add missing device lock on tweak configuration cmd Date: Mon, 13 Jun 2022 12:08:35 +0200 Message-Id: <20220613094923.327418442@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@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=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Niels Dossche [ Upstream commit d088fabace2ca337b275d1d4b36db4fe7771e44f ] The function documentation of usb_set_configuration says that its callers should hold the device lock. This lock is held for all callsites except tweak_set_configuration_cmd. The code path can be executed for example when attaching a remote USB device. The solution is to surround the call by the device lock. This bug was found using my experimental own-developed static analysis tool, which reported the missing lock on v5.17.2. I manually verified this bug report by doing code review as well. I runtime checked that the required lock is not held. I compiled and runtime tested this on x86_64 with a USB mouse. After applying this patch, my analyser no longer reports this potential bug. Fixes: 2c8c98158946 ("staging: usbip: let client choose device configuration") Reviewed-by: Shuah Khan Signed-off-by: Niels Dossche Link: https://lore.kernel.org/r/20220412165055.257113-1-dossche.niels@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/usbip/stub_rx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/usbip/stub_rx.c b/drivers/usb/usbip/stub_rx.c index 325c22008e53..5dd41e8215e0 100644 --- a/drivers/usb/usbip/stub_rx.c +++ b/drivers/usb/usbip/stub_rx.c @@ -138,7 +138,9 @@ static int tweak_set_configuration_cmd(struct urb *urb) req = (struct usb_ctrlrequest *) urb->setup_packet; config = le16_to_cpu(req->wValue); + usb_lock_device(sdev->udev); err = usb_set_configuration(sdev->udev, config); + usb_unlock_device(sdev->udev); if (err && err != -ENODEV) dev_err(&sdev->udev->dev, "can't set config #%d, error %d\n", config, err); -- 2.35.1