From patchwork Mon Jul 24 22:13:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Kanner X-Patchwork-Id: 125221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2121036vqg; Mon, 24 Jul 2023 16:41:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlHQ6V/7K9DNgirZPpY+kLn3T4MMg1yS/qc6nXYMSMRVFwjJa87eRAyljeYcnXhQ/kjPJ82i X-Received: by 2002:a05:6358:4289:b0:134:e5e7:fb0b with SMTP id s9-20020a056358428900b00134e5e7fb0bmr9278390rwc.0.1690242107315; Mon, 24 Jul 2023 16:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690242107; cv=none; d=google.com; s=arc-20160816; b=CLfpfqDWGwXKKbZx/YMI/6El5Kfv4/FzAAnpsv/6DuMGB22ahs2QyEhmI+KNPZ/DwV Yiw6jP7J80KrZ88lQyhVuhXO19ZgjQ4q7eOwN2cOhRVKNcYI9ARlrhRv4ioqhx+gu3N4 crEB+ghYwXlArlZWO0Fqt0vg06teVBna6+fyuLuREoMhdKbWNftI0sc6h1xMSzs/rxEL cxSkz41PCGEbIeasr4h9nTAEwxdkGfaYD9EM4rjO92tS7bki/T+4Z/OA0VOxSjnl54zY EtFDK+F4aRtB/nWsaC3Q/hEROKxMeFCZUPmhW3TbpjqQEtN414p1+0PBX07gckhcSfYV I4Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=yAsZdb1l2a00omNbaFLi6X9Z1M8KVaOQyZOE0+c0Tbc=; fh=neJKXSJhdh/dzWbfNkmI6hL7/RYA+C6ag08sPsn5SZA=; b=LVm0QGsRipr6Td9gNmuzj5LWW7+utZ+fBW36egAHUN4a4f6lNqKchovNYmXi/H0ctJ oNHe3tEuK8XNR5hi5EuTTzBcw44zcFiJZrIgWSG9Op++yMqKSBehj33E+gRKAM5EpXTp PLSmTYOFcCYwmxHb7pjZiqtp3147lQwE+TZElJNUfILAAkvSrluudeD0JkY9XrDZRYCa OwT3zU/ICTqKR2zlOqnjVGkDpGvjwaAzgmw18mMnoNYZWnpoCCc/XGByw2YYL42OJskY AsuhnZpxnBJ0CLjhkBrmS0lj8b0akLaGFT24gwbQtrCn0LGYo3uNor+1aSoH9nlhKu5Q L14Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=hYUPPntx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p26-20020a63741a000000b00563a8c6a843si3876397pgc.178.2023.07.24.16.41.34; Mon, 24 Jul 2023 16:41:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=hYUPPntx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230170AbjGXWOY (ORCPT + 99 others); Mon, 24 Jul 2023 18:14:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229789AbjGXWOW (ORCPT ); Mon, 24 Jul 2023 18:14:22 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60E2710EC; Mon, 24 Jul 2023 15:14:21 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4fdfefdf5abso463853e87.1; Mon, 24 Jul 2023 15:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690236859; x=1690841659; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yAsZdb1l2a00omNbaFLi6X9Z1M8KVaOQyZOE0+c0Tbc=; b=hYUPPntxc6s6ZI4Cv6z9ft0y9WjAHYLbjp4SyKtPI00sUEkmzSHvNUNDypAdtXKVn7 ynUhu6KxwYHAZvUCNW+2HRJbaTFRlavjUeajGgTnONjK0MlNiaz5r1Y/geWjqRs1Q1rq KwrxAF55ex3j2qhvNLaDm9k6H78/5KU79/fipttlxE9I422PoXt70UVSBB8ey9ClHTr9 9ju9MM0jTVFy/FPIdtBqZbEYxjJMe5861wtQvpkW/htfOqRfHjGj1vkujcN+phTOa2jY fZTh60p+kt1nY5Jw7Y9wBB39JPD2XHqJuHEefozlnjfVXVqWATdaczWsvYN0K1BsJrjl oReQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690236859; x=1690841659; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yAsZdb1l2a00omNbaFLi6X9Z1M8KVaOQyZOE0+c0Tbc=; b=WqFX6LQsYfSuSrr6XvjYZzBe014m1JPKaKXnvqiVW61njLo1htHYA91Aq0tjNHRjCr 8zfOxlCaNiKEWmi5/pEK+M2Dh2iu3g0GDaBhaslNy6NfTGvF9XVoUr2+n1fC8ec5hmBU mc8U6X9i8OwQ/7EUxrbXW6CodVWHVGzR9oM3TnDC4dF1ZBf7swhQyWxnCxdyXg9mxqk0 nPoeVu9PSij6Gicj072L+iNsSeQ8S4/FAJzWpIUtUusNt1nb2/mGLXbiZaTl1XxjoCHO GUsJiNg805RcJ/zjvX44UbNwpy3IHpSvaMsxerrM78JjsvJSCV322rna2u49mIFAuivD E8vA== X-Gm-Message-State: ABy/qLZiQVJxtoXTS3ao11ih01AewU1UhoABGiIiU8bWWsv8DBlL/DlM oiKNf6yZ4PDpwH5chYnWDwI= X-Received: by 2002:a05:6512:6d4:b0:4f9:58ed:7bba with SMTP id u20-20020a05651206d400b004f958ed7bbamr7337865lff.16.1690236859228; Mon, 24 Jul 2023 15:14:19 -0700 (PDT) Received: from localhost.localdomain ([77.222.25.78]) by smtp.gmail.com with ESMTPSA id v2-20020a056512048200b004fba077e654sm2401130lfq.194.2023.07.24.15.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 15:14:18 -0700 (PDT) From: Andrew Kanner 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: linux-kernel-mentees@lists.linuxfoundation.org, syzbot+f817490f5bd20541b90a@syzkaller.appspotmail.com, Andrew Kanner Subject: [PATCH 1/2] drivers: net: use xdp only inside tun_build_skb() Date: Tue, 25 Jul 2023 01:13:25 +0300 Message-Id: <20230724221326.384-1-andrew.kanner@gmail.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772347307750502866 X-GMAIL-MSGID: 1772347307750502866 Syzkaller reported the following issue: ======================================= Too BIG xdp->frame_sz = 131072 WARNING: CPU: 0 PID: 5020 at net/core/filter.c:4121 ____bpf_xdp_adjust_tail net/core/filter.c:4121 [inline] WARNING: CPU: 0 PID: 5020 at net/core/filter.c:4121 bpf_xdp_adjust_tail+0x466/0xa10 net/core/filter.c:4103 ... Call Trace: bpf_prog_4add87e5301a4105+0x1a/0x1c __bpf_prog_run include/linux/filter.h:600 [inline] bpf_prog_run_xdp include/linux/filter.h:775 [inline] bpf_prog_run_generic_xdp+0x57e/0x11e0 net/core/dev.c:4721 netif_receive_generic_xdp net/core/dev.c:4807 [inline] do_xdp_generic+0x35c/0x770 net/core/dev.c:4866 tun_get_user+0x2340/0x3ca0 drivers/net/tun.c:1919 tun_chr_write_iter+0xe8/0x210 drivers/net/tun.c:2043 call_write_iter include/linux/fs.h:1871 [inline] new_sync_write fs/read_write.c:491 [inline] vfs_write+0x650/0xe40 fs/read_write.c:584 ksys_write+0x12f/0x250 fs/read_write.c:637 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd frame_sz < PAGE_SIZE check was introduced in commit c8741e2bfe87 ("xdp: Allow bpf_xdp_adjust_tail() to grow packet size"). But tun_get_user() still provides an execution path to exceed XDP limits for packet size. The way to mitigate this is to reduce xdp to be used only in tun_build_skb(), without falling in tun_alloc_skb(), etc. Reported-and-tested-by: syzbot+f817490f5bd20541b90a@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/000000000000774b9205f1d8a80d@google.com/T/ Link: https://syzkaller.appspot.com/bug?id=5335c7c62bfff89bbb1c8f14cdabebe91909060f Signed-off-by: Andrew Kanner --- drivers/net/tun.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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. From patchwork Mon Jul 24 22:13:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Kanner X-Patchwork-Id: 125229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2138916vqg; Mon, 24 Jul 2023 17:24:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlFY/lujv+Uce/ui9qCNcF+0z6dJqHMlyZcfDkC+qey6pEFws7mpWI0L75D3lxrQPkpph9sL X-Received: by 2002:a17:907:1dc3:b0:991:ed4e:1c84 with SMTP id og3-20020a1709071dc300b00991ed4e1c84mr10156597ejc.25.1690244677639; Mon, 24 Jul 2023 17:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690244677; cv=none; d=google.com; s=arc-20160816; b=MDnAbF4CMfC/aK0yqawrSVrQKAbishFi2oWUvABJBimtJdFXQeAROc88Eet2sJfrXc 2CoSF+XO5OPEtGQ3IrcIMqSA7T15LhN5fpfwPw3XqF1oE8Qrlj1kkEArQeWlr9nlyDgX hkgOpv3nvxEoZm1ho5tzNZkxP8dg06bVHYMNClTOp4czNEBgll2Rq8GT1VE/D5830ble e4dEkCW1jlMho9r3igVVS6SfvNmqwQQ3FF90nkjEQuQwXU118bmlfgdgqEdVFwJDkfes OMbTwG4h42yTlNrFkNt18bJqCYyIjFSB8avj/tkKTk5XFvhmyWpiA/AzlfdoPhZjp4Eu B6ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VR5kr5/P9TZGbX0T3kYzKuPMSI9rX/Q6fFU/FogHPdo=; fh=neJKXSJhdh/dzWbfNkmI6hL7/RYA+C6ag08sPsn5SZA=; b=v8u1lYUWnrSU60FYBDeqJYLOTWkAMc9m9MvFOeWT7e0Pr5xDfRK7+gt99OJCE5KH+g GKVkj6b1vAytmu99bRU0ZVLJSg1ElsmEB7MCDn3fp/VN/nXAz8I3oI05OE1D7IhmhUPj CFErQk3E0lGhkgDzgUDKml/iMfz4DJa1GoX7ZxgIzs0zLdrgpEqHsEa1Ft0IFIH77K9J 9W9LxJTgHeRr91mtGrVxF6fizW0TnZiObbiO4FbNIbH1TpjDU67CITO5IEg86Xp/KFMx W29TBZLtq6+90d67bBBNS9MEM5cbEtBch1kJpv8O8l6F7pG9b/3foJcrqnc/rnPGavIb Vipg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=K7TpzLZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z26-20020a1709064e1a00b0099845f6579csi7129650eju.631.2023.07.24.17.24.14; Mon, 24 Jul 2023 17:24:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=K7TpzLZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230413AbjGXWPO (ORCPT + 99 others); Mon, 24 Jul 2023 18:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229789AbjGXWPL (ORCPT ); Mon, 24 Jul 2023 18:15:11 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 383F710CB; Mon, 24 Jul 2023 15:15:10 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2b95d5ee18dso71614301fa.1; Mon, 24 Jul 2023 15:15:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690236908; x=1690841708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VR5kr5/P9TZGbX0T3kYzKuPMSI9rX/Q6fFU/FogHPdo=; b=K7TpzLZSFTbsm+Zv7HTkwil6Z+M7WziaM9XD+4kQ3KbFBS+CPxNzQrS+qIdDt0xqjD ZhGlG7k4TswErdRWQr7kCaIbWRNbpdXCncvvhqnzcXjaYffiry/TwVlxasM+tMlTdHgr qv/H794OC21k3pldfu4o5v58DYcOGMwGjBqGDcATYR4s2vL/xxG0Zj+SZF7QW8RyVuYH gduR5At2PuMloDYbL/jjtySnPlkyb3YNhm89qFF68cu9gckTzkp5tboSnfRnAfmfUuxo lZHOf6lrOj+0h38jW1l+s+gB9LeY4cCWviRw1w+z3u23YshK5fPkSaE0SlbInmZmf2Ii bJQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690236908; x=1690841708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VR5kr5/P9TZGbX0T3kYzKuPMSI9rX/Q6fFU/FogHPdo=; b=KRUWh54Dr2fU/k4sokE/V7f9u+62lwpAbnL1PZxH+KdzrkoiBIOf2ypyL1gAcLe48i 5PKOKZOhb1KE5JExhC84/BASh9euNjugqD25nQcVHYBLZgFbXXUroTwXOkJvhzOmJKto hxhUYURcH6QHG5ME5QFZzdTiBa0lVae0i8L0UXdE8mglMS8V662ASa1YXHmLUs6wC12U QB6UvAWdV0q4b0ffiUdLG1guZclXjd/M5YsEQMV7cMXflPVdL0kXBahuH0b/zx7ghp8X mt5Avrsy0deVfODqXyk+Z8vu8OjUv35+JWGPOTEYuM5tsIbhRFlE4rW7I5hLLczrUP9Y BT8g== X-Gm-Message-State: ABy/qLYAGv0EKBN8wSN1CKiznm1TPLIx8Ix1501a7ByHIJ01+/Z1g6Hu E36wiyCKasvovHw4YLjJqFc= X-Received: by 2002:a05:6512:3b84:b0:4fd:f84f:a729 with SMTP id g4-20020a0565123b8400b004fdf84fa729mr3185178lfv.11.1690236908188; Mon, 24 Jul 2023 15:15:08 -0700 (PDT) Received: from localhost.localdomain ([77.222.25.78]) by smtp.gmail.com with ESMTPSA id v2-20020a056512048200b004fba077e654sm2401130lfq.194.2023.07.24.15.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 15:15:07 -0700 (PDT) From: Andrew Kanner 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: linux-kernel-mentees@lists.linuxfoundation.org, syzbot+f817490f5bd20541b90a@syzkaller.appspotmail.com, Andrew Kanner 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 Message-Id: <20230724221326.384-2-andrew.kanner@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230724221326.384-1-andrew.kanner@gmail.com> References: <20230724221326.384-1-andrew.kanner@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772350002811912621 X-GMAIL-MSGID: 1772350002811912621 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 --- 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;