ASoC: Intel: avs: Fix potential buffer overflow by snprintf()
Subsystems (4)
PATCH v2 1/1 ASoC: Intel: avs: Fix potential buffer overflow by snprintf()
From: HariKrishna Sagala <[email protected]>
snprintf() returns the would-be-filled size when the string overflows the given buffer size, hence using this value may result in a buffer overflow (although it's unrealistic).
This patch replaces it with a safer version, scnprintf() for papering over such a potential issue.
'Fixes: 5a565ba23abe ("ASoC: Intel: avs: Probing and firmware tracing over debugfs")'
---
Thank you for the feedback and the suggestions.
Corrected the indentation & commit message.
V1:
https://lore.kernel.org/all/[email protected]/
sound/soc/intel/avs/debugfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/intel/avs/debugfs.c +3 -3
@@ -119,9 +119,9 @@ static ssize_t probe_points_read(struct file *file, char __user *to, size_t coun }for (i =0 ; i < num_desc; i++) { - ret =snprintf (buf + len,PAGE_SIZE - len, -"Id: %#010x Purpose: %d Node id: %#x\n" , - desc[i].id.value, desc[i].purpose, desc[i].node_id.val); + ret =scnprintf (buf + len,PAGE_SIZE - len, +"Id: %#010x Purpose: %d Node id: %#x\n" , + desc[i].id.value, desc[i].purpose, desc[i].node_id.val);if (ret <0 ) goto free_desc; len += ret;
base-commit: 24172e0d79900908cf5ebf366600616d29c9b417
Signature · 1 line
2.43.0
kernel test robot
build botFYI: kernel test robot notices the stable kernel rule is not satisfied.
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1
Rule: add the tag "Cc: [email protected]" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH v2] ASoC: Intel: avs: Fix potential buffer overflow by snprintf()
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Greg KH
maintainerQuoted 5 lines · On Wed, Nov 12, 2025 at 11:48:51PM +0530, [email protected] wrote:
From: HariKrishna Sagala <[email protected]>
snprintf()returns the would-be-filled size when the string overflows the given buffer size, hence using this value may result in a buffer overflow (although it's unrealistic).
unrealistic == impossible
So why make this change at all?
Quoted 2 lines
This patch replaces it with a safer version,
scnprintf()for papering over such a potential issue.
Don't "paper over", actually fix real things.
Quoted 3 lines
'Fixes:
5a565ba23abe("ASoC: Intel: avs: Probing and firmware tracing over debugfs")'
No, this is not a "fix".
Also please do not wrap lines of fixes tags.
thanks,
greg k-h
Mark Brown
maintainerQuoted 1 line · Greg KH
Also please do not wrap lines of fixes tags.
Someone probably ought to teach checkpatch about that one, it moans about long lines without checking for Fixes: IIRC.
Quoted 6 lines · Mark Brown
Quoted 1 line · Greg KH
Also please do not wrap lines of fixes tags.
Someone probably ought to teach checkpatch about that one, it moans about long lines without checking for Fixes: IIRC.
I can recall this issue, too... I checked how to reproduce and fix this but it seems it's already done: I couldn't reproduce it. I'm getting this for breaking a Fixes: line:
WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: ...
It basically now checks the subject matches with the quoted string.
So all is well!
Signature · 1 line
Sakari Ailus
Cezary Rojewski
maintainerQuoted 10 lines · Greg KH
Quoted 5 lines · On Wed, Nov 12, 2025 at 11:48:51PM +0530, [email protected] wrote:
From: HariKrishna Sagala <[email protected]>
snprintf()returns the would-be-filled size when the string overflows the given buffer size, hence using this value may result in a buffer overflow (although it's unrealistic).unrealistic == impossible
So why make this change at all?
The problem will never occur in production-scenario given the AudioDSP firmware limitation - max ~10 probe-point entries so, the built string will be far away from 4K_SZ bytes.
If the verdict is: ignore the recommendation as the problem is unrealistic, I'm OK with that. Typically though I'd prefer to stick to the recommendations.
Quoted 4 lines
Quoted 3 lines
This patch replaces it with a safer version,
scnprintf()for papering over such a potential issue.
Quoted 8 lines
Don't "paper over", actually fix real things.
Quoted 3 lines
'Fixes:
5a565ba23abe("ASoC: Intel: avs: Probing and firmware tracing over debugfs")'No, this is not a "fix".
The patch isn't worded well, that's clear.
While the patch is an outcome of static-analysis, isn't it good to have 'Fixes:' to point out the offending commit regardless?
Greg KH
maintainerQuoted 12 lines · Cezary Rojewski
Quoted 10 lines · Greg KH
Quoted 5 lines · On Wed, Nov 12, 2025 at 11:48:51PM +0530, [email protected] wrote:
From: HariKrishna Sagala <[email protected]>
snprintf()returns the would-be-filled size when the string overflows the given buffer size, hence using this value may result in a buffer overflow (although it's unrealistic).unrealistic == impossible
So why make this change at all?
Quoted 7 lines
The problem will never occur in production-scenario given the AudioDSP firmware limitation - max ~10 probe-point entries so, the built string will be far away from 4K_SZ bytes.
If the verdict is: ignore the recommendation as the problem is unrealistic, I'm OK with that. Typically though I'd prefer to stick to the recommendations.
That's fine, but don't claim that it fixes a buffer overflow when that is NOT what this is doing at all.
Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
This patch replaces it with a safer version,
scnprintf()for papering over such a potential issue.Don't "paper over", actually fix real things.
Quoted 3 lines
'Fixes:
5a565ba23abe("ASoC: Intel: avs: Probing and firmware tracing over debugfs")'
Quoted 5 lines
Quoted 1 line
No, this is not a "fix".
The patch isn't worded well, that's clear.
While the patch is an outcome of static-analysis, isn't it good to have 'Fixes:' to point out the offending commit regardless?
No, it is not "fixing" anything. Please don't claim that it does. It is "just" a code transformation to get rid of an api that some people do not like.
thanks,
greg k-h