lkml.org 
[lkml]   [2022]   [Jan]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL 5.16 030/217] USB: ehci_brcm_hub_control: Improve port index sanitizing
    Date
    From: Haimin Zhang <tcs.kernel@gmail.com>

    [ Upstream commit 9933698f6119886c110750e67c10ac66f12b730f ]

    Due to (wIndex & 0xff) - 1 can get an integer greater than 15, this
    can cause array index to be out of bounds since the size of array
    port_status is 15. This change prevents a possible out-of-bounds
    pointer computation by forcing the use of a valid port number.

    Reported-by: TCS Robot <tcs_robot@tencent.com>
    Signed-off-by: Haimin Zhang <tcs.kernel@gmail.com>
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Link: https://lore.kernel.org/r/20211113165320.GA59686@rowland.harvard.edu
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    drivers/usb/host/ehci-brcm.c | 6 +++++-
    1 file changed, 5 insertions(+), 1 deletion(-)

    diff --git a/drivers/usb/host/ehci-brcm.c b/drivers/usb/host/ehci-brcm.c
    index d3626bfa966b4..6a0f64c9e5e88 100644
    --- a/drivers/usb/host/ehci-brcm.c
    +++ b/drivers/usb/host/ehci-brcm.c
    @@ -62,8 +62,12 @@ static int ehci_brcm_hub_control(
    u32 __iomem *status_reg;
    unsigned long flags;
    int retval, irq_disabled = 0;
    + u32 temp;

    - status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1];
    + temp = (wIndex & 0xff) - 1;
    + if (temp >= HCS_N_PORTS_MAX) /* Avoid index-out-of-bounds warning */
    + temp = 0;
    + status_reg = &ehci->regs->port_status[temp];

    /*
    * RESUME is cleared when GetPortStatus() is called 20ms after start
    --
    2.34.1
    \
     
     \ /
      Last update: 2022-01-18 03:24    [W:4.127 / U:0.000 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site