Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2075601rwb; Sun, 6 Aug 2023 09:13:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSK/0mj3HigWL2m9OP9amuPO/M8Pe7bI60jhAiGIgdFiYVpFlEaWPJK++eCFALBWlXfCX+ X-Received: by 2002:a05:6512:2827:b0:4fb:8bad:1cdf with SMTP id cf39-20020a056512282700b004fb8bad1cdfmr6056021lfb.42.1691338389881; Sun, 06 Aug 2023 09:13:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691338389; cv=none; d=google.com; s=arc-20160816; b=XQObZmsbuATA8yqeHMcbGhBtzHdP67OmDZvF45elVkE5ZljAGwRTT9N8l5Zp3Uv8Qt /PLyAaF3jWnW8/AULB7XK465sXM6ZSRBzL32jl0YVyC19TTDgRh14OsLPzDUKgmQR3AR qZaiDapbYuBQuiyZa01ay1m9fY9RFfUI9AogkvBuzr3B3J9xDK26CIcAAyfocvpDkWs7 7DupUTzdJ1vVx341XquUFRfFR01MUl36bj+o4JEvEUulplyQbMlwfFD5VP6d3jkO2XLA ZYqqL8n2lZUuCTJ/RYbhtwK1vk359qNGJliYsU9p6LOYPf1RQkKJXYmAu/c9SHtH0PuJ Fa6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+heVtwJaqVhvdeND+/kYfxQrnIX9TY3ZkqZQHOrb6tM=; fh=7a+0LTgZ5582M+DLyvzsl5pgzDnXWUY7jbNzy/lXiW0=; b=dh1NVlLU6VRqKGgd4oQsY7G3vHXgq/gkuMRVIK5WDxVcW8Hyj7pw/E7Vs6zzpZeEIX pU5lttNhjjIRqpFu2EdRp47NKXLUJje0QgkT5sdk5QDSdljYYIQkcZiHrw3Gf3MMq02S ui4aTpPM4lo4j2FX+tlf/0wUL9bXBygdBsZp3gOrvfEVEDYQvduN3jeOZgJ7VDv8Ioxw pCrnyOzs4JDBpeG6qejjHIl5/G1yktyRUJqcYVEr27cVSqcT6mArcAZyBLm9R9uuFSAt ohgF+uqw2FzBoryqTXbdRmd34mPWEt3hjHbrE1tvf2xb90z4eZr7ow8xUz/wo5oNd9Bm ojqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hOhrseXD; 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 i3-20020aa7dd03000000b00521656f855dsi811024edv.110.2023.08.06.09.12.46; Sun, 06 Aug 2023 09:13:09 -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=hOhrseXD; 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 S230377AbjHFO1d (ORCPT + 99 others); Sun, 6 Aug 2023 10:27:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjHFO1c (ORCPT ); Sun, 6 Aug 2023 10:27:32 -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 285DDE49; Sun, 6 Aug 2023 07:27:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A21BB6117F; Sun, 6 Aug 2023 14:27:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD045C433C8; Sun, 6 Aug 2023 14:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1691332050; bh=k7Wz5My+7y3gVES1fFNpSuU/X31s8HmopFxP7aidXy4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hOhrseXDh8smzJLqzn5JMnrQ1JlOrcR/7m0rx32YCV/jfEvBxLxJLP26t1eKCCm3R ap5kt7nu01tatM0i4du1IW4yIO5zzSbWCbw/P3AeRJFfoWY6xllJF11Oww2hvBdgX4 MpqQ8p53clg9JYy89ix1047wMe9DLCjm4wX+hQWs= Date: Sun, 6 Aug 2023 16:27:27 +0200 From: Greg KH To: Zhang Shurong Cc: jgross@suse.com, xen-devel@lists.xenproject.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xen: fix potential shift out-of-bounds in xenhcd_hub_control() Message-ID: <2023080659-turban-exemption-1196@gregkh> References: <2023062628-shame-ebook-56f2@gregkh> <4825193.GXAFRqVoOG@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 On Sun, Aug 06, 2023 at 10:11:43PM +0800, Zhang Shurong wrote: > 在 2023年7月1日星期六 CST 下午11:51:43,Zhang Shurong 写道: > > 在 2023年6月26日星期一 CST 下午1:52:02,您写道: > > > > > On Mon, Jun 26, 2023 at 07:48:05AM +0200, Jan Beulich wrote: > > > > On 25.06.2023 18:42, Zhang Shurong wrote: > > > > > --- a/drivers/usb/host/xen-hcd.c > > > > > +++ b/drivers/usb/host/xen-hcd.c > > > > > @@ -456,6 +456,8 @@ static int xenhcd_hub_control(struct usb_hcd *hcd, > > > > > __u16 typeReq, __u16 wValue,> > > > > > > > > > > > info->ports[wIndex - 1].c_connection = > > > > false; > > > > > > > fallthrough; > > > > > > > > > > default: > > > > > + if (wValue >= 32) > > > > > + goto error; > > > > > > > > > > info->ports[wIndex - 1].status &= ~(1 > > > > << wValue); > > > > > > Even 31 is out of bounds (as in: UB) as long as it's 1 here rather > > > > than 1u. > > > > > > Why isn't the caller fixed so this type of value could never be passed > > > to the hub_control callback? > > > > > > thanks, > > > > > > greg k-h > > > > Although I'm not knowledgeable about the USB subsystem, I've observed that > > not all driver code that implements hub_control callback performs a shift > > operation on wValue, and not all shift operations among them cause > > problems. Therefore, I've decided to fix this issue within each driver > > itself. > > > > For example, in r8a66597_hub_control, it will first check whether wValue is > > valid (always < 31) before the shift operation. In case of an invalid > > number, the code would execute the error branch instead of the shift > > operation. > > > > switch (wValue) { > > case USB_PORT_FEAT_ENABLE: > > rh->port &= ~USB_PORT_STAT_POWER; > > break; > > case USB_PORT_FEAT_SUSPEND: > > break; > > case USB_PORT_FEAT_POWER: > > r8a66597_port_power(r8a66597, port, 0); > > break; > > case USB_PORT_FEAT_C_ENABLE: > > case USB_PORT_FEAT_C_SUSPEND: > > case USB_PORT_FEAT_C_CONNECTION: > > case USB_PORT_FEAT_C_OVER_CURRENT: > > case USB_PORT_FEAT_C_RESET: > > break; > > default: > > goto error; > > } > > rh->port &= ~(1 << wValue); > > Hi there. I apologize for reaching out once more. I'm feeling a bit puzzled > about what my next step should be. I'm unsure whether I should rewrite this > patch or attempt to address the issue at the caller level. Try addressing it at the caller level first please. If that somehow does not work, then we will take a patch series that fixes all of the host controller drivers at once. thanks, greg k-h