The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_fs: use __GFP_NOWARN for user-controlled buffer allocation
@ 2026-07-09  9:18 Vasiliy Kovalev
  0 siblings, 0 replies; only message in thread
From: Vasiliy Kovalev @ 2026-07-09  9:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Michal Nazarewicz, linux-usb, linux-kernel, lvc-project, kovalev

ffs_alloc_buffer() passes iov_iter_count() of a userspace read(2) or
write(2) buffer directly to kmalloc() when the UDC does not support
scatter-gather (gadget->sg_supported == false). There is no upper
bound imposed on data_len before it reaches kmalloc().

If a userspace program issues a read/write large enough that the
resulting order exceeds the page allocator's MAX_PAGE_ORDER, kmalloc()
routes to the page allocator which triggers a WARN_ON_ONCE before
returning NULL. The allocation failure is already handled correctly
via -ENOMEM in ffs_epfile_io(), so the WARN carries no additional
diagnostic value. On systems booted with panic_on_warn=1 this WARN
becomes fatal.

Use __GFP_NOWARN so oversized allocations quietly fall back to
-ENOMEM, matching the existing error path.

Found by Linux Verification Center (linuxtesting.org) with Svace static
analysis tool.

Fixes: ddf8abd25994 ("USB: f_fs: the FunctionFS driver")
Cc: stable@vger.kernel.org
Signed-off-by: Vasiliy Kovalev <kovalev@altlinux.org>
---
 drivers/usb/gadget/function/f_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 44218be1e676..e44b441b844b 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -843,7 +843,7 @@ static inline void *ffs_alloc_buffer(struct ffs_io_data *io_data,
 	if (io_data->use_sg)
 		return ffs_build_sg_list(&io_data->sgt, data_len);
 
-	return kmalloc(data_len, GFP_KERNEL);
+	return kmalloc(data_len, GFP_KERNEL | __GFP_NOWARN);
 }
 
 static inline void ffs_free_buffer(struct ffs_io_data *io_data)
-- 
2.50.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-09  9:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-09  9:18 [PATCH] usb: gadget: f_fs: use __GFP_NOWARN for user-controlled buffer allocation Vasiliy Kovalev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox