* [PATCH net-next v2 1/2] net: dsa: microchip: copy string using strscpy
2024-10-14 8:52 [PATCH net-next v2 0/2] net: String format safety updates Simon Horman
@ 2024-10-14 8:52 ` Simon Horman
2024-10-14 8:52 ` [PATCH net-next v2 2/2] net: txgbe: Pass string literal as format argument of alloc_workqueue() Simon Horman
2024-10-15 18:00 ` [PATCH net-next v2 0/2] net: String format safety updates patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2024-10-14 8:52 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Bill Wendling, Daniel Machon, Florian Fainelli, Jiawen Wu,
Justin Stitt, Mengyuan Lou, Nathan Chancellor, Nick Desaulniers,
Richard Cochran, Vladimir Oltean, Woojung Huh, UNGLinuxDriver,
netdev, llvm, linux-kernel
Prior to this patch ksz_ptp_msg_irq_setup() uses snprintf() to copy
strings. It does so by passing strings as the format argument of
snprintf(). This appears to be safe, due to the absence of format
specifiers in the strings, which are declared within the same function.
But nonetheless GCC 14 warns about it:
.../ksz_ptp.c:1109:55: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
1109 | snprintf(ptpmsg_irq->name, sizeof(ptpmsg_irq->name), name[n]);
| ^~~~~~~
.../ksz_ptp.c:1109:55: note: treat the string as an argument to avoid this
1109 | snprintf(ptpmsg_irq->name, sizeof(ptpmsg_irq->name), name[n]);
| ^
| "%s",
As what we are really dealing with here is a string copy, it seems make
sense to use a function designed for this purpose. In this case null
padding is not required, so strscpy is appropriate. And as the
destination is an array of fixed size, the 2-argument variant may be used.
Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
Signed-off-by: Simon Horman <horms@kernel.org>
--
v2
- Add Reviewed-by from Daniel Machon
- Tweaked patch description, thanks to Daniel Machon
---
drivers/net/dsa/microchip/ksz_ptp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c
index 050f17c43ef6..22fb9ef4645c 100644
--- a/drivers/net/dsa/microchip/ksz_ptp.c
+++ b/drivers/net/dsa/microchip/ksz_ptp.c
@@ -1106,7 +1106,7 @@ static int ksz_ptp_msg_irq_setup(struct ksz_port *port, u8 n)
ptpmsg_irq->port = port;
ptpmsg_irq->ts_reg = ops->get_port_addr(port->num, ts_reg[n]);
- snprintf(ptpmsg_irq->name, sizeof(ptpmsg_irq->name), name[n]);
+ strscpy(ptpmsg_irq->name, name[n]);
ptpmsg_irq->num = irq_find_mapping(port->ptpirq.domain, n);
if (ptpmsg_irq->num < 0)
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH net-next v2 2/2] net: txgbe: Pass string literal as format argument of alloc_workqueue()
2024-10-14 8:52 [PATCH net-next v2 0/2] net: String format safety updates Simon Horman
2024-10-14 8:52 ` [PATCH net-next v2 1/2] net: dsa: microchip: copy string using strscpy Simon Horman
@ 2024-10-14 8:52 ` Simon Horman
2024-10-15 18:00 ` [PATCH net-next v2 0/2] net: String format safety updates patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2024-10-14 8:52 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Bill Wendling, Daniel Machon, Florian Fainelli, Jiawen Wu,
Justin Stitt, Mengyuan Lou, Nathan Chancellor, Nick Desaulniers,
Richard Cochran, Vladimir Oltean, Woojung Huh, UNGLinuxDriver,
netdev, llvm, linux-kernel
Recently I noticed that both gcc-14 and clang-18 report that passing
a non-string literal as the format argument of clkdev_create()
is potentially insecure.
E.g. clang-18 says:
.../txgbe_phy.c:582:35: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
581 | clock = clkdev_create(clk, NULL, clk_name);
| ^~~~~~~~
.../txgbe_phy.c:582:35: note: treat the string as an argument to avoid this
581 | clock = clkdev_create(clk, NULL, clk_name);
| ^
| "%s",
It is always the case where the contents of clk_name is safe to pass as the
format argument. That is, in my understanding, it never contains any
format escape sequences.
However, it seems better to be safe than sorry. And, as a bonus, compiler
output becomes less verbose by addressing this issue as suggested by
clang-18.
Compile tested only.
Signed-off-by: Simon Horman <horms@kernel.org>
--
v2
- No changes
---
drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c
index 3dd89dafe7c7..a0e4920b4761 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c
@@ -578,7 +578,7 @@ static int txgbe_clock_register(struct txgbe *txgbe)
if (IS_ERR(clk))
return PTR_ERR(clk);
- clock = clkdev_create(clk, NULL, clk_name);
+ clock = clkdev_create(clk, NULL, "%s", clk_name);
if (!clock) {
clk_unregister(clk);
return -ENOMEM;
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net-next v2 0/2] net: String format safety updates
2024-10-14 8:52 [PATCH net-next v2 0/2] net: String format safety updates Simon Horman
2024-10-14 8:52 ` [PATCH net-next v2 1/2] net: dsa: microchip: copy string using strscpy Simon Horman
2024-10-14 8:52 ` [PATCH net-next v2 2/2] net: txgbe: Pass string literal as format argument of alloc_workqueue() Simon Horman
@ 2024-10-15 18:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-15 18:00 UTC (permalink / raw)
To: Simon Horman
Cc: andrew, davem, edumazet, kuba, pabeni, morbo, daniel.machon,
f.fainelli, jiawenwu, justinstitt, mengyuanlou, nathan,
ndesaulniers, richardcochran, olteanv, woojung.huh,
UNGLinuxDriver, netdev, llvm, linux-kernel
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 14 Oct 2024 09:52:24 +0100 you wrote:
> Hi,
>
> This series addresses string format safety issues that are
> flagged by tooling in files touched by recent patches.
>
> I do not believe that any of these issues are bugs.
> Rather, I am providing these updates as I think there is a value
> in addressing such warnings so real problems stand out.
>
> [...]
Here is the summary with links:
- [net-next,v2,1/2] net: dsa: microchip: copy string using strscpy
https://git.kernel.org/netdev/net-next/c/26919411acfa
- [net-next,v2,2/2] net: txgbe: Pass string literal as format argument of alloc_workqueue()
https://git.kernel.org/netdev/net-next/c/d6488e77725e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread