Re: [PATCH] ASoC: SOF: Bound the panic filename print to its array size
From: Péter Ujfalusi
Date: Thu Sep 10 2026 - 08:15:45 EST
On 09/09/2026 23:40, Ștefan Ghețu wrote:
> struct sof_ipc_panic_info carries the panic location as a fixed 32 byte
> array, and include/sound/sof/trace.h documents that the "filename array
> will not include null terminator if fully filled".
>
> sof_print_oops_and_stack() prints it with an unbounded %s, so firmware
> that fills all 32 bytes leaves printk() with no terminator to stop at
> within the array. It continues into the adjacent linenum field and, if
> that holds no zero byte either, past the end of the structure into the
> caller's stack frame, since every IPC3 dbg_dump callback passes a stack
> allocated struct sof_ipc_panic_info.
>
> Use %.*s with SOF_TRACE_FILENAME_SIZE so the print honours the
> documented bound.
Same thing as for the ASoC: SOF: ipc3: bound firmware-supplied ext
header size.
The firmware internally constructs this and it makes sure that it is
terminated.
To change that you need to compromise the system first and when you are
there you don't need a compromised firmware.
We trust that the firmware has not been compromised as if it is it means
that the whole system has been already compromised.
>
> Fixes: c16211d6226d ("ASoC: SOF: Add Sound Open Firmware driver core")
> Signed-off-by: Ștefan Ghețu <stefanghetu9@xxxxxxxxx>
> ---
> sound/soc/sof/core.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c
> index 2d394389c945..9b0850e87bf6 100644
> --- a/sound/soc/sof/core.c
> +++ b/sound/soc/sof/core.c
> @@ -152,7 +152,8 @@ void sof_print_oops_and_stack(struct snd_sof_dev *sdev, const char *level,
> dev_printk(level, sdev->dev, "trace point: %#010x\n", tracep_code);
>
> out:
> - dev_printk(level, sdev->dev, "panic at %s:%d\n", panic_info->filename,
> + dev_printk(level, sdev->dev, "panic at %.*s:%d\n",
> + SOF_TRACE_FILENAME_SIZE, panic_info->filename,
> panic_info->linenum);
> sof_oops(sdev, level, oops);
> sof_stack(sdev, level, oops, stack, stack_words);
--
Péter