Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2651236pxj; Mon, 14 Jun 2021 04:04:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKhfbwER8M4Hh7K5uLWTXuFs+119roKk0MxlV3DFhsGuJ3m8uSux8rbOopmZB5v47exxxG X-Received: by 2002:a05:6402:1771:: with SMTP id da17mr16112214edb.31.1623668669496; Mon, 14 Jun 2021 04:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623668669; cv=none; d=google.com; s=arc-20160816; b=Sgd6PyaE48+2NwvRJaGrVF8TIgAFrbOZa17voOiWGP8GR6ODYKPoM5D+Mqoozurqse W4Xk+oApWYyCBh1Iz5xMVUfgiMUAjlPKOfRc2sA9pkeDvgB3e6ZXwRIwkdDikM0m+mLB dyJiOeMPlqmFHnkWV/tPW6RYTEc+ODkPFGAO1Fo05r2OnY3Dh4heQA8Lxolp5WfNxSVC aNzKrdfadLUNY6U0rtIXCz6oWXv1/H3LMbOG+Wi/aG0d4dgirMNCuIWutA9TO1RZXM5a Y1Qrl3zHKvaGlkanRF+iOCjunIueeoXufcoYMsmuWWpYkoosQ2XNP8mS2lrkzQ0P8TUW f3xQ== 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=K20r+yLQji6tYWPIKTaSWQ/y9f3xnTed1K6miqeVpEU=; b=w+vO8XOP9pl319/oLsYkSVzMFzGyGwToi14pe4ntMLHyRLEJOY3zdB222agVz5YzBI y2H5NU9xAz9+fT6eUSXCk2gLjzh34imKQUL+vD9WFiVqofjBzE4mrwPrnSdkAc1pbhQ9 3KOTlTrQMKiFoQsOZxHiSDvhH8uYbKXmc88MXYst8I/iKaCKK8P8BTENM8b9D2wTCLgL IJghGvTSUWWeFjw/jcIgwT3WYvvq8YVmOHzm/YJ4iHvHeULDcBY8XhKUTWw4t55AZke9 nU8W7RwJZSMssz1PLQUdpx00iy6mIJY2My61M/t1EtVXpSLLKk3SYBhb2BOHlAhSLuGr Lm0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rbo0PxC8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i16si11683158ejo.417.2021.06.14.04.04.07; Mon, 14 Jun 2021 04:04:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rbo0PxC8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235217AbhFNLFM (ORCPT + 99 others); Mon, 14 Jun 2021 07:05:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:59282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234012AbhFNKzp (ORCPT ); Mon, 14 Jun 2021 06:55:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1066461584; Mon, 14 Jun 2021 10:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667256; bh=0PEOkMy6BleViziz664TLBeeJPhIJrUK18ritYu7c/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rbo0PxC8+tX1KuQY/Q9wfB1RgJMQE5VnUDBjkUUeVwwDiFkwaGaoW8It6MMlghwdV msdYs1b/jz34lFtXwYA07nbNtueUhXxdvqwygPEv54VlG96zuP9lonfduDKxdSO74g 02o9igil3iH+yBiqhyamnOoQs2WBLggZmIgQBSmU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Felipe Balbi , =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Subject: [PATCH 5.4 61/84] usb: fix various gadget panics on 10gbps cabling Date: Mon, 14 Jun 2021 12:27:39 +0200 Message-Id: <20210614102648.454109883@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102646.341387537@linuxfoundation.org> References: <20210614102646.341387537@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maciej Żenczykowski commit 032e288097a553db5653af552dd8035cd2a0ba96 upstream. usb_assign_descriptors() is called with 5 parameters, the last 4 of which are the usb_descriptor_header for: full-speed (USB1.1 - 12Mbps [including USB1.0 low-speed @ 1.5Mbps), high-speed (USB2.0 - 480Mbps), super-speed (USB3.0 - 5Gbps), super-speed-plus (USB3.1 - 10Gbps). The differences between full/high/super-speed descriptors are usually substantial (due to changes in the maximum usb block size from 64 to 512 to 1024 bytes and other differences in the specs), while the difference between 5 and 10Gbps descriptors may be as little as nothing (in many cases the same tuning is simply good enough). However if a gadget driver calls usb_assign_descriptors() with a NULL descriptor for super-speed-plus and is then used on a max 10gbps configuration, the kernel will crash with a null pointer dereference, when a 10gbps capable device port + cable + host port combination shows up. (This wouldn't happen if the gadget max-speed was set to 5gbps, but it of course defaults to the maximum, and there's no real reason to artificially limit it) The fix is to simply use the 5gbps descriptor as the 10gbps descriptor, if a 10gbps descriptor wasn't provided. Obviously this won't fix the problem if the 5gbps descriptor is also NULL, but such cases can't be so trivially solved (and any such gadgets are unlikely to be used with USB3 ports any way). Cc: Felipe Balbi Cc: Greg Kroah-Hartman Signed-off-by: Maciej Żenczykowski Cc: stable Link: https://lore.kernel.org/r/20210609024459.1126080-1-zenczykowski@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/config.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/usb/gadget/config.c +++ b/drivers/usb/gadget/config.c @@ -164,6 +164,14 @@ int usb_assign_descriptors(struct usb_fu { struct usb_gadget *g = f->config->cdev->gadget; + /* super-speed-plus descriptor falls back to super-speed one, + * if such a descriptor was provided, thus avoiding a NULL + * pointer dereference if a 5gbps capable gadget is used with + * a 10gbps capable config (device port + cable + host port) + */ + if (!ssp) + ssp = ss; + if (fs) { f->fs_descriptors = usb_copy_descriptors(fs); if (!f->fs_descriptors)