]> git.itanic.dy.fi Git - linux-stable/commit
wireguard: netlink: avoid variable-sized memcpy on sockaddr
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 16 Sep 2022 14:37:40 +0000 (15:37 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Sep 2022 09:10:34 +0000 (11:10 +0200)
commitf0a057f49b8db5d9dd39769fecaae7a466825993
treeeb2851e75004174e7b0efa5f8f1e0d6b894ea051
parentb7b38595989457e06beabccc84438ed843686a82
wireguard: netlink: avoid variable-sized memcpy on sockaddr

[ Upstream commit 26c013108c12b94bc023bf19198a4300596c98b1 ]

Doing a variable-sized memcpy is slower, and the compiler isn't smart
enough to turn this into a constant-size assignment.

Further, Kees' latest fortified memcpy will actually bark, because the
destination pointer is type sockaddr, not explicitly sockaddr_in or
sockaddr_in6, so it thinks there's an overflow:

    memcpy: detected field-spanning write (size 28) of single field
    "&endpoint.addr" at drivers/net/wireguard/netlink.c:446 (size 16)

Fix this by just assigning by using explicit casts for each checked
case.

Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reported-by: syzbot+a448cda4dba2dac50de5@syzkaller.appspotmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/wireguard/netlink.c