Skip to contentSkip to conversation

netdevsim: prevent bad user input in nsim_dev_health_break_write()

PATCH Applied Eric Dumazet 3 participants 3 messages Dec 13, 2024 – Dec 15, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netdevsim: prevent bad user input in nsim_dev_health_break_write()

If either a zero count or a large one is provided, kernel can crash.

Fixes 82c93a87bf8b ("netdevsim: implement couple of testing devlink health reporters")
Reported-by [email protected]
Cc Jiri Pirko <[email protected]>
---
 drivers/net/netdevsim/health.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/netdevsim/health.c +2 -0
index 70e8bdf34be900f744e821fb237641a27bb71a7b..688f05316b5e109fc84222476023f3f1f078cf28 100644
@@ -149,6 +149,8 @@ static ssize_t nsim_dev_health_break_write(struct file *file,
 	char *break_msg;
 	int err;
 
+	if (count == 0 || count > PAGE_SIZE)
+		return -EINVAL;
 	break_msg = memdup_user_nul(data, count);
 	if (IS_ERR(break_msg))
 		return PTR_ERR(break_msg);
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Eric Dumazet

If either a zero count or a large one is provided, kernel can crash.

Fixes 82c93a87bf8b ("netdevsim: implement couple of testing devlink health reporters")
Reported-by [email protected]
Cc Jiri Pirko <[email protected]>
---
 drivers/net/netdevsim/health.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/netdevsim/health.c +0 -0
index 70e8bdf34be900f744e821fb237641a27bb71a7b..688f05316b5e109fc84222476023f3f1f078cf28 100644

drivers/net/netdevsim/health.c static ssize_t nsim_dev_health_break_write(struct file *file, · line 156

Quoted 8 lines
drivers/net/netdevsim/health.c +2 -0
@@ -149,6 +149,8 @@ static ssize_t nsim_dev_health_break_write(struct file *file,
 	char *break_msg;
 	int err;
 
+	if (count == 0 || count > PAGE_SIZE)
+		return -EINVAL;
 	break_msg = memdup_user_nul(data, count);
 	if (IS_ERR(break_msg))
 		return PTR_ERR(break_msg);
#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 13 Dec 2024 17:25:18 +0000 you wrote:

If either a zero count or a large one is provided, kernel can crash.

Fixes 82c93a87bf8b ("netdevsim: implement couple of testing devlink health reporters")
Reported-by [email protected]
Cc Jiri Pirko <[email protected]>

[...]

Here is the summary with links:
- [net] netdevsim: prevent bad user input in nsim_dev_health_break_write()

    https://git.kernel.org/netdev/net/c/ee76746387f6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html