* [v2] usb: xhci: Add error handling in xhci_map_urb_for_dma
@ 2024-02-28 12:57 Prashanth K
2024-02-29 14:15 ` Mathias Nyman
0 siblings, 1 reply; 2+ messages in thread
From: Prashanth K @ 2024-02-28 12:57 UTC (permalink / raw)
To: Greg Kroah-Hartman, Mathias Nyman
Cc: Sergei Shtylyov, linux-kernel, linux-usb, Prashanth K, stable
Currently xhci_map_urb_for_dma() creates a temporary buffer
and copies the SG list to the new linear buffer. But if the
kzalloc_node() fails, then the following sg_pcopy_to_buffer()
can lead to crash since it tries to memcpy to NULL pointer.
So return -ENOMEM if kzalloc returns null pointer.
Cc: <stable@vger.kernel.org> # 5.11
Fixes: 2017a1e58472 ("usb: xhci: Use temporary buffer to consolidate SG")
Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
---
v2: Updated -EAGAIN to -ENOMEM
drivers/usb/host/xhci.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index c057c42c36f4..35e9efdee3b2 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1217,6 +1217,8 @@ static int xhci_map_temp_buffer(struct usb_hcd *hcd, struct urb *urb)
temp = kzalloc_node(buf_len, GFP_ATOMIC,
dev_to_node(hcd->self.sysdev));
+ if (!temp)
+ return -ENOMEM;
if (usb_urb_dir_out(urb))
sg_pcopy_to_buffer(urb->sg, urb->num_sgs,
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [v2] usb: xhci: Add error handling in xhci_map_urb_for_dma
2024-02-28 12:57 [v2] usb: xhci: Add error handling in xhci_map_urb_for_dma Prashanth K
@ 2024-02-29 14:15 ` Mathias Nyman
0 siblings, 0 replies; 2+ messages in thread
From: Mathias Nyman @ 2024-02-29 14:15 UTC (permalink / raw)
To: Prashanth K, Greg Kroah-Hartman, Mathias Nyman
Cc: Sergei Shtylyov, linux-kernel, linux-usb, stable
On 28.2.2024 14.57, Prashanth K wrote:
> Currently xhci_map_urb_for_dma() creates a temporary buffer
> and copies the SG list to the new linear buffer. But if the
> kzalloc_node() fails, then the following sg_pcopy_to_buffer()
> can lead to crash since it tries to memcpy to NULL pointer.
> So return -ENOMEM if kzalloc returns null pointer.
>
> Cc: <stable@vger.kernel.org> # 5.11
> Fixes: 2017a1e58472 ("usb: xhci: Use temporary buffer to consolidate SG")
> Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
> ---
Thanks.
Added
-Mathias
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-29 14:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-28 12:57 [v2] usb: xhci: Add error handling in xhci_map_urb_for_dma Prashanth K
2024-02-29 14:15 ` Mathias Nyman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox