ALSA: yet a few more fixes for AI bug reports
cover ALSA: yet a few more fixes for AI bug reports
Hi,
here are a few more fixes I've worked quickly for issues Sashiko and other AI reported.
Takashi
===
Takashi Iwai (11):
ALSA: hda: intel: Cancel delayed work at shutdown, too
ALSA: hda: Disable unsol event handling at error and shutdown paths
ALSA: hda: Add lock around codec->registered flag manipulations
ALSA: hda: Add NULL check for the driver pointer at unsol event work
ALSA: caiaq: Register card at the final step
ALSA: caiaq: Fix races at MIDI URB and trigger accesses
ALSA: usb: us16x08: Fix racy accesses of mixer elements
ASoC: fsl_asrc_m2m: Fix bogus compress task pointer assignments
ALSA: line6: Reject too small max packet sizes
ALSA: line6: Fix potential OOB write in line6_capture_copy()
ALSA: line6: Fix handling of zero-length capture packets
sound/hda/common/bind.c | 2 ++ sound/hda/common/codec.c | 5 +++++ sound/hda/controllers/intel.c | 7 ++++++- sound/hda/core/bus.c | 2 +- sound/soc/fsl/fsl_asrc_m2m.c | 2 ++ sound/usb/caiaq/device.c | 13 +++++++------ sound/usb/caiaq/device.h | 3 ++- sound/usb/caiaq/midi.c | 2 ++ sound/usb/line6/capture.c | 3 ++- sound/usb/line6/pcm.c | 10 ++++++++-- sound/usb/line6/playback.c | 4 ++-- sound/usb/mixer_us16x08.c | 16 ++++++++++++++++ 12 files changed, 55 insertions(+), 14 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/11 ALSA: hda: intel: Cancel delayed work at shutdown, too
The shutdown procedure needs to cancel the delayed probe work in case where the probe work stalls or is slow but still possible to reactivated.
--- sound/hda/controllers/intel.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
sound/hda/controllers/intel.c +6 -1
@@ -2484,12 +2484,17 @@ static void azx_remove(struct pci_dev *pci)static void azx_shutdown (struct pci_dev *pci) {struct snd_card *card =pci_get_drvdata (pci); +struct hda_intel *hda;struct azx *chip;if (!card)return ; chip = card->private_data; -if (chip && chip->running) +if (!chip) +return ; + hda = container_of(chip, struct hda_intel, chip); +cancel_delayed_work_sync (&hda->probe_work); +if (chip->running)__azx_shutdown_chip (chip, true); }
Signature · 1 line
2.55.0
PATCH 2/11 ALSA: hda: Disable unsol event handling at error and shutdown paths
In reply to Takashi IwaiWhen the HD-audio controller driver probe fails, it still leaves the unsolicited event handling and jackpoll work active, hence if they are pending, they might fire up later after the resource gets released, which may lead to a UAF. A similar problem may be seen at shutdown, too.
Add the recently added helper to disable unsol events and the cancel of jackpoll_work at the appropriate places.
--- sound/hda/common/bind.c | 2 ++ sound/hda/common/codec.c | 1 + 2 files changed, 3 insertions(+)
sound/hda/common/bind.c +2 -0
@@ -147,6 +147,8 @@ static int hda_codec_driver_probe(struct device *dev)module_put (owner); error: +snd_hdac_device_disable_unsol (&codec->core); +cancel_delayed_work_sync (&codec->jackpoll_work);snd_hda_codec_cleanup_for_unbind (codec); codec->preset =NULL ;return err;
sound/hda/common/codec.c +1 -0
@@ -3039,6 +3039,7 @@ void snd_hda_codec_shutdown(struct hda_codec *codec) codec->jackpoll_interval =0 ;/* don't poll any longer */ cancel_delayed_work_sync (&codec->jackpoll_work); +snd_hdac_device_disable_unsol (&codec->core);list_for_each_entry (cpcm, &codec->pcm_list_head, list)snd_pcm_suspend_all (cpcm->pcm);
Signature · 1 line
2.55.0
PATCH 3/11 ALSA: hda: Add lock around codec->registered flag manipulations
In reply to Takashi IwaiCurrently the places setting or clearing codec->registered flag have no locking, while its reference in the unsol handling work snd_hdac_bus_process_unsol_events() takes the bus->reg_lock lock. Let's add the same bus->reg_lock at the places where codec->registered is set and cleared for avoiding the races.
--- sound/hda/common/codec.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/hda/common/codec.c +4 -0
@@ -761,7 +761,9 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)/* pm_runtime_put() is called in snd_hdac_device_exit() */ pm_runtime_get_noresume (hda_codec_dev (codec));pm_runtime_disable (hda_codec_dev (codec)); +spin_lock_irq (&bus->reg_lock); codec->core.registered = false; +spin_unlock_irq (&bus->reg_lock); }snd_hda_codec_disconnect_pcms (codec);
@@ -815,7 +817,9 @@ void snd_hda_codec_register(struct hda_codec *codec)pm_runtime_enable (hda_codec_dev (codec));/* it was powered up in snd_hda_codec_new(), now all done */ snd_hda_power_down (codec); +spin_lock_irq (&bus->reg_lock); codec->core.registered = true; +spin_unlock_irq (&bus->reg_lock); } }EXPORT_SYMBOL_GPL (snd_hda_codec_register);
Signature · 1 line
2.55.0
kernel test robot
build botRe: [PATCH 03/11] ALSA: hda: Add lock around codec->registered flag manipulations
kernel test robot noticed the following build errors:
Hi Takashi,
kernel test robot noticed the following build errors:
[auto build test ERROR on tiwai-sound/for-next]
[also build test ERROR on next-20261008]
[cannot apply to tiwai-sound/for-linus broonie-sound/for-next linus/master v7.3-rc6] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Takashi-Iwai/ALSA-hda-intel-Cancel-delayed-work-at-shutdown-too/20261008-212541 base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next patch link: https://lore.kernel.org/r/20261008192553.300025-4-tiwai%40suse.de patch subject: [PATCH 03/11] ALSA: hda: Add lock around codec->registered flag manipulations config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20261009/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261009/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
sound/hda/common/codec.c: In function 'snd_hda_codec_cleanup_for_unbind':
>> sound/hda/common/codec.c:764:32: error: 'bus' undeclared (first use in this function)
764 | spin_lock_irq(&bus->reg_lock);
| ^~~
sound/hda/common/codec.c:764:32: note: each undeclared identifier is reported only once for each function it appears in
sound/hda/common/codec.c: In function 'snd_hda_codec_register':
sound/hda/common/codec.c:820:32: error: 'bus' undeclared (first use in this function)
820 | spin_lock_irq(&bus->reg_lock);
| ^~~vim +/bus +764 sound/hda/common/codec.c
753
754 /**
755 * snd_hda_codec_cleanup_for_unbind - Prepare codec for removal
756 * @codec: codec device to cleanup
757 */
758 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
759 {
760 if (codec->core.registered) {
761 /* pm_runtime_put() is called in snd_hdac_device_exit() */
762 pm_runtime_get_noresume(hda_codec_dev(codec));
763 pm_runtime_disable(hda_codec_dev(codec));
> 764 spin_lock_irq(&bus->reg_lock);
765 codec->core.registered = false;
766 spin_unlock_irq(&bus->reg_lock);
767 }
768
769 snd_hda_codec_disconnect_pcms(codec);
770 cancel_delayed_work_sync(&codec->jackpoll_work);
771 if (!codec->in_freeing)
772 snd_hda_ctls_clear(codec);
773 codec_release_pcms(codec);
774 snd_hda_detach_beep_device(codec);
775 snd_hda_jack_tbl_clear(codec);
776 codec->proc_widget_hook = NULL;
777 codec->spec = NULL;
778
779 /* free only driver_pins so that init_pins + user_pins are restored */
780 snd_array_free(&codec->driver_pins);
781 snd_array_free(&codec->cvt_setups);
782 snd_array_free(&codec->spdif_out);
783 snd_array_free(&codec->verbs);
784 codec->follower_dig_outs = NULL;
785 codec->spdif_status_reset = 0;
786 snd_array_free(&codec->mixers);
787 snd_array_free(&codec->nids);
788 remove_conn_list(codec);
789 snd_hdac_regmap_exit(&codec->core);
790 codec->configured = 0;
791 snd_refcount_init(&codec->pcm_ref); /* reset refcount */
792 }
793 EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup_for_unbind);
794
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 03/11] ALSA: hda: Add lock around codec->registered flag manipulations
In reply to Takashi Iwaikernel test robot noticed the following build errors:
Hi Takashi,
kernel test robot noticed the following build errors:
[auto build test ERROR on tiwai-sound/for-next]
[also build test ERROR on next-20261008]
[cannot apply to tiwai-sound/for-linus broonie-sound/for-next linus/master v7.3-rc6] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Takashi-Iwai/ALSA-hda-intel-Cancel-delayed-work-at-shutdown-too/20261008-212541 base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next patch link: https://lore.kernel.org/r/20261008192553.300025-4-tiwai%40suse.de patch subject: [PATCH 03/11] ALSA: hda: Add lock around codec->registered flag manipulations config: i386-defconfig (https://download.01.org/0day-ci/archive/20261009/[email protected]/config) compiler: clang version 22.1.3 (https://github.com/llvm/llvm-project e9846648fd6183ee6d8cbdb4502213fcf902a211) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261009/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> sound/hda/common/codec.c:764:18: error: use of undeclared identifier 'bus'
764 | spin_lock_irq(&bus->reg_lock);
| ^~~
sound/hda/common/codec.c:766:20: error: use of undeclared identifier 'bus'
766 | spin_unlock_irq(&bus->reg_lock);
| ^~~
sound/hda/common/codec.c:820:18: error: use of undeclared identifier 'bus'
820 | spin_lock_irq(&bus->reg_lock);
| ^~~
sound/hda/common/codec.c:822:20: error: use of undeclared identifier 'bus'
822 | spin_unlock_irq(&bus->reg_lock);
| ^~~4 errors generated.
vim +/bus +764 sound/hda/common/codec.c
753
754 /**
755 * snd_hda_codec_cleanup_for_unbind - Prepare codec for removal
756 * @codec: codec device to cleanup
757 */
758 void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
759 {
760 if (codec->core.registered) {
761 /* pm_runtime_put() is called in snd_hdac_device_exit() */
762 pm_runtime_get_noresume(hda_codec_dev(codec));
763 pm_runtime_disable(hda_codec_dev(codec));
> 764 spin_lock_irq(&bus->reg_lock);
765 codec->core.registered = false;
766 spin_unlock_irq(&bus->reg_lock);
767 }
768
769 snd_hda_codec_disconnect_pcms(codec);
770 cancel_delayed_work_sync(&codec->jackpoll_work);
771 if (!codec->in_freeing)
772 snd_hda_ctls_clear(codec);
773 codec_release_pcms(codec);
774 snd_hda_detach_beep_device(codec);
775 snd_hda_jack_tbl_clear(codec);
776 codec->proc_widget_hook = NULL;
777 codec->spec = NULL;
778
779 /* free only driver_pins so that init_pins + user_pins are restored */
780 snd_array_free(&codec->driver_pins);
781 snd_array_free(&codec->cvt_setups);
782 snd_array_free(&codec->spdif_out);
783 snd_array_free(&codec->verbs);
784 codec->follower_dig_outs = NULL;
785 codec->spdif_status_reset = 0;
786 snd_array_free(&codec->mixers);
787 snd_array_free(&codec->nids);
788 remove_conn_list(codec);
789 snd_hdac_regmap_exit(&codec->core);
790 codec->configured = 0;
791 snd_refcount_init(&codec->pcm_ref); /* reset refcount */
792 }
793 EXPORT_SYMBOL_GPL(snd_hda_codec_cleanup_for_unbind);
794
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
PATCH 4/11 ALSA: hda: Add NULL check for the driver pointer at unsol event work
In reply to Takashi Iwaisnd_hdac_bus_process_unsol_events() assumes that the codec driver is always set when it's accessible from the codec table. It's true in general, but in a sheer timing, it might have been already NULLified at the driver unbinding.
As a safety, let's add a NULL check before dereferencing and calling the driver's unsol_event callback.
--- sound/hda/core/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/hda/core/bus.c +1 -1
@@ -184,7 +184,7 @@ static void snd_hdac_bus_process_unsol_events(struct work_struct *work)continue ;spin_unlock_irq (&bus->reg_lock); drv =drv_to_hdac_driver (codec->dev.driver); -if (drv->unsol_event) +if (drv && drv->unsol_event) drv->unsol_event (codec, res);spin_lock_irq (&bus->reg_lock); }
Signature · 1 line
2.55.0
PATCH 5/11 ALSA: caiaq: Register card at the final step
In reply to Takashi Iwaicaiaq driver calls snd_card_register() before creating the mixer elements, which is rather confusing to user-space, as the devices have been published before adding the control elements.
Swap the call order to make the card registration as the final step (as written in the comment).
--- sound/usb/caiaq/device.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
sound/usb/caiaq/device.c +6 -6
@@ -395,6 +395,12 @@ static int setup_card(struct snd_usb_caiaqdev *cdev)return ret; } + ret =snd_usb_caiaq_control_init (cdev); +if (ret <0 ) { +dev_err (dev,"Unable to set up control system (ret=%d)\n" , ret); +return ret; + } +/* finally, register the card and all its sub-instances */ ret =snd_card_register (cdev->chip.card);if (ret <0 ) {
@@ -402,12 +408,6 @@ static int setup_card(struct snd_usb_caiaqdev *cdev)return ret; } - ret =snd_usb_caiaq_control_init (cdev); -if (ret <0 ) { -dev_err (dev,"Unable to set up control system (ret=%d)\n" , ret); -return ret; - } -return 0 ; }
Signature · 1 line
2.55.0
PATCH 6/11 ALSA: caiaq: Fix races at MIDI URB and trigger accesses
In reply to Takashi IwaiURB completion and rawmidi trigger callbacks can race with each other, which may put the state inconsistent, causing double submissions, etc.
Guard both with a new spinlock for avoiding the races.
--- sound/usb/caiaq/device.c | 1 + sound/usb/caiaq/device.h | 3 ++- sound/usb/caiaq/midi.c | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-)
sound/usb/caiaq/device.c +1 -0
@@ -455,6 +455,7 @@ static int create_card(struct usb_device *usb_dev, cdev->chip.usb_id =USB_ID (le16_to_cpu (usb_dev->descriptor.idVendor),le16_to_cpu (usb_dev->descriptor.idProduct));spin_lock_init (&cdev->spinlock); +spin_lock_init (&cdev->midi_lock);mutex_init (&cdev->ep1_out_mutex); *cardp = card;
sound/usb/caiaq/device.h +2 -1
@@ -77,7 +77,8 @@ struct snd_usb_caiaqdev {unsigned char midi_out_buf[EP1_BUFSIZE ];struct caiaq_device_spec spec; -spinlock_t spinlock; +spinlock_t spinlock;/* for PCM audio */ +spinlock_t midi_lock;/* midi_x_stream, midi_out_active */ wait_queue_head_t ep1_wait_queue;wait_queue_head_t prepare_wait_queue;int spec_received, audio_parm_answer;
sound/usb/caiaq/midi.c +2 -0
@@ -79,6 +79,7 @@ static void snd_usb_caiaq_midi_output_trigger(struct snd_rawmidi_substream *subs {struct snd_usb_caiaqdev *cdev = substream->rmidi->private_data; +guard (spinlock_irqsave)(&cdev->midi_lock);if (up) { cdev->midi_out_substream = substream;if (!cdev->midi_out_active)
@@ -151,6 +152,7 @@ void snd_usb_caiaq_midi_output_done(struct urb* urb) {struct snd_usb_caiaqdev *cdev = urb->context; +guard (spinlock_irqsave)(&cdev->midi_lock); cdev->midi_out_active =0 ;if (urb->status !=0 )return ;
Signature · 1 line
2.55.0
PATCH 7/11 ALSA: usb: us16x08: Fix racy accesses of mixer elements
In reply to Takashi IwaiAll get and put callbacks for us16x08 mixer have no proper protection, hence the concurrent accesses to multiple elements may face data races, resulting in unexpected values.
Put the new mixer->lock mutex for protecting the concurrent accesses.
--- sound/usb/mixer_us16x08.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
sound/usb/mixer_us16x08.c +16 -0
@@ -189,6 +189,7 @@ static int snd_us16x08_route_get(struct snd_kcontrol *kcontrol,struct usb_mixer_elem_info *elem =snd_kcontrol_chip (kcontrol);int index = ucontrol->id.index; +guard (mutex)(&elem->head.mixer->lock);/* route has no bias */ ucontrol->value.enumerated.item[0 ] = elem->cache_val[index];
@@ -204,6 +205,7 @@ static int snd_us16x08_route_put(struct snd_kcontrol *kcontrol,char buf[sizeof (route_msg)];int val, val_org, err; +guard (mutex)(&elem->head.mixer->lock);/* get the new value (no bias for routes) */ val = ucontrol->value.enumerated.item[0 ];
@@ -258,6 +260,7 @@ static int snd_us16x08_master_get(struct snd_kcontrol *kcontrol,struct usb_mixer_elem_info *elem =snd_kcontrol_chip (kcontrol);int index = ucontrol->id.index; +guard (mutex)(&elem->head.mixer->lock); ucontrol->value.integer.value[0 ] = elem->cache_val[index];return 0 ;
@@ -272,6 +275,7 @@ static int snd_us16x08_master_put(struct snd_kcontrol *kcontrol,int val, err;int index = ucontrol->id.index; +guard (mutex)(&elem->head.mixer->lock);/* new control value incl. bias*/ val = ucontrol->value.integer.value[0 ];
@@ -310,6 +314,7 @@ static int snd_us16x08_bus_put(struct snd_kcontrol *kcontrol, val = ucontrol->value.integer.value[0 ]; +guard (mutex)(&elem->head.mixer->lock);/* prepare the message buffer from template */ switch (elem->head.id) {case SND_US16X08_ID_BYPASS :
@@ -346,6 +351,7 @@ static int snd_us16x08_bus_get(struct snd_kcontrol *kcontrol, {struct usb_mixer_elem_info *elem =snd_kcontrol_chip (kcontrol); +guard (mutex)(&elem->head.mixer->lock);switch (elem->head.id) {case SND_US16X08_ID_BUSS_OUT : ucontrol->value.integer.value[0 ] = elem->cache_val[0 ];
@@ -368,6 +374,7 @@ static int snd_us16x08_channel_get(struct snd_kcontrol *kcontrol,struct usb_mixer_elem_info *elem =snd_kcontrol_chip (kcontrol);int index = ucontrol->id.index; +guard (mutex)(&elem->head.mixer->lock); ucontrol->value.integer.value[0 ] = elem->cache_val[index];return 0 ;
@@ -382,6 +389,7 @@ static int snd_us16x08_channel_put(struct snd_kcontrol *kcontrol,int val, err;int index = ucontrol->id.index; +guard (mutex)(&elem->head.mixer->lock); val = ucontrol->value.integer.value[0 ];/* sanity check */
@@ -428,6 +436,7 @@ static int snd_us16x08_comp_get(struct snd_kcontrol *kcontrol,int index = ucontrol->id.index;int val_idx =COMP_STORE_IDX (elem->head.id); +guard (mutex)(&elem->head.mixer->lock); ucontrol->value.integer.value[0 ] = store->val[val_idx][index];return 0 ;
@@ -445,6 +454,7 @@ static int snd_us16x08_comp_put(struct snd_kcontrol *kcontrol,int threshold, ratio, attack, release, gain, switch_on;int err; +guard (mutex)(&elem->head.mixer->lock); val = ucontrol->value.integer.value[0 ];/* sanity check */
@@ -521,6 +531,7 @@ static int snd_us16x08_eqswitch_get(struct snd_kcontrol *kcontrol,struct snd_us16x08_eq_store *store = elem->private_data;int index = ucontrol->id.index; +guard (mutex)(&elem->head.mixer->lock);/* get low switch from cache is enough, cause all bands are together */ val = store->val[EQ_STORE_BAND_IDX (elem->head.id)] [EQ_STORE_PARAM_IDX (elem->head.id)][index];
@@ -540,6 +551,7 @@ static int snd_us16x08_eqswitch_put(struct snd_kcontrol *kcontrol,int val, err =0 ;int b_idx; +guard (mutex)(&elem->head.mixer->lock);/* new control value incl. bias*/ val = ucontrol->value.integer.value[0 ] +SND_US16X08_KCBIAS (kcontrol);
@@ -582,6 +594,7 @@ static int snd_us16x08_eq_get(struct snd_kcontrol *kcontrol,int b_idx =EQ_STORE_BAND_IDX (elem->head.id) -1 ;int p_idx =EQ_STORE_PARAM_IDX (elem->head.id); +guard (mutex)(&elem->head.mixer->lock); val = store->val[b_idx][p_idx][index]; ucontrol->value.integer.value[0 ] = val;
@@ -601,6 +614,7 @@ static int snd_us16x08_eq_put(struct snd_kcontrol *kcontrol,int b_idx =EQ_STORE_BAND_IDX (elem->head.id) -1 ;int p_idx =EQ_STORE_PARAM_IDX (elem->head.id); +guard (mutex)(&elem->head.mixer->lock); val = ucontrol->value.integer.value[0 ];/* sanity check */
@@ -729,6 +743,7 @@ static int snd_us16x08_meter_get(struct snd_kcontrol *kcontrol,struct snd_us16x08_meter_store *store = elem->private_data;u8 meter_urb[64 ] = {0 }; +guard (mutex)(&elem->head.mixer->lock);switch (kcontrol->private_value) {case 0 : {char tmp[sizeof (mix_init_msg1)];
@@ -788,6 +803,7 @@ static int snd_us16x08_meter_put(struct snd_kcontrol *kcontrol,struct snd_us16x08_meter_store *store = elem->private_data;int val; +guard (mutex)(&elem->head.mixer->lock); val = ucontrol->value.integer.value[0 ];/* sanity check */
Signature · 1 line
2.55.0
PATCH 8/11 ASoC: fsl_asrc_m2m: Fix bogus compress task pointer assignments
In reply to Takashi IwaiWhen a creation of input or output compress-offload task fails in fsl-asrc driver, the task->input or task->output pointer is left with ERR_PTR(), which is non-NULL. Then it's handled in the compress offload core and it tries to release via dma_buf_put(), resulting in an access to a wrong address.
Clear the bogus pointers properly before returning an error.
--- sound/soc/fsl/fsl_asrc_m2m.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/fsl/fsl_asrc_m2m.c +2 -0
@@ -475,6 +475,7 @@ static int fsl_asrc_m2m_comp_task_create(struct snd_compr_stream *stream, task->input =dma_buf_export (&exp_info_in);if (IS_ERR (task->input)) { ret =PTR_ERR (task->input); + task->input =NULL ;return ret; }
@@ -485,6 +486,7 @@ static int fsl_asrc_m2m_comp_task_create(struct snd_compr_stream *stream, task->output =dma_buf_export (&exp_info_out);if (IS_ERR (task->output)) { ret =PTR_ERR (task->output); + task->output =NULL ;return ret; }
Signature · 1 line
2.55.0
PATCH 9/11 ALSA: line6: Reject too small max packet sizes
In reply to Takashi IwaiAlthough the LINE6 driver has a sanity check for the given max packet sizes, it still has an implicit requirement of the minimal size being bytes-per-frame; e.g. the impulse test signal assuming the fixed size, and when a too small size is specified by a malformed USB descriptor, this may lead to an OOB access.
Change the sanity check conditions to reject too small max packet sizes for avoiding the scenario above.
--- sound/usb/line6/pcm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
sound/usb/line6/pcm.c +5 -1
@@ -554,7 +554,11 @@ int line6_init_pcm(struct usb_line6 *line6, line6pcm->max_packet_size_out =usb_maxpacket (line6->usbdev,usb_sndisocpipe (line6->usbdev, ep_write)); -if (!line6pcm->max_packet_size_in || !line6pcm->max_packet_size_out) { +/* reject max packet sizes smaller than bytes-per-frame; +* (the magic number 6 is taken from the playback case) +*/ +if (line6pcm->max_packet_size_in <6 || + line6pcm->max_packet_size_out <6 ) {dev_err (line6pcm->line6->ifcdev,"cannot get proper max packet size\n" );return -EINVAL ;
Signature · 1 line
2.55.0
PATCH 10/11 ALSA: line6: Fix potential OOB write in line6_capture_copy()
In reply to Takashi Iwailine6_capture_copy() copies the data for the original byte size, but the buffer overwrap is checked against the frame size. Because of it, when the data size isn't aligned in frames, the remaining bytes might be still copied above the buffer size.
For avoiding the potential OOB write, correct the copied data size in line6_capture_copy() to be aligned with frames.
--- sound/usb/line6/capture.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/usb/line6/capture.c +2 -1
@@ -117,7 +117,8 @@ void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize) }else {/* copy single chunk */ memcpy (runtime->dma_area + - line6pcm->in.pos_done * bytes_per_frame, fbuf, fsize); + line6pcm->in.pos_done * bytes_per_frame, fbuf, + frames * bytes_per_frame); } line6pcm->in.pos_done += frames;
Signature · 1 line
2.55.0
PATCH 11/11 ALSA: line6: Fix handling of zero-length capture packets
In reply to Takashi IwaiThe LINE6 playback engine assumes that line6pcm->prev_fsize=0 indicates that there was no input packet to be processed, and synthesizes the frames. But, when a capture stream receives a zero-length (or a very small size) packet, it sets 0 to prev_fsize, while playback engine still believes it's for synthesis, hence it tries to copy the larger data than the actual input data.
As prev_fsize=0 can't be a good indication for "no input", change the meaning slightly: now prev_fsize=-1 means no input, while prev_fsize=0 means it's a zero-length packet.
--- sound/usb/line6/pcm.c | 4 +++- sound/usb/line6/playback.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-)
sound/usb/line6/pcm.c +3 -1
@@ -217,7 +217,7 @@ static void line6_stream_stop(struct snd_line6_pcm *line6pcm, int direction,if (direction ==SNDRV_PCM_STREAM_CAPTURE ) {guard (spinlock_irqsave)(&pstr->lock); line6pcm->prev_fbuf =NULL ; - line6pcm->prev_fsize =0 ; + line6pcm->prev_fsize =-1 ; } }
@@ -538,6 +538,8 @@ int line6_init_pcm(struct usb_line6 *line6, line6pcm->volume_playback[0 ] = line6pcm->volume_playback[1 ] =255 ; line6pcm->volume_monitor =255 ; line6pcm->line6 = line6; + line6pcm->prev_fbuf =NULL ; + line6pcm->prev_fsize =-1 ;spin_lock_init (&line6pcm->out.lock);spin_lock_init (&line6pcm->in.lock);
sound/usb/line6/playback.c +2 -2
@@ -171,7 +171,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) &urb_out->iso_frame_desc[i]; fsize = line6pcm->prev_fsize; -if (fsize ==0 ) { +if (fsize ==-1 ) {int n; line6pcm->out.count += frame_increment;
@@ -271,7 +271,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) bytes_per_frame); } line6pcm->prev_fbuf =NULL ; - line6pcm->prev_fsize =0 ; + line6pcm->prev_fsize =-1 ; }spin_unlock (&line6pcm->in.lock);
Signature · 1 line
2.55.0