Skip to contentSkip to conversation

ip_tunnel: harden copying IP tunnel params to userspace

PATCH Applied Alexander Lobakin 3 participants 3 messages Apr 4, 2024 – Apr 8, 2024

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

PATCH 1/1 ip_tunnel: harden copying IP tunnel params to userspace

Structures which are about to be copied to userspace shouldn't have uninitialized fields or paddings.
memset() the whole &ip_tunnel_parm in ip_tunnel_parm_to_user() before filling it with the kernel data. The compilers will hopefully combine writes to it.

Fixes 117aef12a7b1 ("ip_tunnel: use a separate struct to store tunnel params in the kernel")
---
 net/ipv4/ip_tunnel.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/ip_tunnel.c +2 -0
index f63b573f66dc..6ec4365cefa5 100644
@@ -1034,6 +1034,8 @@ bool ip_tunnel_parm_to_user(void __user *data, struct ip_tunnel_parm_kern *kp)
 	    !ip_tunnel_flags_is_be16_compat(kp->o_flags))
 		return false;
 
+	memset(&p, 0, sizeof(p));
+
 	strscpy(p.name, kp->name);
 	p.link = kp->link;
 	p.i_flags = ip_tunnel_flags_to_be16(kp->i_flags);
Signature · 1 line
2.44.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Alexander Lobakin

Structures which are about to be copied to userspace shouldn't have uninitialized fields or paddings.
memset() the whole &ip_tunnel_parm in ip_tunnel_parm_to_user() before filling it with the kernel data. The compilers will hopefully combine writes to it.

Fixes 117aef12a7b1 ("ip_tunnel: use a separate struct to store tunnel params in the kernel")
#2 lore raw
In reply to Alexander Lobakin
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 6 lines · On Thu, 4 Apr 2024 18:03:02 +0200 you wrote:

Structures which are about to be copied to userspace shouldn't have uninitialized fields or paddings.
memset() the whole &ip_tunnel_parm in ip_tunnel_parm_to_user() before filling it with the kernel data. The compilers will hopefully combine writes to it.

Quoted 6 lines
Fixes 117aef12a7b1 ("ip_tunnel: use a separate struct to store tunnel params in the kernel")

[...]

Here is the summary with links:
- [net-next] ip_tunnel: harden copying IP tunnel params to userspace

    https://git.kernel.org/netdev/net-next/c/5a66cda52d7d

You are awesome, thank you!

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