ip_tunnel: harden copying IP tunnel params to userspace
authorAlexander Lobakin <aleksander.lobakin@intel.com>
Thu, 4 Apr 2024 16:03:02 +0000 (18:03 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 Apr 2024 10:02:00 +0000 (11:02 +0100)
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")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/netdev/5f63dd25-de94-4ca3-84e6-14095953db13@moroto.mountain
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ip_tunnel.c

index f65170a28106eccc37187075075f68cf2f7429da..177f40c3a8e8f6abea37836d2dea0682d22f2fc0 100644 (file)
@@ -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);