]> git.baikalelectronics.ru Git - kernel.git/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)
committerJakub Kicinski <kuba@kernel.org>
Tue, 20 Sep 2022 18:26:14 +0000 (11:26 -0700)
commit1e226edfbe5e5a2d3013a61f72a3220d7e5aaf7e
treec713b038b1f48a571e68da4a7035e3a396e40374
parent708c5c42c39b8c82eb4f5bf759b955f2729e3a03
wireguard: netlink: avoid variable-sized memcpy on sockaddr

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: 4dff5496e367 ("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>
drivers/net/wireguard/netlink.c