Linux Kernel Mentees list
 help / color / mirror / Atom feed
From: Andrew Kanner <andrew.kanner@gmail.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, jasowang@redhat.com, netdev@vger.kernel.org,
	brouer@redhat.com, linux-kernel@vger.kernel.org
Cc: syzbot+f817490f5bd20541b90a@syzkaller.appspotmail.com,
	linux-kernel-mentees@lists.linuxfoundation.org
Subject: [PATCH 2/2] drivers: net: prevent tun_can_build_skb() to exceed xdp size limits
Date: Tue, 25 Jul 2023 01:13:26 +0300	[thread overview]
Message-ID: <20230724221326.384-2-andrew.kanner@gmail.com> (raw)
In-Reply-To: <20230724221326.384-1-andrew.kanner@gmail.com>

Tested with syzkaller repro with reduced packet size. It was
discovered that XDP_PACKET_HEADROOM is not checked in
tun_can_build_skb(), although pad may be incremented in
tun_build_skb().

Fixes: 7df13219d757 ("tun: reserve extra headroom only when XDP is set")
Link: https://syzkaller.appspot.com/text?tag=ReproC&x=12b2593ea80000
Signed-off-by: Andrew Kanner <andrew.kanner@gmail.com>
---
 drivers/net/tun.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 18ccbbe9830a..cdf2bd85b383 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1582,7 +1582,13 @@ 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 *skb_xdp)
 {
-	if (SKB_DATA_ALIGN(len + TUN_RX_PAD) +
+	int pad = TUN_RX_PAD;
+	struct bpf_prog *xdp_prog = rcu_dereference(tun->xdp_prog);
+
+	if (xdp_prog)
+		pad += XDP_PACKET_HEADROOM;
+
+	if (SKB_DATA_ALIGN(len + pad) +
 	    SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) > PAGE_SIZE) {
 		*skb_xdp = 0;
 		return false;
-- 
2.39.3

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2023-07-24 22:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-24 22:13 [PATCH 1/2] drivers: net: use xdp only inside tun_build_skb() Andrew Kanner
2023-07-24 22:13 ` Andrew Kanner [this message]
2023-07-25  3:39   ` [PATCH 2/2] drivers: net: prevent tun_can_build_skb() to exceed xdp size limits Jason Wang
2023-07-25 10:49     ` Andrew Kanner
2023-07-25  3:28 ` [PATCH 1/2] drivers: net: use xdp only inside tun_build_skb() Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230724221326.384-2-andrew.kanner@gmail.com \
    --to=andrew.kanner@gmail.com \
    --cc=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jasowang@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=syzbot+f817490f5bd20541b90a@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox