Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp536525pxb; Wed, 18 Aug 2021 08:05:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4INWEveIhT6Jk2I87ZpLJImBTBiZUcfFEI6+tduDBs/nDvkHAfY7XS4XfrRwX6bMItNP9 X-Received: by 2002:a05:6638:164c:: with SMTP id a12mr8552890jat.49.1629299145029; Wed, 18 Aug 2021 08:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629299145; cv=none; d=google.com; s=arc-20160816; b=KWcc/+bmsFpq0TOWh0CePUlWimcJV7xHhpTQqeYq6ggOauAc99h527iUckJO+TvZbp 6Rq+zvRgaTP0/VdqtjIJLPRcPzJbbps21EWClJ6hngilUzwR4gHsmTbcscDXGe7/k6gc 8Ixcwcrnmv0tQiPcW7eZktvZn1L8Tdqud2/sBwlSstcc19ptgSiod1xsxw+iuhjzacnQ qwjI4wZSAVVgunmoEgObKtJdIJ8QhkZkcArEmeZ4RxowKjPaLubD/SrVphTcN20OcDOd TtOeCTlFMeynIQrqMXN0MEfooM9TpJYAa60SpJl2I/JRtu5MgQYbPTzySdxjrhyJaRSO 8TPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=hPYeR9EzgQYbIrvXMk7e+k5GDYW7Acz7+iZzl2UPLlg=; b=BcaAp8W89bq3oC1+1UNsiX70lA1/cIH7HHS53oJvRN+p4UzN1fYp9gJ1hK0ojYzXUP dyCF6Yps/2zgv/3Mkh6xyctYLMKSjxeAcX3v2f2llpkXT43nzB14tb+Ua7T6swZhfMIA F032IfNgfOkOL2GDIxFIVSIdZ6lbsZsexUHghKhm9IP4W/i7n7H2KF/ZOuhQ4l1vfN/X dEMmjedbBip8V2OTlvXmNw8zQAZuG6Z5es0ha0L3EBVkmnhx7G1v2nqZ8UXiK/sh8Fn0 ix9qCCJth7fRQrFNV6AiAHlj3BBcmgDE8QpfgSMPieBuXqf5m0OhAJqIlB1PzaZIl95Q ePmw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z9si6211461jat.41.2021.08.18.08.05.26; Wed, 18 Aug 2021 08:05:45 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239042AbhHRPDD (ORCPT + 99 others); Wed, 18 Aug 2021 11:03:03 -0400 Received: from netrider.rowland.org ([192.131.102.5]:44443 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S238483AbhHRPDC (ORCPT ); Wed, 18 Aug 2021 11:03:02 -0400 Received: (qmail 196618 invoked by uid 1000); 18 Aug 2021 11:02:27 -0400 Date: Wed, 18 Aug 2021 11:02:27 -0400 From: Alan Stern To: Andy Shevchenko Cc: Kees Cook , Greg Kroah-Hartman , Arnd Bergmann , Al Cooper , linux-usb@vger.kernel.org, Florian Fainelli , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-hardening@vger.kernel.org Subject: Re: [PATCH 1/2] USB: EHCI: Add register array bounds to HCS ports Message-ID: <20210818150227.GE193695@rowland.harvard.edu> References: <20210818043035.1308062-1-keescook@chromium.org> <20210818043035.1308062-2-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 18, 2021 at 12:48:17PM +0300, Andy Shevchenko wrote: > On Wed, Aug 18, 2021 at 7:30 AM Kees Cook wrote: > > > > The original EHCI register struct used a trailing 0-element array for > > addressing the N_PORTS-many available registers. However, after > > commit a46af4ebf9ff ("USB: EHCI: define extension registers like normal ones") > > the 0-element array started to overlap the USBMODE extension register. > > > > To avoid future compile-time warnings about accessing indexes within a > > 0-element array, rearrange the struct to actually describe the expected > > layout (max 15 registers) with a union. All offsets remain the same, and > > bounds checking becomes possible on accesses to port_status and hostpc. > > ... > > > /* HOSTPC: offset 0x84 */ > > - u32 hostpc[0]; /* HOSTPC extension */ > > + u32 hostpc[HCS_N_PORTS_MAX]; > > #define HOSTPC_PHCD (1<<22) /* Phy clock disable */ > > #define HOSTPC_PSPD (3<<25) /* Port speed detection */ > > > > - u32 reserved5[17]; > > + u32 reserved5[2]; > > Shouldn't it be rather [17 - PORT_MAX]? for accuracy? > Or also a union approach? It's okay to use [2] here. The only purpose is to ensure that the following usbmode_ex field is allocated at offset 0xc8; there's no special intrinsic meaning to that 17 value. Alan Stern