diff --git a/drivers/net/tun.c b/drivers/net/tun.c index d75456adc62a..18ccbbe9830a 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1580,8 +1580,14 @@ static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile, } static bool tun_can_build_skb(struct tun_struct *tun, struct tun_file *tfile, - int len, int noblock, bool zerocopy) + int len, int noblock, bool zerocopy, int *skb_xdp) { + if (SKB_DATA_ALIGN(len + TUN_RX_PAD) + + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) > PAGE_SIZE) { + *skb_xdp = 0; + return false; + } + if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP) return false; @@ -1594,10 +1600,6 @@ static bool tun_can_build_skb(struct tun_struct *tun, struct tun_file *tfile, if (zerocopy) return false; - if (SKB_DATA_ALIGN(len + TUN_RX_PAD) + - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) > PAGE_SIZE) - return false; - return true; } @@ -1809,7 +1811,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, zerocopy = true; } - if (!frags && tun_can_build_skb(tun, tfile, len, noblock, zerocopy)) { + if (tun_can_build_skb(tun, tfile, len, noblock, zerocopy, &skb_xdp) && !frags) { /* For the packet that is not easy to be processed * (e.g gso or jumbo packet), we will do it at after * skb was created with generic XDP routine.