ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by
PATCH 1/1 ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
As found with Coccinelle[1], add __counted_by for struct snd_soc_dapm_widget_list. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.
--- include/sound/soc-dapm.h | 2 +- sound/soc/soc-dapm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/sound/soc-dapm.h +1 -1
@@ -717,7 +717,7 @@ struct snd_soc_dapm_context {/* A list of widgets associated with an object, typically a snd_kcontrol */ struct snd_soc_dapm_widget_list {int num_widgets; -struct snd_soc_dapm_widget *widgets[]; + struct snd_soc_dapm_widget *widgets[] __counted_by(num_widgets); };#define for_each_dapm_widgets (list, i, widget) \
sound/soc/soc-dapm.c +1 -1
@@ -497,8 +497,8 @@ static int dapm_kcontrol_add_widget(struct snd_kcontrol *kcontrol,if (!new_wlist)return -ENOMEM ; - new_wlist->widgets[n -1 ] = widget; new_wlist->num_widgets = n; + new_wlist->widgets[n -1 ] = widget; data->wlist = new_wlist;
Signature · 1 line
2.34.1
Quoted 10 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structsnd_soc_dapm_widget_list. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.
Quoted 9 lines
Cc Liam Girdwood <[email protected]>Cc Mark Brown <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Takashi Iwai <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>
Thanks
--
Gustavo
Quoted 32 lines
--- include/sound/soc-dapm.h | 2 +- sound/soc/soc-dapm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/sound/soc-dapm.h +1
-1@@ -717,7 +717,7 @@ struct snd_soc_dapm_context {/* A list of widgets associated with an object, typically a snd_kcontrol */ struct snd_soc_dapm_widget_list {int num_widgets; -struct snd_soc_dapm_widget *widgets[]; + struct snd_soc_dapm_widget *widgets[] __counted_by(num_widgets); };#define for_each_dapm_widgets (list, i, widget) \sound/soc/soc-dapm.c +1
-1@@ -497,8 +497,8 @@ static int dapm_kcontrol_add_widget(struct snd_kcontrol *kcontrol,if (!new_wlist)return -ENOMEM ; - new_wlist->widgets[n -1 ] = widget; new_wlist->num_widgets = n; + new_wlist->widgets[n -1 ] = widget; data->wlist = new_wlist;
Mark Brown
maintainerQuoted 11 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structsnd_soc_dapm_widget_list. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by
commit: 80e698e2df5ba2124bdeca37f1e589de58a4d514
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark