Commit bee34890 authored by Will Deacon's avatar Will Deacon Committed by David S. Miller

tun: Don't put_page() for all negative return values from XDP program

When an XDP program is installed, tun_build_skb() grabs a reference to
the current page fragment page if the program returns XDP_REDIRECT or
XDP_TX. However, since tun_xdp_act() passes through negative return
values from the XDP program, it is possible to trigger the error path by
mistake and accidentally drop a reference to the fragments page without
taking one, leading to a spurious free. This is believed to be the cause
of some KASAN use-after-free reports from syzbot [1], although without a
reproducer it is not possible to confirm whether this patch fixes the
problem.

Ensure that we only drop a reference to the fragments page if the XDP
transmit or redirect operations actually fail.

[1] https://syzkaller.appspot.com/bug?id=e76a6af1be4acd727ff6bbca669833f98cbf5d95

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
CC: Eric Dumazet <edumazet@google.com>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Fixes: 8ae1aff0 ("tuntap: split out XDP logic")
Signed-off-by: default avatarWill Deacon <will@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0452800f
...@@ -1678,8 +1678,12 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, ...@@ -1678,8 +1678,12 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
alloc_frag->offset += buflen; alloc_frag->offset += buflen;
} }
err = tun_xdp_act(tun, xdp_prog, &xdp, act); err = tun_xdp_act(tun, xdp_prog, &xdp, act);
if (err < 0) if (err < 0) {
goto err_xdp; if (act == XDP_REDIRECT || act == XDP_TX)
put_page(alloc_frag->page);
goto out;
}
if (err == XDP_REDIRECT) if (err == XDP_REDIRECT)
xdp_do_flush(); xdp_do_flush();
if (err != XDP_PASS) if (err != XDP_PASS)
...@@ -1693,8 +1697,6 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun, ...@@ -1693,8 +1697,6 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
return __tun_build_skb(tfile, alloc_frag, buf, buflen, len, pad); return __tun_build_skb(tfile, alloc_frag, buf, buflen, len, pad);
err_xdp:
put_page(alloc_frag->page);
out: out:
rcu_read_unlock(); rcu_read_unlock();
local_bh_enable(); local_bh_enable();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment