Skip to content

Commit 9f34290

Browse files
jason77-wangbroonie
authored andcommitted
ASoC: cs35l41: Fix an out-of-bounds access in otp_packed_element_t
The CS35L41_NUM_OTP_ELEM is 100, but only 99 entries are defined in the array otp_map_1/2[CS35L41_NUM_OTP_ELEM], this will trigger UBSAN to report a shift-out-of-bounds warning in the cs35l41_otp_unpack() since the last entry in the array will result in GENMASK(-1, 0). UBSAN reports this problem: UBSAN: shift-out-of-bounds in /home/hwang4/build/jammy/jammy/sound/soc/codecs/cs35l41-lib.c:836:8 shift exponent 64 is too large for 64-bit type 'long unsigned int' CPU: 10 PID: 595 Comm: systemd-udevd Not tainted 5.15.0-23-generic thesofproject#23 Hardware name: LENOVO \x02MFG_IN_GO/\x02MFG_IN_GO, BIOS N3GET19W (1.00 ) 03/11/2022 Call Trace: <TASK> show_stack+0x52/0x58 dump_stack_lvl+0x4a/0x5f dump_stack+0x10/0x12 ubsan_epilogue+0x9/0x45 __ubsan_handle_shift_out_of_bounds.cold+0x61/0xef ? regmap_unlock_mutex+0xe/0x10 cs35l41_otp_unpack.cold+0x1c6/0x2b2 [snd_soc_cs35l41_lib] cs35l41_hda_probe+0x24f/0x33a [snd_hda_scodec_cs35l41] cs35l41_hda_i2c_probe+0x65/0x90 [snd_hda_scodec_cs35l41_i2c] ? cs35l41_hda_i2c_remove+0x20/0x20 [snd_hda_scodec_cs35l41_i2c] i2c_device_probe+0x252/0x2b0 Fixes: 6450ef5 ("ASoC: cs35l41: CS35L41 Boosted Smart Amplifier") Reviewed-by: Lucas Tanure <tanureal@opensource.cirrus.com> Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Hui Wang <hui.wang@canonical.com> Link: https://lore.kernel.org/r/20220328123535.50000-2-hui.wang@canonical.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 0f91bc7 commit 9f34290

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

include/sound/cs35l41.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@
536536

537537
#define CS35L41_MAX_CACHE_REG 36
538538
#define CS35L41_OTP_SIZE_WORDS 32
539-
#define CS35L41_NUM_OTP_ELEM 100
540539

541540
#define CS35L41_VALID_PDATA 0x80000000
542541
#define CS35L41_NUM_SUPPLIES 2

sound/soc/codecs/cs35l41-lib.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static bool cs35l41_volatile_reg(struct device *dev, unsigned int reg)
422422
}
423423
}
424424

425-
static const struct cs35l41_otp_packed_element_t otp_map_1[CS35L41_NUM_OTP_ELEM] = {
425+
static const struct cs35l41_otp_packed_element_t otp_map_1[] = {
426426
/* addr shift size */
427427
{ 0x00002030, 0, 4 }, /*TRIM_OSC_FREQ_TRIM*/
428428
{ 0x00002030, 7, 1 }, /*TRIM_OSC_TRIM_DONE*/
@@ -525,7 +525,7 @@ static const struct cs35l41_otp_packed_element_t otp_map_1[CS35L41_NUM_OTP_ELEM]
525525
{ 0x00017044, 0, 24 }, /*LOT_NUMBER*/
526526
};
527527

528-
static const struct cs35l41_otp_packed_element_t otp_map_2[CS35L41_NUM_OTP_ELEM] = {
528+
static const struct cs35l41_otp_packed_element_t otp_map_2[] = {
529529
/* addr shift size */
530530
{ 0x00002030, 0, 4 }, /*TRIM_OSC_FREQ_TRIM*/
531531
{ 0x00002030, 7, 1 }, /*TRIM_OSC_TRIM_DONE*/
@@ -671,35 +671,35 @@ static const struct cs35l41_otp_map_element_t cs35l41_otp_map_map[] = {
671671
{
672672
.id = 0x01,
673673
.map = otp_map_1,
674-
.num_elements = CS35L41_NUM_OTP_ELEM,
674+
.num_elements = ARRAY_SIZE(otp_map_1),
675675
.bit_offset = 16,
676676
.word_offset = 2,
677677
},
678678
{
679679
.id = 0x02,
680680
.map = otp_map_2,
681-
.num_elements = CS35L41_NUM_OTP_ELEM,
681+
.num_elements = ARRAY_SIZE(otp_map_2),
682682
.bit_offset = 16,
683683
.word_offset = 2,
684684
},
685685
{
686686
.id = 0x03,
687687
.map = otp_map_2,
688-
.num_elements = CS35L41_NUM_OTP_ELEM,
688+
.num_elements = ARRAY_SIZE(otp_map_2),
689689
.bit_offset = 16,
690690
.word_offset = 2,
691691
},
692692
{
693693
.id = 0x06,
694694
.map = otp_map_2,
695-
.num_elements = CS35L41_NUM_OTP_ELEM,
695+
.num_elements = ARRAY_SIZE(otp_map_2),
696696
.bit_offset = 16,
697697
.word_offset = 2,
698698
},
699699
{
700700
.id = 0x08,
701701
.map = otp_map_1,
702-
.num_elements = CS35L41_NUM_OTP_ELEM,
702+
.num_elements = ARRAY_SIZE(otp_map_1),
703703
.bit_offset = 16,
704704
.word_offset = 2,
705705
},

0 commit comments

Comments
 (0)