ASoC:codecs: lpass: Fix for KASAN use_after_free out of bounds
Subsystems (3)
PATCH 1/1 ASoC:codecs: lpass: Fix for KASAN use_after_free out of bounds
When we run syzkaller we get below Out of Bounds error.
"KASAN: slab-out-of-bounds Read in regcache_flat_read"
Below is the backtrace of the issue:
BUG: KASAN: slab-out-of-bounds in regcache_flat_read+0x10c/0x110 Read of size 4 at addr ffffff8088fbf714 by task syz-executor.4/14144 CPU: 6 PID: 14144 Comm: syz-executor.4 Tainted: G W Hardware name: Qualcomm Technologies, Inc. sc7280 CRD platform (rev5+) (DT) Call trace: dump_backtrace+0x0/0x4ec show_stack+0x34/0x50 dump_stack_lvl+0xdc/0x11c print_address_description+0x30/0x2d8 kasan_report+0x178/0x1e4 __asan_report_load4_noabort+0x44/0x50 regcache_flat_read+0x10c/0x110 regcache_read+0xf8/0x5a0 _regmap_read+0x45c/0x86c _regmap_update_bits+0x128/0x290 regmap_update_bits_base+0xc0/0x15c snd_soc_component_update_bits+0xa8/0x22c snd_soc_component_write_field+0x68/0xd4 tx_macro_put_dec_enum+0x1d0/0x268 snd_ctl_elem_write+0x288/0x474
By Error checking and checking valid values issue gets rectifies.
--- sound/soc/codecs/lpass-tx-macro.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
sound/soc/codecs/lpass-tx-macro.c +15 -4
@@ -746,6 +746,8 @@ static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,struct tx_macro *tx =snd_soc_component_get_drvdata (component); val = ucontrol->value.enumerated.item[0 ]; +if (val <0 && val >15 ) +return -EINVAL ;switch (e->reg) {case CDC_TX_INP_MUX_ADC_MUX0_CFG0 :
@@ -772,6 +774,9 @@ static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,case CDC_TX_INP_MUX_ADC_MUX7_CFG0 : mic_sel_reg =CDC_TX7_TX_PATH_CFG0 ;break ; +default : +dev_err (component->dev,"Error in configuration!!\n" ); +return -EINVAL ; }if (val !=0 ) {
@@ -785,10 +790,16 @@ static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,snd_soc_component_write_field (component, mic_sel_reg, CDC_TXn_ADC_DMIC_SEL_MASK,1 ); dmic =TX_ADC_TO_DMIC (val); - dmic_clk_reg =CDC_TX_TOP_CSR_SWR_DMICn_CTL (dmic); -snd_soc_component_write_field (component, dmic_clk_reg, -CDC_TX_SWR_DMIC_CLK_SEL_MASK , - tx->dmic_clk_div); +if (dmic <4 ) { + dmic_clk_reg =CDC_TX_TOP_CSR_SWR_DMICn_CTL (dmic); +snd_soc_component_write_field (component, dmic_clk_reg, +CDC_TX_SWR_DMIC_CLK_SEL_MASK , + tx->dmic_clk_div); + }else { +dev_err (component->dev,"Error in dmic configuration!!\n" ); +return -EINVAL ; + } + } }
Signature · 1 line
2.17.1
Quoted 39 lines · Ravulapati Vishnu Vardhan Rao
When we run syzkaller we get below Out of Bounds error.
"KASAN: slab-out-of-bounds Read in
regcache_flat_read"Below is the backtrace of the issue:
BUG: KASAN: slab-out-of-bounds in regcache_flat_read+0x10c/0x110 Read of size 4 at addr ffffff8088fbf714 by task syz-executor.4/14144 CPU: 6 PID: 14144 Comm: syz-executor.4 Tainted: G W Hardware name: Qualcomm Technologies, Inc. sc7280 CRD platform (rev5+) (DT) Call trace: dump_backtrace+0x0/0x4ec show_stack+0x34/0x50 dump_stack_lvl+0xdc/0x11c print_address_description+0x30/0x2d8 kasan_report+0x178/0x1e4 __asan_report_load4_noabort+0x44/0x50 regcache_flat_read+0x10c/0x110 regcache_read+0xf8/0x5a0 _regmap_read+0x45c/0x86c _regmap_update_bits+0x128/0x290 regmap_update_bits_base+0xc0/0x15c snd_soc_component_update_bits+0xa8/0x22c snd_soc_component_write_field+0x68/0xd4 tx_macro_put_dec_enum+0x1d0/0x268 snd_ctl_elem_write+0x288/0x474By Error checking and checking valid values issue gets rectifies.
Signed-off-by Ravulapati Vishnu Vardhan Rao <[email protected]>--- sound/soc/codecs/lpass-tx-macro.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)sound/soc/codecs/lpass-tx-macro.c +0
-0
sound/soc/codecs/lpass-tx-macro.c static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol, · line 750
Quoted 5 lines
sound/soc/codecs/lpass-tx-macro.c +2
-0@@ -746,6 +746,8 @@ static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,struct tx_macro *tx =snd_soc_component_get_drvdata (component); val = ucontrol->value.enumerated.item[0 ]; +if (val <0 && val >15 ) +return -EINVAL ;
how about
if (val >= e->items)
return -EINVAL;
We could get these checks if CONFIG_SND_CTL_INTPUT_VALIDATION was enabled.
Quoted 20 lines
sound/soc/codecs/lpass-tx-macro.c +3
-3switch (e->reg) {case CDC_TX_INP_MUX_ADC_MUX0_CFG0 :@@ -772,6 +774,9 @@ static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,case CDC_TX_INP_MUX_ADC_MUX7_CFG0 : mic_sel_reg =CDC_TX7_TX_PATH_CFG0 ;break ; +default : +dev_err (component->dev,"Error in configuration!!\n" ); +return -EINVAL ; }if (val !=0 ) {@@ -785,10 +790,16 @@ static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,snd_soc_component_write_field (component, mic_sel_reg, CDC_TXn_ADC_DMIC_SEL_MASK,1 ); dmic =TX_ADC_TO_DMIC (val); - dmic_clk_reg =CDC_TX_TOP_CSR_SWR_DMICn_CTL (dmic); - snd_soc_component_write_field(component, dmic_clk_reg, - CDC_TX_SWR_DMIC_CLK_SEL_MASK,
sound/soc/codecs/lpass-tx-macro.c static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol, · line 801
Quoted 10 lines
sound/soc/codecs/lpass-tx-macro.c +9
-1- tx->dmic_clk_div); +if (dmic <4 ) { + dmic_clk_reg =CDC_TX_TOP_CSR_SWR_DMICn_CTL (dmic); +snd_soc_component_write_field (component, dmic_clk_reg, +CDC_TX_SWR_DMIC_CLK_SEL_MASK , + tx->dmic_clk_div); + }else { +dev_err (component->dev,"Error in dmic configuration!!\n" ); +return -EINVAL ; + }
These changes look unrelated.
--srini
Quoted 4 lines
sound/soc/codecs/lpass-tx-macro.c +1
-0+ } }
Mark Brown
maintainerQuoted 10 lines · Srinivas Kandagatla
sound/soc/codecs/lpass-tx-macro.c static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol, · line 750
Quoted 3 lines · Ravulapati Vishnu Vardhan Rao
val = ucontrol->value.enumerated.item[0];sound/soc/codecs/lpass-tx-macro.c +2
-0+if (val <0 && val >15 ) +return -EINVAL ;how about
if (val >=
e->items)return -EINVAL;
The enum value is passed as an int so is signed unfortunately.
Quoted 1 line
We could get these checks if
CONFIG_SND_CTL_INTPUT_VALIDATIONwas enabled.
You can't rely on that being set.
Mark Brown
maintainersound/soc/codecs/lpass-tx-macro.c static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol, · line 750
Quoted 3 lines · Ravulapati Vishnu Vardhan Rao
sound/soc/codecs/lpass-tx-macro.c +2
-0val = ucontrol->value.enumerated.item[0 ]; +if (val <0 && val >15 ) +return -EINVAL ;
Srini is right that it'd be better to read the upper bound from the control, that way it can't geto out of sync.
Quoted 7 lines · Mark Brown
sound/soc/codecs/lpass-tx-macro.c static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol, · line 750
Quoted 3 lines · Ravulapati Vishnu Vardhan Rao
val = ucontrol->value.enumerated.item[0];sound/soc/codecs/lpass-tx-macro.c +2
-0+if (val <0 && val >15 ) +return -EINVAL ;Srini is right that it'd be better to read the upper bound from the control, that way it can't geto out of sync.
Will address and resend it..
Thanks for review.