From patchwork Mon Sep 6 08:56:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jussi Maki X-Patchwork-Id: 12476701 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 478C9C433EF for ; Mon, 6 Sep 2021 08:57:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 308926101C for ; Mon, 6 Sep 2021 08:57:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241045AbhIFI6n (ORCPT ); Mon, 6 Sep 2021 04:58:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241209AbhIFI6M (ORCPT ); Mon, 6 Sep 2021 04:58:12 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AD05C0613CF for ; Mon, 6 Sep 2021 01:57:07 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id o39-20020a05600c512700b002e74638b567so4225448wms.2 for ; Mon, 06 Sep 2021 01:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=axu/h3QQb94/dtjp6k6opc3V9u9UhFdRdW3Ivohfazc=; b=N74WNe8Oe9dFOnNDZI/aQT/qUdOUTPRCyGqxVZgxig1Y/36mnwEZ8jrflR28sJCawJ bcyxco3io1D69qygPQc85hWAwbgvP2inytm2XP8lv9N+XRg7+Gg0FUmcdNR7vodjiXOa X+eVDyHes2mFgWIIss1CD7AYE9TcfXGehTrNIdFDSnYrqKXTG5NnW1WBhSz6myhClDzl BZUuNyORVbCExCrJp+x383xS+Xn9pmy6qFj9+XLmtOUWo7sjWzUXWEKTPocw397uHQf5 rTK7oYepbdDxM29qAC0Apm/QEsor6gLP6XXQg/7JVUCHW+e2ylY0l2VtBXOaoPVs+Tcz 6FxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=axu/h3QQb94/dtjp6k6opc3V9u9UhFdRdW3Ivohfazc=; b=g1Q2zmexqJR0Se2Wd5UkJ+RHwYGQgWPUoYlLzk6SNUUcVPmvFIsGF3C5A46njwdkBg 217k8yb2iJxpYBbh51StTNe3km4KBXnOVAtokhIvwR6x/HQamE+n9KaLFqsQg72D5N6d eMR8K1n+U1qPkKO/AkvMzvNvDo8GSeNqQDRiLn3cIPKyTWnGCCL3ug4skuZGoWXMAdTb ncrLgYrv1cURBDdj53+eTCfJaOGTdUAulVLBHwpJgB2uJ0XsR+UG+lELhxz3Nomy78ix ej0X062+rvoPUhOpAsR33o6p7yqAgjuvI0N9rl+wjnzobHuaWDNKRLVzCniK82MAwRXj FlEQ== X-Gm-Message-State: AOAM530xEXGdx7qpd8075Kl/pInFLjbO4ooyVOmU5okxT+EIpRFurtkX wJBkcjg40e2xFhvU0lfujryLjdyxuppPcgM= X-Google-Smtp-Source: ABdhPJy9GBEScWIGRu/xTrBJ3zeq5rt4O4Ipd1mT92KohpRImY9sfxNstQWG+EsvvRrpzNwEZP6C1w== X-Received: by 2002:a05:600c:1914:: with SMTP id j20mr9929283wmq.25.1630918625779; Mon, 06 Sep 2021 01:57:05 -0700 (PDT) Received: from devaron.home ([2001:1620:5107:0:f22f:74ff:fe62:384a]) by smtp.gmail.com with ESMTPSA id x9sm6523071wmi.30.2021.09.06.01.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 01:57:05 -0700 (PDT) From: Jussi Maki To: netdev@vger.kernel.org Cc: ardb@kernel.org, jbaron@akamai.com, peterz@infradead.org, rostedt@goodmis.org, jpoimboe@redhat.com, Daniel Borkmann , Jussi Maki , syzbot+30622fb04ddd72a4d167@syzkaller.appspotmail.com Subject: [PATCH net 1/2] bonding: Fix negative jump label count on nested bonding Date: Mon, 6 Sep 2021 10:56:37 +0200 Message-Id: <20210906085638.1027202-2-joamaki@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210906085638.1027202-1-joamaki@gmail.com> References: <20210906085638.1027202-1-joamaki@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org With nested bonding devices the nested bond device's ndo_bpf was called without a program causing it to decrement the static key without a prior increment leading to negative count. Fix the issue by 1) only calling slave's ndo_bpf when there's a program to be loaded and 2) only decrement the count when a program is unloaded. Fixes: 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver") Reported-by: syzbot+30622fb04ddd72a4d167@syzkaller.appspotmail.com Signed-off-by: Jussi Maki --- drivers/net/bonding/bond_main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index b0966e733926..ae155b284f94 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -2169,7 +2169,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, res = -EOPNOTSUPP; goto err_sysfs_del; } - } else { + } else if (bond->xdp_prog) { struct netdev_bpf xdp = { .command = XDP_SETUP_PROG, .flags = 0, @@ -5224,13 +5224,12 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog, bpf_prog_inc(prog); } - if (old_prog) - bpf_prog_put(old_prog); - - if (prog) + if (prog) { static_branch_inc(&bpf_master_redirect_enabled_key); - else + } else if (old_prog) { + bpf_prog_put(old_prog); static_branch_dec(&bpf_master_redirect_enabled_key); + } return 0; From patchwork Mon Sep 6 08:56:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jussi Maki X-Patchwork-Id: 12476703 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF11FC433EF for ; Mon, 6 Sep 2021 08:57:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97ECE60232 for ; Mon, 6 Sep 2021 08:57:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240117AbhIFI6t (ORCPT ); Mon, 6 Sep 2021 04:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241237AbhIFI6d (ORCPT ); Mon, 6 Sep 2021 04:58:33 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89CD9C0613D9 for ; Mon, 6 Sep 2021 01:57:08 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id e26so4022987wmk.2 for ; Mon, 06 Sep 2021 01:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xsAUnpvsjZoOrIdtLj1lOTplaQwx8CEaSB4LOfRqAYI=; b=lXqsayYxzuke3KOcmbfHR5ukxITid6ppOxFdpJEkDrA3VzpaoODqZV0Ih2A6sTie7z wbEcIENvN3goy4O40nCB0midCbTFiQAH7iNV+kjcRaMQ9/DxMQU6VPTEHpTPoZZqT4b6 NH5ktTMifI2WIjtec6NmyyZrtW+7GO6usTJlW28+jdnuTokXSpEO3j4el2qMiRNSHwTa nCgKSPeYPU3o8K4Synw3bIyLksxVvyFCeqRI10uGg+A3S2IqIyVgvOe5m6YMtRwj8GuF ArQgX2uHcIry/DCAxz0uFXxcQehlmPXT6L8XbSfhEJDW3X+uiCPq+uko+vQwrVZG5dup EBRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xsAUnpvsjZoOrIdtLj1lOTplaQwx8CEaSB4LOfRqAYI=; b=F3S6tKXL0ww6BdWHYwpSqROn/tiInSJ9YycimB/92LvvKHQxEpPG4D54S7L6zfytPp uIr3Rx4cEdY2cM4ha95YCOf5w2JAuHjINHGdiihU70Ghai2vt4uj+9PzMQQvJmrIJURe 0aeuXXGMlWC98GcvsvcRsBvsnMNBpYc2t/gQcUDz2uYbWKfHtgz6A++YY3pVRAvyTwDl mkD2f3r4mN+p6q5koIKQoqf2Nhct0efluAIUCkGi9/yTiY8sZGWdd7WvWeg0sqW1Fzd1 cZK19LjKO87tWjE0sde5HUJFD8I3dr5thegl85E/6itr2zli+GSQRSIQFb7k2SP31+iw SRrQ== X-Gm-Message-State: AOAM5327yXrDsyP1cbsTzBcIIYqvDvNbovG8BcyuL87TiRyNHsFa/vOz hQLsPZnHY3NN0gM4/Or+7Y4HZREPJ2+tDuw= X-Google-Smtp-Source: ABdhPJzdtafQgwMIsQrXtFHIQNWyzMVVIcvQ6Cu/dlApD8yW+JC7OpL1/RSVy/agLwoHAgyRQlDE2w== X-Received: by 2002:a05:600c:3b15:: with SMTP id m21mr10193270wms.162.1630918626772; Mon, 06 Sep 2021 01:57:06 -0700 (PDT) Received: from devaron.home ([2001:1620:5107:0:f22f:74ff:fe62:384a]) by smtp.gmail.com with ESMTPSA id x9sm6523071wmi.30.2021.09.06.01.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 01:57:06 -0700 (PDT) From: Jussi Maki To: netdev@vger.kernel.org Cc: ardb@kernel.org, jbaron@akamai.com, peterz@infradead.org, rostedt@goodmis.org, jpoimboe@redhat.com, Daniel Borkmann , Jussi Maki Subject: [PATCH net 2/2] selftests/bpf: Test XDP bonding nest and unwind Date: Mon, 6 Sep 2021 10:56:38 +0200 Message-Id: <20210906085638.1027202-3-joamaki@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210906085638.1027202-1-joamaki@gmail.com> References: <20210906085638.1027202-1-joamaki@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Modify the test to check that enslaving a bond slave with a XDP program is now allowed. Extend attach test to exercise the program unwinding in bond_xdp_set and add a new test for loading XDP program on doubly nested bond device to verify that static key incr/decr is correct. Signed-off-by: Jussi Maki --- .../selftests/bpf/prog_tests/xdp_bonding.c | 74 ++++++++++++++++--- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c index 370d220288a6..ad3ba81b4048 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c @@ -384,8 +384,7 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons) { struct bpf_link *link = NULL; struct bpf_link *link2 = NULL; - int veth, bond; - int err; + int veth, bond, err; if (!ASSERT_OK(system("ip link add veth type veth"), "add veth")) goto out; @@ -399,22 +398,18 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons) if (!ASSERT_GE(bond, 0, "if_nametoindex bond")) goto out; - /* enslaving with a XDP program loaded fails */ + /* enslaving with a XDP program loaded is allowed */ link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, veth); if (!ASSERT_OK_PTR(link, "attach program to veth")) goto out; err = system("ip link set veth master bond"); - if (!ASSERT_NEQ(err, 0, "attaching slave with xdp program expected to fail")) + if (!ASSERT_OK(err, "set veth master")) goto out; bpf_link__destroy(link); link = NULL; - err = system("ip link set veth master bond"); - if (!ASSERT_OK(err, "set veth master")) - goto out; - /* attaching to slave when master has no program is allowed */ link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, veth); if (!ASSERT_OK_PTR(link, "attach program to slave when enslaved")) @@ -434,8 +429,26 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons) goto out; /* attaching to slave not allowed when master has program loaded */ - link2 = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond); - ASSERT_ERR_PTR(link2, "attach program to slave when master has program"); + link2 = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, veth); + if (!ASSERT_ERR_PTR(link2, "attach program to slave when master has program")) + goto out; + + bpf_link__destroy(link); + link = NULL; + + /* test program unwinding with a non-XDP slave */ + if (!ASSERT_OK(system("ip link add vxlan type vxlan id 1 remote 1.2.3.4 dstport 0 dev lo"), + "add vxlan")) + goto out; + + err = system("ip link set vxlan master bond"); + if (!ASSERT_OK(err, "set vxlan master")) + goto out; + + /* attaching not allowed when one slave does not support XDP */ + link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond); + if (!ASSERT_ERR_PTR(link, "attach program to master when slave does not support XDP")) + goto out; out: bpf_link__destroy(link); @@ -443,6 +456,44 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons) system("ip link del veth"); system("ip link del bond"); + system("ip link del vxlan"); +} + +/* Test with nested bonding devices to catch issue with negative jump label count */ +static void test_xdp_bonding_nested(struct skeletons *skeletons) +{ + struct bpf_link *link = NULL; + int bond, err; + + if (!ASSERT_OK(system("ip link add bond type bond"), "add bond")) + goto out; + + bond = if_nametoindex("bond"); + if (!ASSERT_GE(bond, 0, "if_nametoindex bond")) + goto out; + + if (!ASSERT_OK(system("ip link add bond_nest1 type bond"), "add bond_nest1")) + goto out; + + err = system("ip link set bond_nest1 master bond"); + if (!ASSERT_OK(err, "set bond_nest1 master")) + goto out; + + if (!ASSERT_OK(system("ip link add bond_nest2 type bond"), "add bond_nest1")) + goto out; + + err = system("ip link set bond_nest2 master bond_nest1"); + if (!ASSERT_OK(err, "set bond_nest2 master")) + goto out; + + link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond); + ASSERT_OK_PTR(link, "attach program to master"); + +out: + bpf_link__destroy(link); + system("ip link del bond"); + system("ip link del bond_nest1"); + system("ip link del bond_nest2"); } static int libbpf_debug_print(enum libbpf_print_level level, @@ -496,6 +547,9 @@ void test_xdp_bonding(void) if (test__start_subtest("xdp_bonding_attach")) test_xdp_bonding_attach(&skeletons); + if (test__start_subtest("xdp_bonding_nested")) + test_xdp_bonding_nested(&skeletons); + for (i = 0; i < ARRAY_SIZE(bond_test_cases); i++) { struct bond_test_case *test_case = &bond_test_cases[i];