linux/sound
Nathan Chancellor 72165c867f ALSA: hwdep: Move put_user() call out of scoped_guard() in snd_hwdep_control_ioctl()
Clang prior to 17.0.0 has a bug in its asm goto jump scope analysis to
determine that no variables with the cleanup attribute are skipped by an
indirect jump. Instead of only checking the scope of each label that is
a possible target of each asm goto statement, it checks the scope of
every label, which can cause an error when a variable with the cleanup
attribute is used between two asm goto statements with different scopes,
even if they have completely different label targets:

  sound/core/hwdep.c:273:8: error: cannot jump from this asm goto statement to one of its possible targets
                          if (get_user(device, (int __user *)arg))
                              ^
  arch/powerpc/include/asm/uaccess.h:295:5: note: expanded from macro 'get_user'
                    __get_user(x, _gu_addr) :                             \
                    ^
  arch/powerpc/include/asm/uaccess.h:283:2: note: expanded from macro '__get_user'
          __get_user_size_allowed(__gu_val, __gu_addr, __gu_size, __gu_err);      \
          ^
  arch/powerpc/include/asm/uaccess.h:199:3: note: expanded from macro '__get_user_size_allowed'
                  __get_user_size_goto(x, ptr, size, __gus_failed);       \
                  ^
  arch/powerpc/include/asm/uaccess.h:187:10: note: expanded from macro '__get_user_size_goto'
          case 1: __get_user_asm_goto(x, (u8 __user *)ptr, label, "lbz"); break;  \
                  ^
  arch/powerpc/include/asm/uaccess.h:158:2: note: expanded from macro '__get_user_asm_goto'
          asm_volatile_goto(                                      \
          ^
  include/linux/compiler_types.h:366:33: note: expanded from macro 'asm_volatile_goto'
  #define asm_volatile_goto(x...) asm goto(x)
                                  ^
  sound/core/hwdep.c:291:9: note: possible target of asm goto statement
                                  if (put_user(device, (int __user *)arg))
                                      ^
  arch/powerpc/include/asm/uaccess.h:66:5: note: expanded from macro 'put_user'
                    __put_user(x, _pu_addr) : -EFAULT;                    \
                    ^
  arch/powerpc/include/asm/uaccess.h:52:9: note: expanded from macro '__put_user'
                                                                  \
                                                                  ^
  sound/core/hwdep.c:276:4: note: jump bypasses initialization of variable with __attribute__((cleanup))
                          scoped_guard(mutex, &register_mutex) {
                          ^
  include/linux/cleanup.h:169:20: note: expanded from macro 'scoped_guard'
          for (CLASS(_name, scope)(args),                                 \

To avoid this issue, move the put_user() call out of the scoped_guard()
scope, which allows the asm goto scope analysis to see that the variable
with the cleanup attribute will never be skipped by the asm goto
statements.

There should be no functional change because prior to the refactoring,
put_user() was not called under register_mutex, so this call does not
even need to be in the scoped_guard() in the first place.

Fixes: e6684d08cc ("ALSA: hwdep: Use guard() for locking")
Closes: https://github.com/ClangBuiltLinux/linux/issues/2003
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/r/20240301-fix-snd-hwdep-guard-v1-1-6aab033f3f83@kernel.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2024-03-01 18:10:57 +01:00
..
ac97 ALSA: ac97: fix build regression 2024-01-03 11:47:04 +01:00
aoa ALSA: aoa: make soundbus_bus_type const 2024-02-15 13:48:03 +01:00
arm ALSA: pxa2xx-ac97: Replace with DEFINE_SIMPLE_DEV_PM_OPS() 2024-02-12 11:50:25 +01:00
atmel
core ALSA: hwdep: Move put_user() call out of scoped_guard() in snd_hwdep_control_ioctl() 2024-03-01 18:10:57 +01:00
drivers ALSA: pcsp: Replace with DEFINE_SIMPLE_DEV_PM_OPS() 2024-02-12 11:50:24 +01:00
firewire Merge branch 'for-linus' into for-next 2024-02-21 11:17:06 +01:00
hda ALSA: hda: Downgrade BDL table overflow message 2024-02-21 11:14:16 +01:00
i2c
isa
mips
oss
parisc
pci ALSA: hda: beep: Drop stale mutex 2024-02-22 17:26:53 +01:00
pcmcia
ppc
sh
soc Merge branch 'for-linus' into for-next 2024-02-15 16:57:37 +01:00
sparc
spi ALSA: at73c213: Replace with DEFINE_SIMPLE_DEV_PM_OPS() 2024-02-12 11:50:25 +01:00
synth ALSA: synth: Save a few bytes of memory when registering a 'snd_emux' 2024-01-22 13:04:22 +01:00
usb ALSA: usb-audio: More relaxed check of MIDI jack names 2024-02-15 16:56:05 +01:00
virtio ALSA: virtio: Fix "Coverity: virtsnd_kctl_tlv_op(): Uninitialized variables" warning. 2024-02-16 15:01:31 +01:00
x86
xen
ac97_bus.c ALSA: mark all struct bus_type as const 2023-12-30 10:10:41 +01:00
Kconfig
last.c
Makefile
sound_core.c