Skip to content

Commit bee3489

Browse files
willdeacondavem330
authored andcommitted
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" <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Daniel Borkmann <[email protected]> CC: Eric Dumazet <[email protected]> Acked-by: Jason Wang <[email protected]> Fixes: 8ae1aff ("tuntap: split out XDP logic") Signed-off-by: Will Deacon <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0452800 commit bee3489

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/net/tun.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,8 +1678,12 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
16781678
alloc_frag->offset += buflen;
16791679
}
16801680
err = tun_xdp_act(tun, xdp_prog, &xdp, act);
1681-
if (err < 0)
1682-
goto err_xdp;
1681+
if (err < 0) {
1682+
if (act == XDP_REDIRECT || act == XDP_TX)
1683+
put_page(alloc_frag->page);
1684+
goto out;
1685+
}
1686+
16831687
if (err == XDP_REDIRECT)
16841688
xdp_do_flush();
16851689
if (err != XDP_PASS)
@@ -1693,8 +1697,6 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
16931697

16941698
return __tun_build_skb(tfile, alloc_frag, buf, buflen, len, pad);
16951699

1696-
err_xdp:
1697-
put_page(alloc_frag->page);
16981700
out:
16991701
rcu_read_unlock();
17001702
local_bh_enable();

0 commit comments

Comments
 (0)