alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] ASoC: SOF: ipc4-topology: Use size_add() in call to struct_size()
@ 2023-09-15 19:09 Gustavo A. R. Silva
  2023-09-15 19:14 ` Kees Cook
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-15 19:09 UTC (permalink / raw)
  To: Pierre-Louis Bossart, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Daniel Baluta, Kai Vehmanen, Mark Brown,
	Jaroslav Kysela, Takashi Iwai
  Cc: sound-open-firmware, alsa-devel, linux-kernel,
	Gustavo A. R. Silva, linux-hardening

If, for any reason, the open-coded arithmetic causes a wraparound,
the protection that `struct_size()` adds against potential integer
overflows is defeated. Fix this by hardening call to `struct_size()`
with `size_add()`.

Fixes: f9efae954905 ("ASoC: SOF: ipc4-topology: Add support for base config extension")
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 sound/soc/sof/ipc4-topology.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c
index f2a30cd31378..2a19dd022aaf 100644
--- a/sound/soc/sof/ipc4-topology.c
+++ b/sound/soc/sof/ipc4-topology.c
@@ -895,7 +895,8 @@ static int sof_ipc4_widget_setup_comp_process(struct snd_sof_widget *swidget)
 	if (process->init_config == SOF_IPC4_MODULE_INIT_CONFIG_TYPE_BASE_CFG_WITH_EXT) {
 		struct sof_ipc4_base_module_cfg_ext *base_cfg_ext;
 		u32 ext_size = struct_size(base_cfg_ext, pin_formats,
-						swidget->num_input_pins + swidget->num_output_pins);
+					   size_add(swidget->num_input_pins,
+						    swidget->num_output_pins));
 
 		base_cfg_ext = kzalloc(ext_size, GFP_KERNEL);
 		if (!base_cfg_ext) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-10-02 16:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-15 19:09 [PATCH][next] ASoC: SOF: ipc4-topology: Use size_add() in call to struct_size() Gustavo A. R. Silva
2023-09-15 19:14 ` Kees Cook
2023-09-29 19:14 ` Kees Cook
2023-10-01 10:25   ` Mark Brown
2023-10-01 20:37     ` Kees Cook
2023-10-02 10:59       ` Mark Brown
2023-10-02 15:17 ` Mark Brown
2023-10-02 16:49   ` Kees Cook

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).