net: ieee802154: adf7242: Fix some potential buffer overflow in adf7242_stats_show()
Subsystems (5)
PATCH 1/1 net: ieee802154: adf7242: Fix some potential buffer overflow in adf7242_stats_show()
strncat() usage in adf7242_debugfs_init() is wrong.
The size given to strncat() is the maximum number of bytes that can be written, excluding the trailing NULL.
Here, the size that is passed, DNAME_INLINE_LEN, does not take into account the size of "adf7242-" that is already in the array.
In order to fix it, use snprintf() instead.
--- drivers/net/ieee802154/adf7242.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ieee802154/adf7242.c +3 -2
@@ -1162,9 +1162,10 @@ static int adf7242_stats_show(struct seq_file *file, void *offset)static void adf7242_debugfs_init (struct adf7242_local *lp) { -char debugfs_dir_name[DNAME_INLINE_LEN +1 ] ="adf7242-" ; +char debugfs_dir_name[DNAME_INLINE_LEN +1 ]; -strncat (debugfs_dir_name,dev_name (&lp->spi->dev),DNAME_INLINE_LEN ); +snprintf (debugfs_dir_name,sizeof (debugfs_dir_name), +"adf7242-%s" ,dev_name (&lp->spi->dev)); lp->debugfs_root =debugfs_create_dir (debugfs_dir_name,NULL );
Signature · 1 line
2.34.1
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 8 lines · On Sat, 21 Oct 2023 20:03:53 +0200 you wrote:
strncat()usage inadf7242_debugfs_init()is wrong.
The size given tostrncat()is the maximum number of bytes that can be written, excluding the trailing NULL.Here, the size that is passed,
DNAME_INLINE_LEN, does not take into account the size of "adf7242-" that is already in the array.[...]
Here is the summary with links:
- [net] net: ieee802154: adf7242: Fix some potential buffer overflow in adf7242_stats_show()
https://git.kernel.org/netdev/net/c/ca082f019d8f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 26 lines
-----Original Message-----
From: Christophe JAILLET <[email protected]>
Sent: Samstag, 21. Oktober 2023 20:04
To: [email protected]; Hennerich, Michael <[email protected]>; Alexander Aring <[email protected]>; Stefan Schmidt <[email protected]>; Miquel Raynal <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Marcel Holtmann <[email protected]>
Cc: [email protected]; [email protected]; kernel- [email protected]; Christophe JAILLET <[email protected]>; Stefan Schmidt <[email protected]>; [email protected]; [email protected]
Subject: [PATCH net] net: ieee802154: adf7242: Fix some potential buffer overflow inadf7242_stats_show()
strncat()usage inadf7242_debugfs_init()is wrong.
The size given tostrncat()is the maximum number of bytes that can be written, excluding the trailing NULL.Here, the size that is passed,
DNAME_INLINE_LEN, does not take into account the size of "adf7242-" that is already in the array.
Quoted 6 lines
In order to fix it, use
snprintf()instead.Fixes 7302b9d90117 ("ieee802154/adf7242: Driver for ADF7242 MACIEEE802154")
Signed-off-by Christophe JAILLET <[email protected]>---
Quoted 24 lines
drivers/net/ieee802154/adf7242.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/net/ieee802154/adf7242.c +3
-3@@ -1162,9 +1162,10 @@ static int adf7242_stats_show(struct seq_file *file, void *offset)static void adf7242_debugfs_init (struct adf7242_local *lp) { -char debugfs_dir_name[DNAME_INLINE_LEN +1 ] ="adf7242-" ; +char debugfs_dir_name[DNAME_INLINE_LEN +1 ]; -strncat (debugfs_dir_name,dev_name (&lp->spi->dev), DNAME_INLINE_LEN); +snprintf (debugfs_dir_name,sizeof (debugfs_dir_name), +"adf7242-%s" ,dev_name (&lp->spi->dev)); lp->debugfs_root =debugfs_create_dir (debugfs_dir_name,NULL ); --2.34.1