mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Liu Chao <liuc63@xiaopeng.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] usb: gadget: f_eem: use GFP_ATOMIC for echo response buffer
Date: Fri, 16 Oct 2026 12:11:47 +0800	[thread overview]
Message-ID: <20261016041147.2293994-1-liuc63@xiaopeng.com> (raw)

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.

Reviewed-by: Guo Zihao <guozh23@xiaopeng.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
---
 drivers/usb/gadget/function/f_eem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/f_eem.c b/drivers/usb/gadget/function/f_eem.c
index edbbadad6..b42f25ffb 100644
--- a/drivers/usb/gadget/function/f_eem.c
+++ b/drivers/usb/gadget/function/f_eem.c
@@ -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


                 reply	other threads:[~2026-10-16  4:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261016041147.2293994-1-liuc63@xiaopeng.com \
    --to=liuc63@xiaopeng.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®