Skip to content

Commit b5172e6

Browse files
bandaritiwai
authored andcommitted
ALSA: pcm: fix undefined behavior in bit shift for SNDRV_PCM_RATE_KNOT
Shifting signed 32-bit value by 31 bits is undefined, so changing significant bit to unsigned. The UBSAN warning calltrace like below: UBSAN: shift-out-of-bounds in sound/core/pcm_native.c:2676:21 left shift of 1 by 31 places cannot be represented in type 'int' ... Call Trace: <TASK> dump_stack_lvl+0x8d/0xcf ubsan_epilogue+0xa/0x44 __ubsan_handle_shift_out_of_bounds+0x1e7/0x208 snd_pcm_open_substream+0x9f0/0xa90 snd_pcm_oss_open.part.26+0x313/0x670 snd_pcm_oss_open+0x30/0x40 soundcore_open+0x18b/0x2e0 chrdev_open+0xe2/0x270 do_dentry_open+0x2f7/0x620 path_openat+0xd66/0xe70 do_filp_open+0xe3/0x170 do_sys_openat2+0x357/0x4a0 do_sys_open+0x87/0xd0 do_syscall_64+0x34/0x80 Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Baisong Zhong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 1cf47b0 commit b5172e6

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

include/sound/pcm.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,24 @@ struct snd_pcm_ops {
106106
#define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1)
107107

108108
/* If you change this don't forget to change rates[] table in pcm_native.c */
109-
#define SNDRV_PCM_RATE_5512 (1<<0) /* 5512Hz */
110-
#define SNDRV_PCM_RATE_8000 (1<<1) /* 8000Hz */
111-
#define SNDRV_PCM_RATE_11025 (1<<2) /* 11025Hz */
112-
#define SNDRV_PCM_RATE_16000 (1<<3) /* 16000Hz */
113-
#define SNDRV_PCM_RATE_22050 (1<<4) /* 22050Hz */
114-
#define SNDRV_PCM_RATE_32000 (1<<5) /* 32000Hz */
115-
#define SNDRV_PCM_RATE_44100 (1<<6) /* 44100Hz */
116-
#define SNDRV_PCM_RATE_48000 (1<<7) /* 48000Hz */
117-
#define SNDRV_PCM_RATE_64000 (1<<8) /* 64000Hz */
118-
#define SNDRV_PCM_RATE_88200 (1<<9) /* 88200Hz */
119-
#define SNDRV_PCM_RATE_96000 (1<<10) /* 96000Hz */
120-
#define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */
121-
#define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */
122-
#define SNDRV_PCM_RATE_352800 (1<<13) /* 352800Hz */
123-
#define SNDRV_PCM_RATE_384000 (1<<14) /* 384000Hz */
124-
125-
#define SNDRV_PCM_RATE_CONTINUOUS (1<<30) /* continuous range */
126-
#define SNDRV_PCM_RATE_KNOT (1<<31) /* supports more non-continuos rates */
109+
#define SNDRV_PCM_RATE_5512 (1U<<0) /* 5512Hz */
110+
#define SNDRV_PCM_RATE_8000 (1U<<1) /* 8000Hz */
111+
#define SNDRV_PCM_RATE_11025 (1U<<2) /* 11025Hz */
112+
#define SNDRV_PCM_RATE_16000 (1U<<3) /* 16000Hz */
113+
#define SNDRV_PCM_RATE_22050 (1U<<4) /* 22050Hz */
114+
#define SNDRV_PCM_RATE_32000 (1U<<5) /* 32000Hz */
115+
#define SNDRV_PCM_RATE_44100 (1U<<6) /* 44100Hz */
116+
#define SNDRV_PCM_RATE_48000 (1U<<7) /* 48000Hz */
117+
#define SNDRV_PCM_RATE_64000 (1U<<8) /* 64000Hz */
118+
#define SNDRV_PCM_RATE_88200 (1U<<9) /* 88200Hz */
119+
#define SNDRV_PCM_RATE_96000 (1U<<10) /* 96000Hz */
120+
#define SNDRV_PCM_RATE_176400 (1U<<11) /* 176400Hz */
121+
#define SNDRV_PCM_RATE_192000 (1U<<12) /* 192000Hz */
122+
#define SNDRV_PCM_RATE_352800 (1U<<13) /* 352800Hz */
123+
#define SNDRV_PCM_RATE_384000 (1U<<14) /* 384000Hz */
124+
125+
#define SNDRV_PCM_RATE_CONTINUOUS (1U<<30) /* continuous range */
126+
#define SNDRV_PCM_RATE_KNOT (1U<<31) /* supports more non-continuos rates */
127127

128128
#define SNDRV_PCM_RATE_8000_44100 (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
129129
SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|\

0 commit comments

Comments
 (0)