From patchwork Thu Mar 10 22:56:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12776990 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15332C433FE for ; Thu, 10 Mar 2022 22:56:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231816AbiCJW5j (ORCPT ); Thu, 10 Mar 2022 17:57:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232738AbiCJW5i (ORCPT ); Thu, 10 Mar 2022 17:57:38 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EED241986FF for ; Thu, 10 Mar 2022 14:56:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646952996; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SfOk1zwO0CCu7UnUHNMnpLnqee7NGxIZY+rGqvasiEM=; b=GAqmDUB26yf7Y+Ejht+Elkv3Jo1GJYT4bmDe9D1oCNiBx/YhV+hj0EhWT0+QNmLSIpE7K7 xBCOjMXO2et1FbrcR7merV+y439dAWlfM8FE0CS2qIxWhVUsBhBsb9POWlDi94s8fahOhi hTnNETs6QpcfIxdX/m79Wnw4ICYQHoQ= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-497-CRm2qFAbNbadXoM61G_S_Q-1; Thu, 10 Mar 2022 17:56:34 -0500 X-MC-Unique: CRm2qFAbNbadXoM61G_S_Q-1 Received: by mail-ed1-f71.google.com with SMTP id da28-20020a056402177c00b00415ce4b20baso3879365edb.17 for ; Thu, 10 Mar 2022 14:56:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SfOk1zwO0CCu7UnUHNMnpLnqee7NGxIZY+rGqvasiEM=; b=ruKBEgtGa8caEDV6H9VnO2ffYkCilI0pchtTy4ravODHBm8aXo8bMDBsT+3me+Io9q f1/1jXvtDC9ggfR4WBLsazH/C1GMWLCFUJ0xksgSpVfYxnL2KXcvD5G5KY41LZwhJmi/ rWcg4LoLGTelj6C0RaV+aLFaquG9lmEbK6oQr8GGMUSn2U97Ba9STld2sxCK2t6tcwW+ +FEaQGW07VtW6VpVRne2r6jua+REhxhR8n9uus/VHV5ht43vhUcjdE5am8NK9E5fTTVu 2OsdNqi0QxaFKf9UwXnKKcHW+HWQMTudTrb10xwfLJ20NZ3tmTXqQIF3cMjRkAFFTXpq xyvQ== X-Gm-Message-State: AOAM530q5IdEpUiCY5warnyKk4MhLsx6Oyny3Xla4Lst+R9x4T79+IKz C/JT8J+FRLYzLu3mDhnnEovao+YqBqAuq82VoYoONgf6lmkXaJcmeN9+ACiJYHtp8rnm58ORl2Z U1JvhxIjP3oJmOlVr X-Received: by 2002:a17:906:1e42:b0:6d6:df12:7f8d with SMTP id i2-20020a1709061e4200b006d6df127f8dmr6385694ejj.15.1646952993105; Thu, 10 Mar 2022 14:56:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJx33hGechmaR55dBTCvCwglt6UpEpp4eC/uQzhRk4p0Bukj3NBZ9jh5bzbm2BhY8X2MykqW1w== X-Received: by 2002:a17:906:1e42:b0:6d6:df12:7f8d with SMTP id i2-20020a1709061e4200b006d6df127f8dmr6385662ejj.15.1646952992672; Thu, 10 Mar 2022 14:56:32 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id y18-20020a056402271200b0041697d1a691sm2501142edd.33.2022.03.10.14.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 14:56:32 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 8B5DF1A89A1; Thu, 10 Mar 2022 23:56:31 +0100 (CET) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= Cc: syzbot+0e91362d99386dc5de99@syzkaller.appspotmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf-next 1/2] bpf, test_run: Fix packet size check for live packet mode Date: Thu, 10 Mar 2022 23:56:20 +0100 Message-Id: <20220310225621.53374-1-toke@redhat.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The live packet mode uses some extra space at the start of each page to cache data structures so they don't have to be rebuilt at every repetition. This space wasn't correctly accounted for in the size checking of the arguments supplied to userspace. In addition, the definition of the frame size should include the size of the skb_shared_info (as there is other logic that subtracts the size of this). Together, these mistakes resulted in userspace being able to trip the XDP_WARN() in xdp_update_frame_from_buff(), which syzbot discovered in short order. Fix this by changing the frame size define and adding the extra headroom to the bpf_prog_test_run_xdp() function. Also drop the max_len parameter to the page_pool init, since this is related to DMA which is not used for the page pool instance in PROG_TEST_RUN. Reported-by: syzbot+0e91362d99386dc5de99@syzkaller.appspotmail.com Fixes: b530e9e1063e ("bpf: Add "live packet" mode for XDP in BPF_PROG_RUN") Signed-off-by: Toke Høiland-Jørgensen Acked-by: Martin KaFai Lau --- net/bpf/test_run.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 24405a280a9b..e7b9c2636d10 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -112,8 +112,7 @@ struct xdp_test_data { u32 frame_cnt; }; -#define TEST_XDP_FRAME_SIZE (PAGE_SIZE - sizeof(struct xdp_page_head) \ - - sizeof(struct skb_shared_info)) +#define TEST_XDP_FRAME_SIZE (PAGE_SIZE - sizeof(struct xdp_page_head)) #define TEST_XDP_MAX_BATCH 256 static void xdp_test_run_init_page(struct page *page, void *arg) @@ -156,7 +155,6 @@ static int xdp_test_run_setup(struct xdp_test_data *xdp, struct xdp_buff *orig_c .flags = 0, .pool_size = xdp->batch_size, .nid = NUMA_NO_NODE, - .max_len = TEST_XDP_FRAME_SIZE, .init_callback = xdp_test_run_init_page, .init_arg = xdp, }; @@ -1230,6 +1228,8 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr, batch_size = NAPI_POLL_WEIGHT; else if (batch_size > TEST_XDP_MAX_BATCH) return -E2BIG; + + headroom += sizeof(struct xdp_page_head); } else if (batch_size) { return -EINVAL; } From patchwork Thu Mar 10 22:56:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12776991 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39716C433F5 for ; Thu, 10 Mar 2022 22:57:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344503AbiCJW5r (ORCPT ); Thu, 10 Mar 2022 17:57:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344496AbiCJW5k (ORCPT ); Thu, 10 Mar 2022 17:57:40 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B64EC198D0E for ; Thu, 10 Mar 2022 14:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646952997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X+C4z+W6JKvW1PkIKtt/f0rXq2MGC/kPw7Xm7/uk89s=; b=FjZelZNX4hNp2TNws2K2Hojj4QyhC76VuUJEYSjNLMLFnEdJyHslxeUCfGwO7dzH89Vnya Q2OtKXlnqbmsMFlTVkZtl/hhepHNFibb+tdFfh/bIPg2eSwX8f1O5KDyzry5qornzSofc6 q+pQBqXt1zCk7xC2tqeNPjg0zE5eGCE= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-251-QQgq5ivnPwOF-VkIM8Ak6w-1; Thu, 10 Mar 2022 17:56:36 -0500 X-MC-Unique: QQgq5ivnPwOF-VkIM8Ak6w-1 Received: by mail-ej1-f70.google.com with SMTP id le4-20020a170907170400b006dab546bc40so3885337ejc.15 for ; Thu, 10 Mar 2022 14:56:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X+C4z+W6JKvW1PkIKtt/f0rXq2MGC/kPw7Xm7/uk89s=; b=pMhs+Gfm2dzdI7uPXbVgZES7xv+lxJN+T9zK8Sh8+EdN8VKIzCyB8p9AbORb/b46j+ VIUNBY3ca03ig6ciSKthwdbWeaG+xY/xif9G7cfIcRlecn1gXaDZv0Stzi34vcz5yPn7 IZbm16rtBUPJUeZmavDPq2WVVro4J3ZQoeNjoPTNbsIAs5lIdxzCGPBA4/wnvNxKCbwF n9mvJcaLFasrBwiskwJsgNqQ+JVN3aBsD2e4OD8VlL5XvVi0k3RfUMBCRBgmUjb2PICC QYM4G6/5PHQgo9cGSnCMSVzaS5HpWSKr5OQwQ5tdzcMEmNANg/TXhA8bY88+dTV3sa9K K3pQ== X-Gm-Message-State: AOAM530vIix4hzx56/ZWk6CuN+xreOfJoWYrS0HA7yjr6lY1+89by37k cfBK6hd4Zj6v+6bhF2D98WLUZCjsZi+kgbPICy3b+Ebycw4WKRBd3EIC/YXg7PZdDHJtYFqCa8A LcbtkxvBlU3RKe8wY X-Received: by 2002:a17:907:da4:b0:6da:7952:ccd2 with SMTP id go36-20020a1709070da400b006da7952ccd2mr6015465ejc.763.1646952993991; Thu, 10 Mar 2022 14:56:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsZOomQyju/SgppJIjOpLtra7yrnPadi1K+LnceE/3q023DlNqyHtR4F2O64IOpBOAZBUmdA== X-Received: by 2002:a17:907:da4:b0:6da:7952:ccd2 with SMTP id go36-20020a1709070da400b006da7952ccd2mr6015421ejc.763.1646952992959; Thu, 10 Mar 2022 14:56:32 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id g16-20020a170906521000b006d58773e992sm2259017ejm.188.2022.03.10.14.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 14:56:32 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id C34181A89A3; Thu, 10 Mar 2022 23:56:31 +0100 (CET) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh Cc: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Shuah Khan , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf-next 2/2] selftests/bpf: Add a test for maximum packet size in xdp_do_redirect Date: Thu, 10 Mar 2022 23:56:21 +0100 Message-Id: <20220310225621.53374-2-toke@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310225621.53374-1-toke@redhat.com> References: <20220310225621.53374-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This adds an extra test to the xdp_do_redirect selftest for XDP live packet mode, which verifies that the maximum permissible packet size is accepted without any errors, and that a too big packet is correctly rejected. Signed-off-by: Toke Høiland-Jørgensen Acked-by: Martin KaFai Lau --- .../bpf/prog_tests/xdp_do_redirect.c | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c index 9926b07e38c8..a50971c6cf4a 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c @@ -62,6 +62,28 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int fd) return 0; } +/* The maximum permissible size is: PAGE_SIZE - sizeof(struct xdp_page_head) - + * sizeof(struct skb_shared_info) - XDP_PACKET_HEADROOM = 3368 bytes + */ +#define MAX_PKT_SIZE 3368 +static void test_max_pkt_size(int fd) +{ + char data[MAX_PKT_SIZE + 1] = {}; + int err; + DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, + .data_in = &data, + .data_size_in = MAX_PKT_SIZE, + .flags = BPF_F_TEST_XDP_LIVE_FRAMES, + .repeat = 1, + ); + err = bpf_prog_test_run_opts(fd, &opts); + ASSERT_OK(err, "prog_run_max_size"); + + opts.data_size_in += 1; + err = bpf_prog_test_run_opts(fd, &opts); + ASSERT_EQ(err, -EINVAL, "prog_run_too_big"); +} + #define NUM_PKTS 10000 void test_xdp_do_redirect(void) { @@ -167,6 +189,8 @@ void test_xdp_do_redirect(void) ASSERT_EQ(skel->bss->pkts_seen_zero, 2, "pkt_count_zero"); ASSERT_EQ(skel->bss->pkts_seen_tc, NUM_PKTS - 2, "pkt_count_tc"); + test_max_pkt_size(bpf_program__fd(skel->progs.xdp_count_pkts)); + out_tc: bpf_tc_hook_destroy(&tc_hook); out: