* [PATCH] ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by
@ 2023-10-03 23:28 Kees Cook
2023-10-03 23:43 ` Gustavo A. R. Silva
2023-10-04 17:14 ` Mark Brown
0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2023-10-03 23:28 UTC (permalink / raw)
To: Liam Girdwood
Cc: Kees Cook, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Gustavo A. R. Silva, alsa-devel, linux-hardening,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm
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.
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: alsa-devel@alsa-project.org
Cc: linux-hardening@vger.kernel.org
Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
include/sound/soc-dapm.h | 2 +-
sound/soc/soc-dapm.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index d2faec9a323e..51516c93916e 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -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) \
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 2512aadf95f7..2e3df47c9cf3 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by
2023-10-03 23:28 [PATCH] ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by Kees Cook
@ 2023-10-03 23:43 ` Gustavo A. R. Silva
2023-10-04 17:14 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-03 23:43 UTC (permalink / raw)
To: Kees Cook, Liam Girdwood
Cc: Mark Brown, Jaroslav Kysela, Takashi Iwai, Gustavo A. R. Silva,
alsa-devel, linux-hardening, Nathan Chancellor, Nick Desaulniers,
Tom Rix, linux-kernel, llvm
On 10/4/23 01:28, Kees Cook wrote:
> 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.
>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Jaroslav Kysela <perex@perex.cz>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: alsa-devel@alsa-project.org
> Cc: linux-hardening@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> include/sound/soc-dapm.h | 2 +-
> sound/soc/soc-dapm.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
> index d2faec9a323e..51516c93916e 100644
> --- a/include/sound/soc-dapm.h
> +++ b/include/sound/soc-dapm.h
> @@ -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) \
> diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
> index 2512aadf95f7..2e3df47c9cf3 100644
> --- a/sound/soc/soc-dapm.c
> +++ b/sound/soc/soc-dapm.c
> @@ -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;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by
2023-10-03 23:28 [PATCH] ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by Kees Cook
2023-10-03 23:43 ` Gustavo A. R. Silva
@ 2023-10-04 17:14 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2023-10-04 17:14 UTC (permalink / raw)
To: Liam Girdwood, Kees Cook
Cc: Jaroslav Kysela, Takashi Iwai, Gustavo A. R. Silva, alsa-devel,
linux-hardening, Nathan Chancellor, Nick Desaulniers, Tom Rix,
linux-kernel, llvm
On Tue, 03 Oct 2023 16:28:53 -0700, Kees Cook wrote:
> 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.
>
> [...]
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-04 17:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-03 23:28 [PATCH] ASoC: soc-dapm: Annotate struct snd_soc_dapm_widget_list with __counted_by Kees Cook
2023-10-03 23:43 ` Gustavo A. R. Silva
2023-10-04 17:14 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).