Skip to contentSkip to conversation

usb: gadget: f_eem: use GFP_ATOMIC for echo response buffer

PATCH New Liu Chao 1 participant 1 message Oct 16 USB

lore
Share & tools
lore

Liu Chao

author
#0 lore raw

PATCH 1/1 usb: gadget: f_eem: use GFP_ATOMIC for echo response buffer

eem_unwrap() is invoked from the URB completion callback (rx_complete) in softirq/atomic context. The EEM echo command path allocates the response buffer with kmalloc(skb2->len, GFP_KERNEL), which may sleep and trigger "scheduling while atomic" or a panic. A malicious host can reach this path by sending a bulk OUT transfer carrying an EEM command header with bmEEMCmd=0.

Allocate the echo response buffer with GFP_ATOMIC, consistent with the other allocations in this path (skb_clone, usb_ep_alloc_request, usb_ep_queue). The subsequent ctx allocation has the same problem and is fixed the same way.

---
 drivers/usb/gadget/function/f_eem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/f_eem.c +2 -2
index edbbadad6..b42f25ffb 100644
@@ -455,14 +455,14 @@ static int eem_unwrap(struct gether *port,
 					goto next;
 				}
 
-				req->buf = kmalloc(skb2->len, GFP_KERNEL);
+				req->buf = kmalloc(skb2->len, GFP_ATOMIC);
 				if (!req->buf) {
 					usb_ep_free_request(ep, req);
 					dev_kfree_skb_any(skb2);
 					goto next;
 				}
 
-				ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
+				ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
 				if (!ctx) {
 					kfree(req->buf);
 					usb_ep_free_request(ep, req);

--
2.50.1