[PATCH] ALSA: FCP: avoid leaking uninitialized heap memory in fcp_ioctl_cmd()
From: Ziheng Wei
Date: Mon Nov 30 2026 - 05:33:41 EST
fcp_ioctl_cmd() allocates the request/response buffer with kmalloc(). If
userspace invokes FCP_IOCTL_CMD with opcode == FCP_USB_REBOOT,
req_size == 0, and resp_size > 0 (up to 4096 bytes), fcp_usb() returns 0
early on -ESHUTDOWN or -EPROTO without writing resp_data, and
fcp_ioctl_cmd() copies uninitialized heap memory back to userspace.
Allocate the buffer with kzalloc() and zero resp_data on the early-return
path in fcp_usb().
Found by LLM-assisted static analysis and compile-tested on x86_64.
Fixes: 46757a3e7d50 ("ALSA: FCP: Add Focusrite Control Protocol driver")
Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>
---
sound/usb/fcp.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/sound/usb/fcp.c b/sound/usb/fcp.c
index 68bb7eabf..34a363d33 100644
--- a/sound/usb/fcp.c
+++ b/sound/usb/fcp.c
@@ -248,8 +248,11 @@ retry:
* reboot request
*/
if (opcode == FCP_USB_REBOOT &&
- (err == -ESHUTDOWN || err == -EPROTO))
+ (err == -ESHUTDOWN || err == -EPROTO)) {
+ if (resp_data && resp_size > 0)
+ memset(resp_data, 0, resp_size);
return 0;
+ }
usb_audio_err(mixer->chip,
"FCP read response %08x failed: %d\n",
@@ -585,7 +588,7 @@ static int fcp_ioctl_cmd(struct usb_mixer_interface *mixer,
buf_size = max(cmd.req_size, cmd.resp_size);
if (buf_size > 0) {
- data = kmalloc(buf_size, GFP_KERNEL);
+ data = kzalloc(buf_size, GFP_KERNEL);
if (!data)
return -ENOMEM;
}
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0