FAILED: patch "[PATCH] ALSA: FCP: do not copy out an uninitialised init response" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 4335e387786479889e6db691fe06d345e52ea536
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090333-knee-unfrozen-751f@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 4335e387786479889e6db691fe06d345e52ea536 Mon Sep 17 00:00:00 2001
From: Baul Lee <[email protected]>
Date: Wed, 5 Aug 2026 10:38:04 +0900
Subject: [PATCH] ALSA: FCP: do not copy out an uninitialised init response
fcp_ioctl_init() allocates its response buffer with kmalloc() and copies the whole buffer back to userspace:
buf_size = init.step0_resp_size + init.step2_resp_size; void *resp __free(kfree) = kmalloc(buf_size, GFP_KERNEL); ... if (copy_to_user(arg->resp, resp, buf_size)) return -EFAULT;
Nothing clears the buffer, and the only writer of its leading step0_resp_size bytes is the step-0 control transfer:
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), FCP_USB_REQ_STEP0, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 0, private->bInterfaceNumber, step0_resp, private->step0_resp_size); if (err < 0) return err;
usb_fill_control_urb() does not set URB_SHORT_NOT_OK, so a short or zero-length data stage completes with status 0 and snd_usb_ctl_msg() returns a small actual_length. The only check is err < 0, so a short transfer is accepted as success.
snd_usb_ctl_msg() copies the full size back unconditionally:
buf = kmemdup(data, size, GFP_KERNEL); ... memcpy(data, buf, size);
Bytes the device never wrote are therefore restored into resp unchanged and copied to userspace. step0_resp_size and step2_resp_size are each validated only to 1..255, so the caller also picks the slab cache, from kmalloc-8 up to kmalloc-512.
On 7.2.0-rc5 (arm64), device answering step 0 with a zero-length data stage, s0 = s2 = 255:
# init_on_alloc off, no spray step0 window [0,255): nonzero=94/255 000: 00 80 60 06 00 00 ff ff 18 00 00 00 57 01 ea 01 010: 08 78 22 13 00 00 ff ff a8 c4 5f 80 00 80 ff ff
# same kernel, kmalloc-512 pre-seeded with an 8-byte tag step0 window [0,255): nonzero=219/255 tagbytes=232
# identical run, init_on_alloc=1 step0 window [0,255): nonzero=0/255 tagbytes=0
# all three runs step2 window [255,510): device words matched=62/62
a8 c4 5f 80 00 80 ff ff is the little-endian kernel text address ffff8000805fc4a8. The step-2 window is unaffected, so the disclosure is exactly the step-0 region.
Zero the buffer, and require the step-0 transfer to deliver the full step0_resp_size bytes so a short data stage is reported as an error.
Discovered by XBOW, triaged by Baul Lee <[email protected]>
sound/usb/fcp.c +3 -1
@@ -486,7 +486,7 @@ static int fcp_ioctl_init(struct usb_mixer_interface *mixer, buf_size = init.step0_resp_size + init.step2_resp_size; void *resp __free(kfree) = -kmalloc (buf_size,GFP_KERNEL ); +kzalloc (buf_size,GFP_KERNEL );if (!resp)return -ENOMEM ;
@@ -1022,6 +1022,8 @@ static int fcp_init(struct usb_mixer_interface *mixer, step0_resp, private->step0_resp_size);if (err <0 )return err; +if (err != private->step0_resp_size) +return -EIO ; err =fcp_init_notify (mixer);if (err <0 )
Sasha Levin
maintainerPATCH 1/2 ALSA: usb-audio: Relax __free() variable declarations
From: Takashi Iwai <[email protected]>
[ Upstream commit 03f705b9ca58b91c6dffe64875ea3d9a38cad9b5 ]
We used to have a variable declaration with __free() initialized with NULL. This was to keep the old coding style rule, but recently it's relaxed and rather recommends to follow the new rule to declare in place of use for __free() -- which avoids potential deadlocks or UAFs with nested cleanups.
Although the current code has no bug, per se, let's follow the new standard and move the declaration to the place of assignment (or directly assign the allocated result) instead of NULL initializations.
Note that there are still a few remaining __free(kfree) with NULL initializations; they are because of the code complexity (the data size calculation).
Stable-dep-of: 4335e3877864 ("ALSA: FCP: do not copy out an uninitialised init response")
--- sound/usb/fcp.c | 36 ++++++++++++++++++------------------ sound/usb/mixer_scarlett2.c | 21 ++++++++++----------- sound/usb/quirks.c | 13 ++++++------- 3 files changed, 34 insertions(+), 36 deletions(-)
sound/usb/fcp.c +18 -18
@@ -187,10 +187,6 @@ static int fcp_usb(struct usb_mixer_interface *mixer, u32 opcode, {struct fcp_data *private = mixer->private_data;struct usb_device *dev = mixer->chip->dev; - struct fcp_usb_packet *req __free(kfree) = NULL; - struct fcp_usb_packet *resp __free(kfree) = NULL; -size_t req_buf_size =struct_size (req, data, req_size); -size_t resp_buf_size =struct_size (resp, data, resp_size);int retries =0 ;const int max_retries =5 ;int err;
@@ -198,10 +194,14 @@ static int fcp_usb(struct usb_mixer_interface *mixer, u32 opcode,if (!private->urb)return -ENODEV ; + struct fcp_usb_packet *req __free(kfree) = NULL; +size_t req_buf_size =struct_size (req, data, req_size); req =kmalloc (req_buf_size,GFP_KERNEL );if (!req)return -ENOMEM ; + struct fcp_usb_packet *resp __free(kfree) = NULL; +size_t resp_buf_size =struct_size (resp, data, resp_size); resp =kmalloc (resp_buf_size,GFP_KERNEL );if (!resp)return -ENOMEM ;
@@ -305,16 +305,17 @@ static int fcp_usb(struct usb_mixer_interface *mixer, u32 opcode,static int fcp_reinit (struct usb_mixer_interface *mixer) {struct fcp_data *private = mixer->private_data; - void *step0_resp __free(kfree) = NULL; - void *step2_resp __free(kfree) = NULL;if (private->urb)return 0 ; - step0_resp =kmalloc (private->step0_resp_size,GFP_KERNEL ); + void *step0_resp __free(kfree) = +kmalloc (private->step0_resp_size,GFP_KERNEL );if (!step0_resp)return -ENOMEM ; - step2_resp =kmalloc (private->step2_resp_size,GFP_KERNEL ); + + void *step2_resp __free(kfree) = +kmalloc (private->step2_resp_size,GFP_KERNEL );if (!step2_resp)return -ENOMEM ;
@@ -472,7 +473,6 @@ static int fcp_ioctl_init(struct usb_mixer_interface *mixer,struct fcp_init init;struct usb_device *dev = mixer->chip->dev;struct fcp_data *private = mixer->private_data; - void *resp __free(kfree) = NULL;void *step2_resp;int err, buf_size;
@@ -493,7 +493,8 @@ static int fcp_ioctl_init(struct usb_mixer_interface *mixer,/* Allocate response buffer */ buf_size = init.step0_resp_size + init.step2_resp_size; - resp =kmalloc (buf_size,GFP_KERNEL ); + void *resp __free(kfree) = +kmalloc (buf_size,GFP_KERNEL );if (!resp)return -ENOMEM ;
@@ -627,7 +628,6 @@ static int fcp_ioctl_set_meter_map(struct usb_mixer_interface *mixer, {struct fcp_meter_map map;struct fcp_data *private = mixer->private_data; - s16 *tmp_map __free(kfree) = NULL;int err;if (copy_from_user (&map, arg,sizeof (map)))
@@ -650,7 +650,8 @@ static int fcp_ioctl_set_meter_map(struct usb_mixer_interface *mixer,return -EINVAL ;/* Allocate and copy the map data */ - tmp_map =memdup_array_user (arg->map, map.map_size,sizeof (s16)); + s16 *tmp_map __free(kfree) = +memdup_array_user (arg->map, map.map_size,sizeof (s16));if (IS_ERR (tmp_map))return PTR_ERR (tmp_map);
@@ -660,17 +661,16 @@ static int fcp_ioctl_set_meter_map(struct usb_mixer_interface *mixer,/* If the control doesn't exist, create it */ if (!private->meter_ctl) { - s16 *new_map __free(kfree) = NULL; - __le32 *meter_levels __free(kfree) = NULL; -/* Allocate buffer for the map */ - new_map =kmalloc_array (map.map_size,sizeof (s16),GFP_KERNEL ); + s16 *new_map __free(kfree) = +kmalloc_array (map.map_size,sizeof (s16),GFP_KERNEL );if (!new_map)return -ENOMEM ;/* Allocate buffer for reading meter levels */ - meter_levels =kmalloc_array (map.meter_slots,sizeof (__le32), -GFP_KERNEL ); + __le32 *meter_levels __free(kfree) = +kmalloc_array (map.meter_slots,sizeof (__le32), +GFP_KERNEL );if (!meter_levels)return -ENOMEM ;
sound/usb/mixer_scarlett2.c +10 -11
@@ -2499,18 +2499,18 @@ static int scarlett2_usb( {struct scarlett2_data *private = mixer->private_data;struct usb_device *dev = mixer->chip->dev; - struct scarlett2_usb_packet *req __free(kfree) = NULL; - struct scarlett2_usb_packet *resp __free(kfree) = NULL; -size_t req_buf_size =struct_size (req, data, req_size); -size_t resp_buf_size =struct_size (resp, data, resp_size);int retries =0 ;const int max_retries =5 ;int err; + struct scarlett2_usb_packet *req __free(kfree) = NULL; +size_t req_buf_size =struct_size (req, data, req_size); req =kmalloc (req_buf_size,GFP_KERNEL );if (!req)return -ENOMEM ; + struct scarlett2_usb_packet *resp __free(kfree) = NULL; +size_t resp_buf_size =struct_size (resp, data, resp_size); resp =kmalloc (resp_buf_size,GFP_KERNEL );if (!resp)return -ENOMEM ;
@@ -4065,9 +4065,9 @@ static int scarlett2_input_select_ctl_info(struct scarlett2_data *private = mixer->private_data;int inputs = private->info->gain_input_count;int i, err; - char **values __free(kfree) = NULL; + char **values __free(kfree) = +kcalloc (inputs,sizeof (char *),GFP_KERNEL ); - values =kcalloc (inputs,sizeof (char *),GFP_KERNEL );if (!values)return -ENOMEM ;
@@ -9293,8 +9293,6 @@ static long scarlett2_hwdep_read(struct snd_hwdep *hw,__le32 len; }__packed req; - u8 *resp __free(kfree) = NULL; -/* Flash segment must first be selected */ if (private->flash_write_state !=SCARLETT2_FLASH_WRITE_STATE_SELECTED )return -EINVAL ;
@@ -9332,7 +9330,8 @@ static long scarlett2_hwdep_read(struct snd_hwdep *hw, req.offset =cpu_to_le32 (*offset); req.len =cpu_to_le32 (count); - resp =kzalloc (count,GFP_KERNEL ); + u8 *resp __free(kfree) = +kzalloc (count,GFP_KERNEL );if (!resp)return -ENOMEM ;
@@ -9480,7 +9479,6 @@ static ssize_t scarlett2_devmap_read( loff_t pos) {struct usb_mixer_interface *mixer = entry->private_data; - u8 *resp_buf __free(kfree) = NULL;const size_t block_size =SCARLETT2_DEVMAP_BLOCK_SIZE ;size_t copied =0 ;
@@ -9490,7 +9488,8 @@ static ssize_t scarlett2_devmap_read(if (pos + count > entry->size) count = entry->size - pos; - resp_buf =kmalloc (block_size,GFP_KERNEL ); + u8 *resp_buf __free(kfree) = +kmalloc (block_size,GFP_KERNEL );if (!resp_buf)return -ENOMEM ;
sound/usb/quirks.c +6 -7
@@ -555,7 +555,6 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip,static int snd_usb_extigy_boot_quirk (struct usb_device *dev,struct usb_interface *intf) {struct usb_host_config *config = dev->actconfig; - struct usb_device_descriptor *new_device_descriptor __free(kfree) = NULL;int err; if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
@@ -566,8 +565,8 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac 0x10, 0x43, 0x0001, 0x000a, NULL, 0);if (err <0 )dev_dbg (&dev->dev,"error sending boot message: %d\n" , err); - - new_device_descriptor =kmalloc (sizeof (*new_device_descriptor),GFP_KERNEL ); + struct usb_device_descriptor *new_device_descriptor __free(kfree) = +kmalloc (sizeof (*new_device_descriptor),GFP_KERNEL );if (!new_device_descriptor)return -ENOMEM ; err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
@@ -910,7 +909,6 @@ static void mbox2_setup_48_24_magic(struct usb_device *dev)static int snd_usb_mbox2_boot_quirk (struct usb_device *dev) {struct usb_host_config *config = dev->actconfig; - struct usb_device_descriptor *new_device_descriptor __free(kfree) = NULL;int err;u8 bootresponse[0x12 ];int fwsize;
@@ -945,7 +943,8 @@ static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)dev_dbg (&dev->dev,"device initialised!\n" ); - new_device_descriptor =kmalloc (sizeof (*new_device_descriptor),GFP_KERNEL ); + struct usb_device_descriptor *new_device_descriptor __free(kfree) = +kmalloc (sizeof (*new_device_descriptor),GFP_KERNEL );if (!new_device_descriptor)return -ENOMEM ;
@@ -1267,7 +1266,6 @@ static void mbox3_setup_defaults(struct usb_device *dev)static int snd_usb_mbox3_boot_quirk (struct usb_device *dev) {struct usb_host_config *config = dev->actconfig; - struct usb_device_descriptor *new_device_descriptor __free(kfree) = NULL;int err;int descriptor_size;
@@ -1280,7 +1278,8 @@ static int snd_usb_mbox3_boot_quirk(struct usb_device *dev)dev_dbg (&dev->dev,"MBOX3: device initialised!\n" ); - new_device_descriptor =kmalloc (sizeof (*new_device_descriptor),GFP_KERNEL ); + struct usb_device_descriptor *new_device_descriptor __free(kfree) = +kmalloc (sizeof (*new_device_descriptor),GFP_KERNEL );if (!new_device_descriptor)return -ENOMEM ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 ALSA: FCP: do not copy out an uninitialised init response
From: Baul Lee <[email protected]>
[ Upstream commit 4335e387786479889e6db691fe06d345e52ea536 ]
fcp_ioctl_init() allocates its response buffer with kmalloc() and copies the whole buffer back to userspace:
buf_size = init.step0_resp_size + init.step2_resp_size; void *resp __free(kfree) = kmalloc(buf_size, GFP_KERNEL); ... if (copy_to_user(arg->resp, resp, buf_size)) return -EFAULT;
Nothing clears the buffer, and the only writer of its leading step0_resp_size bytes is the step-0 control transfer:
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), FCP_USB_REQ_STEP0, USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 0, private->bInterfaceNumber, step0_resp, private->step0_resp_size); if (err < 0) return err;
usb_fill_control_urb() does not set URB_SHORT_NOT_OK, so a short or zero-length data stage completes with status 0 and snd_usb_ctl_msg() returns a small actual_length. The only check is err < 0, so a short transfer is accepted as success.
snd_usb_ctl_msg() copies the full size back unconditionally:
buf = kmemdup(data, size, GFP_KERNEL); ... memcpy(data, buf, size);
Bytes the device never wrote are therefore restored into resp unchanged and copied to userspace. step0_resp_size and step2_resp_size are each validated only to 1..255, so the caller also picks the slab cache, from kmalloc-8 up to kmalloc-512.
On 7.2.0-rc5 (arm64), device answering step 0 with a zero-length data stage, s0 = s2 = 255:
# init_on_alloc off, no spray step0 window [0,255): nonzero=94/255 000: 00 80 60 06 00 00 ff ff 18 00 00 00 57 01 ea 01 010: 08 78 22 13 00 00 ff ff a8 c4 5f 80 00 80 ff ff
# same kernel, kmalloc-512 pre-seeded with an 8-byte tag step0 window [0,255): nonzero=219/255 tagbytes=232
# identical run, init_on_alloc=1 step0 window [0,255): nonzero=0/255 tagbytes=0
# all three runs step2 window [255,510): device words matched=62/62
a8 c4 5f 80 00 80 ff ff is the little-endian kernel text address ffff8000805fc4a8. The step-2 window is unaffected, so the disclosure is exactly the step-0 region.
Zero the buffer, and require the step-0 transfer to deliver the full step0_resp_size bytes so a short data stage is reported as an error.
Discovered by XBOW, triaged by Baul Lee <[email protected]>
--- sound/usb/fcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/usb/fcp.c +3 -1
@@ -494,7 +494,7 @@ static int fcp_ioctl_init(struct usb_mixer_interface *mixer, buf_size = init.step0_resp_size + init.step2_resp_size; void *resp __free(kfree) = -kmalloc (buf_size,GFP_KERNEL ); +kzalloc (buf_size,GFP_KERNEL );if (!resp)return -ENOMEM ;
@@ -1033,6 +1033,8 @@ static int fcp_init(struct usb_mixer_interface *mixer, step0_resp, private->step0_resp_size);if (err <0 )return err; +if (err != private->step0_resp_size) +return -EIO ; err =fcp_init_notify (mixer);if (err <0 )
Signature · 1 line
2.53.0