From patchwork Thu Aug 3 18:59:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Kanner X-Patchwork-Id: 130857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1400392vqx; Thu, 3 Aug 2023 13:55:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlHG+lEj0Yv+Lq5YhabWKnGO2xJdk8X2r1zA3wjBLiXcHKAaFWdDgV2cqjb1egYZGK5st8ke X-Received: by 2002:a05:6808:1211:b0:3a1:d629:d1dd with SMTP id a17-20020a056808121100b003a1d629d1ddmr25590405oil.56.1691096152626; Thu, 03 Aug 2023 13:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691096152; cv=none; d=google.com; s=arc-20160816; b=oM5UbW5f3MluY8NFdUaDDooeXTYDIFhux/wkP8MbXU+L98+5ZUhrQ7pYhc9urcqQDK AmrdxZtvixJmWpjLdLsfVdU55CxDeLCbDFxL2MYhtILQlvmvGy6UM859Hp3hQJnZOMFi zMIRINFS1ngJlNvxJ/AneL4sRhkZIGxqbVhel97sFKM1uXdiDx7KZdKd2iAUZRntHJzT ZvGAR7v/5zPbfgOFNVlYSOiMfEqQR7WG0ByETccxSFE0nug4n+uYpiJpNBKAg/faYCZG 727zFB1o1q5ov1jpGAKU6HSVN5XuyIHe+9sQ9msJYx929FVMmSjqlM+gW7H5+htXgq35 AgwQ== 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=fpJNHhs8hGi2yDC45xTTVL8bPEioZdZntYr6lajc9vM=; fh=IF+y20gbIuOPMFnUD07j8ckGhRwRWHSdpdsouObJbDs=; b=w7RycDHuze/MBJHYzKnkSv+dnlYZxqM/5tXbjbGNdutLxTUoo4qWtP9mH1D+v1RZSL SGIBbROIKUjyqsaq+tH62I6fY/nHeWLT/VrxPGKXvQEkCL8uzmMP4NTVCuoegGCxRJtz cqRaQHfRx0cEE4BD2LqdTyhAHoLahgZuoJETRcIwpC9hixrEUJSmbwnOr+RP9PG84D70 DNQP3xr1ICStogJp19to4q+1kQZ05VCph5SBRiyoQbXRIOV4gYoL3V9Ey2l0YwtVV0Ho 4HRzkyNMce9obZYCNzC5+grMmKkFiYIlKhP+sSaWvam1r31eerE+mGYz+ZU5VKg+KGcG TY9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=k5NDFDrE; 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 y23-20020a631817000000b00563db158152si514228pgl.457.2023.08.03.13.55.38; Thu, 03 Aug 2023 13:55:52 -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=k5NDFDrE; 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 S230122AbjHCTAg (ORCPT + 99 others); Thu, 3 Aug 2023 15:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229822AbjHCTAe (ORCPT ); Thu, 3 Aug 2023 15:00:34 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B9802D45; Thu, 3 Aug 2023 12:00:30 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-99bed101b70so177599466b.3; Thu, 03 Aug 2023 12:00:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691089229; x=1691694029; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fpJNHhs8hGi2yDC45xTTVL8bPEioZdZntYr6lajc9vM=; b=k5NDFDrEg+9nNDfAkqK83fDOp8A5hffycEbrlbI1/HFSkoagQYZMmMPYLy72x3L1wF JTyYZl2/V9SuoMJt9V3F/7xfyxu01MSFXa2Xhu/TtBD6BVVPbIYsb+0cN3OSQ4ZzY7qV sLMQfRL+DlBOv9af5SFsYVhKt8Yrf8E+RH9PvIzTXoXF5B3MwM01l3mdjlPDFa94T/5x XIi4lG512p/FVDpSvNiARyeXHw50IbimFnqlTAn/a/o63GlyqwYjJBdWDdtAbFGbfknY PcDd53ab0QCfjsii/z7pcosDnLaQrDL9LBgq9QPpZCYn7XUPYkMAEojnEN9BefiQyZTN 77Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691089229; x=1691694029; 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=fpJNHhs8hGi2yDC45xTTVL8bPEioZdZntYr6lajc9vM=; b=hliGL4XMG/izhD1vc88sC/3AMnwPi5BEVOqy0h4xklm+8uTHpXUUSmaI887BJ3NK6O 1AqKAN1wkmWx2kB9NbYCg+ps2kSh3VQW3hWkJdJTLrPZa35lYYRdmv9F6pfPjib7Hb+U aBKr9nAvXdgQ8QhHx7s8I339UDOM8SEM/Q9Y1nJhAvRBV3P4TgsJZWbNVzU+7RwIy3LK kv5cWVi9MUJbRCNAAIZ25z6bX7KUhOHrTIveyi5MJLqG6IkArDPPWlF+vEZybeEjHdfk NFN80W/o8p28qraKQ4CgF68RmOMK/UW4a2GTBAZXpusFrxU8y92fjI/6bADEjPe4Av5N EVTQ== X-Gm-Message-State: ABy/qLaQCra+qoNC0DaP69C/xqa1EVABm1BOEeUnSpJuE8ckWQ29PXV0 6kbzbVSNNmr10KayXSenttw= X-Received: by 2002:a17:906:20d9:b0:994:47a0:c730 with SMTP id c25-20020a17090620d900b0099447a0c730mr8455282ejc.43.1691089228564; Thu, 03 Aug 2023 12:00:28 -0700 (PDT) Received: from dev7.kernelcare.com ([2a01:4f8:201:23::2]) by smtp.gmail.com with ESMTPSA id d13-20020a1709063ecd00b00992a8a54f32sm182939ejj.139.2023.08.03.12.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 12:00:27 -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, hawk@kernel.org, jbrouer@redhat.com, dsahern@gmail.com, john.fastabend@gmail.com, linux-kernel@vger.kernel.org Cc: linux-kernel-mentees@lists.linuxfoundation.org, syzbot+f817490f5bd20541b90a@syzkaller.appspotmail.com, Andrew Kanner Subject: [PATCH net-next v5 1/2] drivers: net: prevent tun_build_skb() to exceed the packet size limit Date: Thu, 3 Aug 2023 20:59:48 +0200 Message-Id: <20230803185947.2379988-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_BLOCKED,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: 1773067528619337198 X-GMAIL-MSGID: 1773242839317740558 Using the 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(). This may end up with exceeding the PAGE_SIZE limit in tun_build_skb(). Jason Wang proposed to count XDP_PACKET_HEADROOM always (e.g. without rcu_access_pointer(tun->xdp_prog)) in tun_can_build_skb() since there's a window during which XDP program might be attached between tun_can_build_skb() and tun_build_skb(). Fixes: 7df13219d757 ("tun: reserve extra headroom only when XDP is set") Link: https://syzkaller.appspot.com/bug?extid=f817490f5bd20541b90a Signed-off-by: Andrew Kanner --- Notes (akanner): v5: - always count XDP_PACKET_HEADROOM in tun_can_build_skb() as there's a window between tun_can_build_skb() and tun_build_skb() and XDP program might be attached there. - rcu_read_lock/unlock() for tun->xdp_prog were completely removed and there's no need to use rcu_access_pointer() instead which was noted by David Ahern . v4: https://lore.kernel.org/all/20230801220710.464-1-andrew.kanner@gmail.com/T/ - fall back to v1, fixing only missing XDP_PACKET_HEADROOM in pad and removing bpf_xdp_adjust_tail() check for frame_sz. - added rcu read lock, noted by Jason Wang in v1 - I decided to leave the packet length check in tun_can_build_skb() instead of moving to tun_build_skb() suggested by Jason Wang . Otherwise extra packets will be dropped without falling back to tun_alloc_skb(). And in the discussion of v3 Jesper Dangaard Brouer noticed that XDP is ok with a higher order pages if it's a contiguous physical memory allocation, so falling to tun_alloc_skb() -> do_xdp_generic() should be ok. v3: https://lore.kernel.org/all/20230725155403.796-1-andrew.kanner@gmail.com/T/ - attach the forgotten changelog v2: https://lore.kernel.org/all/20230725153941.653-1-andrew.kanner@gmail.com/T/ - merged 2 patches in 1, fixing both issues: WARN_ON_ONCE with syzkaller repro and missing XDP_PACKET_HEADROOM in pad - changed the title and description of the execution path, suggested by Jason Wang - move the limit check from tun_can_build_skb() to tun_build_skb() to remove duplication and locking issue, and also drop the packet in case of a failed check - noted by Jason Wang v1: https://lore.kernel.org/all/20230724221326.384-1-andrew.kanner@gmail.com/T/ drivers/net/tun.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 25f0191df00b..100339bc8b04 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1594,7 +1594,7 @@ 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) + + if (SKB_DATA_ALIGN(len + TUN_RX_PAD + XDP_PACKET_HEADROOM) + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) > PAGE_SIZE) return false; From patchwork Thu Aug 3 19:03:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Kanner X-Patchwork-Id: 130866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1410470vqx; Thu, 3 Aug 2023 14:15:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlFakOcGrb/dbU7qhcpeXQf/bgHRQjtqPAAhpOsDWRpVj1stH2cronyJvUWXHnBq6b+qqBxA X-Received: by 2002:a05:6402:1252:b0:51d:91ef:c836 with SMTP id l18-20020a056402125200b0051d91efc836mr8353515edw.32.1691097354288; Thu, 03 Aug 2023 14:15:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691097354; cv=none; d=google.com; s=arc-20160816; b=CnLj8zshm+rA6VmiHY4/Swiqg0gagkzm+vhz3bp5epJ4S11InZFp1PlRJ4SBbKBV+O l/C87wDcYNtNx60AOtKLdUsSde/zn9cd1QVha9gdUNV1GNqCREiV5s4hc1Y/FYghKN// oA9CusnLSLYJGsSpBbfYbWwTipJxJa1UV1Q/oYFHCdD2YvnE1xhb3Bn83oZrevkUBKRM BtZdLsbtDJZ7b2H1jAvgqoZz3CIzjcL4rzw3bZGDY4brNaQCXQVBXAPqAFi47qL1nVp0 kHC2qB8vZltn5zdQYmOV6UepS8ZuHvOZf8tCPwhQWo8OfR5Zb5UUn221NBsLSQ1wjKl7 5u4Q== 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=OjWDL2QftxnG9c5+Vha2qoI437XfBQWXN8yDWNa47PQ=; fh=t3YAuBSfWCTrdPjuQ+/476dwMGuXKwGa4i0aCv+FZLs=; b=WX1bL5IjLxRTE36AwQLNput51baHTyZYCrx8szl+cgH8VOL0ZHQ4O0dKEyT56e32+x VplweqRvq3xQbN3bdNW30PyTtHtTqEzYRquJBGAjUUcyE4Xvq4KOKJMDIZfryLaNHb2g Fz5Qi2RbRf9wQl1EOs8999hEob+RNBoDxxLP76Lqq8JmXMOkXGt7cLaD7l6uv5Wv5hvu fIA7qDVHzEPliUMKCG9Xv/OV/dh5hD++oK/Dpa1Q6DLY+nM5rXsy1Di+8NWCKB99CarM n9VAEvG23xPRCL9FLq7coL9fdujc10+e1TbHRtlxw1okZ87N88kJsCZhF51tZh+wjl9j /lLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mV4KTN0y; 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 m7-20020aa7d347000000b005223789d9e9si399089edr.382.2023.08.03.14.15.31; Thu, 03 Aug 2023 14:15:54 -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=mV4KTN0y; 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 S229618AbjHCTFl (ORCPT + 99 others); Thu, 3 Aug 2023 15:05:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231765AbjHCTF1 (ORCPT ); Thu, 3 Aug 2023 15:05:27 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E17143A93; Thu, 3 Aug 2023 12:04:49 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5230f8da574so1159539a12.3; Thu, 03 Aug 2023 12:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691089488; x=1691694288; 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=OjWDL2QftxnG9c5+Vha2qoI437XfBQWXN8yDWNa47PQ=; b=mV4KTN0ysT5hTWu9K8Zc31QqIGOV7LQ1dwH4El6DJSEHE1FtI7dZUuEczg74YLrZOT 0EgbOxFz3pD9xeAK9hkbHYdc8Xx8xR/Jo2aomITNvTm6y5PWIfWVNZ7l789Ld8GZfjkn cp4c/v4/D4O4XC6+Vv7CEJUb/sh3D+as1ZZeJUk3990UkQT0Oimc1u4ElS7CwkE8Mitx wdGw5o06v4xn2IF1MTnG1qHGxULGuI60c4DVaUMCJe2mKVippAQQW2EH3ek6G/QW+Z7p 9OK01xzemoCiwbDcj3oFZwFVfOHejPB+7PLomRQ4Iir8StXjxNo+DnXSjRaLPwgcbKB0 KM1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691089488; x=1691694288; 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=OjWDL2QftxnG9c5+Vha2qoI437XfBQWXN8yDWNa47PQ=; b=N7gXFKXhB7defZ4+7b6SbBBp9LJCsrY9V2FfA0YJV+bUVOhfpscORrh0i1u7LNSzeo 3XSCAkXSwwLjcP+XhW7TpB6fMO7CDBrCudlPuFNrmtuh5UGwCR8h1uotdyaiK/rwKnhY ABTKlRNlrj3632GgO055rTZMnM+ZX/VuFRb4bv/x5Cazdo+TkKm+0FZiS2uV9bX7bjXG EkUOT8UttUaIwWVN+yDC3FxTjFtcyr2V01itaGrLgBvkMKQm1+ehXdtfnQnCT3o4D9JA uUofZtuOUAXJPm6710j0pJdG7YQaxt3hcM6vOME9fvWoeWdIgoeTiA1F4jwKJwZS0400 onbg== X-Gm-Message-State: ABy/qLYIQySqtHb5EIjN5qu3W14DI8/Q8LasK7MSSDWiIw5s96/gW4vh n+6yTR27tzOpDar7YXy2BwA= X-Received: by 2002:aa7:c251:0:b0:522:3410:de23 with SMTP id y17-20020aa7c251000000b005223410de23mr7929054edo.3.1691089487896; Thu, 03 Aug 2023 12:04:47 -0700 (PDT) Received: from dev7.kernelcare.com ([2a01:4f8:201:23::2]) by smtp.gmail.com with ESMTPSA id g8-20020a056402180800b005227ead61d0sm158232edy.83.2023.08.03.12.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 12:04:47 -0700 (PDT) From: Andrew Kanner To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mw@semihalf.com, shayagr@amazon.com, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jasowang@redhat.com, hawk@kernel.org, jbrouer@redhat.com, dsahern@gmail.com, john.fastabend@gmail.com, linux-kernel-mentees@lists.linuxfoundation.org, syzbot+f817490f5bd20541b90a@syzkaller.appspotmail.com, Andrew Kanner Subject: [PATCH net-next v5 2/2] net: core: remove unnecessary frame_sz check in bpf_xdp_adjust_tail() Date: Thu, 3 Aug 2023 21:03:18 +0200 Message-Id: <20230803190316.2380231-1-andrew.kanner@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230803185947.2379988-1-andrew.kanner@gmail.com> References: <20230803185947.2379988-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_BLOCKED,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: 1773244099464051519 X-GMAIL-MSGID: 1773244099464051519 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 xdp->frame_sz > PAGE_SIZE check was introduced in commit c8741e2bfe87 ("xdp: Allow bpf_xdp_adjust_tail() to grow packet size"). But Jesper Dangaard Brouer noted that after introducing the xdp_init_buff() which all XDP driver use - it's safe to remove this check. The original intend was to catch cases where XDP drivers have not been updated to use xdp.frame_sz, but that is not longer a concern (since xdp_init_buff). Running the initial syzkaller repro it was discovered that the contiguous physical memory allocation is used for both xdp paths in tun_get_user(), e.g. tun_build_skb() and tun_alloc_skb(). It was also stated by Jesper Dangaard Brouer that XDP can work on higher order pages, as long as this is contiguous physical memory (e.g. a page). 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?extid=f817490f5bd20541b90a Link: https://lore.kernel.org/all/20230725155403.796-1-andrew.kanner@gmail.com/T/ Fixes: 43b5169d8355 ("net, xdp: Introduce xdp_init_buff utility routine") Signed-off-by: Andrew Kanner Acked-by: Jesper Dangaard Brouer Acked-by: Jason Wang --- Notes (akanner): v5: - same as v4, but cc-ed bpf@vger.kernel.org according to v3->v4 change v4: https://lore.kernel.org/all/20230801220710.464-1-andrew.kanner@gmail.com/T/ - remove bpf_xdp_adjust_tail() check for frame_sz instead. v3: https://lore.kernel.org/all/20230725155403.796-1-andrew.kanner@gmail.com/T/ v2: https://lore.kernel.org/all/20230725153941.653-1-andrew.kanner@gmail.com/T/ v1: https://lore.kernel.org/all/20230724221326.384-1-andrew.kanner@gmail.com/T/ - initial attempts to fix drivers/net/tun.c:tun_get_user(), e.g. tun_build_skb() or tun_alloc_skb(), to not exceed xdp->frame_sz check from net/core/filter.c net/core/filter.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 06ba0e56e369..28a59596987a 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4116,12 +4116,6 @@ BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset) if (unlikely(data_end > data_hard_end)) return -EINVAL; - /* ALL drivers MUST init xdp->frame_sz, chicken check below */ - if (unlikely(xdp->frame_sz > PAGE_SIZE)) { - WARN_ONCE(1, "Too BIG xdp->frame_sz = %d\n", xdp->frame_sz); - return -EINVAL; - } - if (unlikely(data_end < xdp->data + ETH_HLEN)) return -EINVAL;