• Jason A. Donenfeld's avatar
    wireguard: netlink: avoid variable-sized memcpy on sockaddr · 26c01310
    Jason A. Donenfeld authored
    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: e7096c13 ("net: WireGuard secure network tunnel")
    Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
    Reviewed-by: default avatarKees Cook <keescook@chromium.org>
    Reported-by: syzbot+a448cda4dba2dac50de5@syzkaller.appspotmail.com
    Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    26c01310
netlink.c 17.7 KB