• Malte Leip's avatar
    usb: usbip: fix isoc packet num validation in get_pipe · 4123f61e
    Malte Leip authored
    BugLink: https://bugs.launchpad.net/bugs/1830176
    
    commit c409ca3b upstream.
    
    Backport of the upstream commit, which fixed c6688ef9.
    c6688ef9 got backported as commit b6f826ba, as the unavailable
    function usb_endpoint_maxp_mult had to be replaced. The upstream commit
    removed the call to this function, so the backport is straightforward.
    
    Original commit message:
    
    Change the validation of number_of_packets in get_pipe to compare the
    number of packets to a fixed maximum number of packets allowed, set to
    be 1024. This number was chosen due to it being used by other drivers as
    well, for example drivers/usb/host/uhci-q.c
    
    Background/reason:
    The get_pipe function in stub_rx.c validates the number of packets in
    isochronous mode and aborts with an error if that number is too large,
    in order to prevent malicious input from possibly triggering large
    memory allocations. This was previously done by checking whether
    pdu->u.cmd_submit.number_of_packets is bigger than the number of packets
    that would be needed for pdu->u.cmd_submit.transfer_buffer_length bytes
    if all except possibly the last packet had maximum length, given by
    usb_endpoint_maxp(epd) *  usb_endpoint_maxp_mult(epd). This leads to an
    error if URBs with packets shorter than the maximum possible length are
    submitted, which is allowed according to
    Documentation/driver-api/usb/URB.rst and occurs for example with the
    snd-usb-audio driver.
    
    Fixes: b6f826ba ("usbip: fix stub_rx: harden CMD_SUBMIT path to handle malicious input")
    Signed-off-by: default avatarMalte Leip <malte@leip.net>
    Cc: stable <stable@vger.kernel.org> # 4.4.x
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
    Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
    4123f61e
usbip_common.h 10.2 KB