Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp628236iog; Mon, 13 Jun 2022 09:26:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjQ2hQFXWyOkvDzICmHMLHrnhhX4qSSTI/9K4I6IkJPbwcyG+RAzc0hmD1gANikRp2+/VQ X-Received: by 2002:a05:6a00:2405:b0:520:6b82:646b with SMTP id z5-20020a056a00240500b005206b82646bmr164720pfh.24.1655137594808; Mon, 13 Jun 2022 09:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655137594; cv=none; d=google.com; s=arc-20160816; b=naGSDiA7L/lyIw0QZAxNEWgm18iH8pqKrKOR3lZl0qP9s138SCBEv2W7hx+nQOMd3j 1JhkT0zt4FYD5Y1zKgB6vMx9zRFnFVvQ5RP7kwHfXE6DiDPjD7KkPQFTLnTvYgWKOVSE 23JhtH1nj1bJuTr1VA1zgeyM1pjJofHcdd1jXJvYDULKcdC/RjDHNpgGwW+Sp3aPLFgV uBoxkA+KwEbcUzOOpLU67TaIVVhTdQZdxKMcO3pdihLKyE2cKPqEGkijmx/vGFkpR2iS C8yi/MGl8qRzKtZyzCjHANO0WwNbQyEE2x2DuwDLgMJgQOjxElksFbaEMtCn46bTIXci pE6w== 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=rG7cMe+XvEfYX/y85hZgzo8vsuWG9mD8Kg16pJcptow=; b=IqMKFKDdTz+yq3JbL86a/Ov9fI4ipIANw0EYggNo0hqWe4DTlE0F1Hs0MFA53npSYx uQbJprTME15StabMOEDAe7rLODCyLNHMV931I4CBOWiwePuyiyTZoUnQiP2IsP+a6VM1 Kl5S7YEJmixcqGZCOeisustJO1GjA/gtvslWG/mgeH8W6hVWJIZb5eRppMaNfQc9UXxJ t0cLGgxU7zn2nBcLFAcrFRyc5zreO2+7sAk7Q3j2qP3pcDbyTuFcH7bNmtnbdJwJYu/U 9/VeNc5M1/q55IhhkJzGrVpSnh6bWspifI5SujRMrXnWnmIeIgGgmKAJpBXznl7Eewwq QR/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=W9iMDrFF; 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 q13-20020a170902dacd00b001622a77631esi11255099plx.594.2022.06.13.09.26.20; Mon, 13 Jun 2022 09:26:34 -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=W9iMDrFF; 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 S1354863AbiFMLgK (ORCPT + 99 others); Mon, 13 Jun 2022 07:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354518AbiFML3k (ORCPT ); Mon, 13 Jun 2022 07:29:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3DDE205D1; Mon, 13 Jun 2022 03:44:56 -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 5BB46B80D3A; Mon, 13 Jun 2022 10:44:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3ED8C34114; Mon, 13 Jun 2022 10:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117094; bh=dgI+xx714YrslaIshqPcqZ88tltimaEP0soGXzXsORA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W9iMDrFFREhQn6ksvrFNYF3f/nZ7os0Dt/whFHpcSZ22U3hAgQ7j3I5AzFPymxINj +g0UPDRkSdfCOvrEjcXqaTTpFqqSKVVuwS0naXW1WyWXf76gq9Au7D+En80Wd/OTiG 5XJAQwf2pfUJde0ZWgmRIRaHT3Za+0GPod/8trkg= 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.4 288/411] usb: usbip: add missing device lock on tweak configuration cmd Date: Mon, 13 Jun 2022 12:09:21 +0200 Message-Id: <20220613094937.394892840@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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 e2b019532234..d3d360ff0d24 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