From patchwork Fri Jan 7 22:11:13 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: 12707105 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 449E9C4332F for ; Fri, 7 Jan 2022 22:11:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230415AbiAGWLZ (ORCPT ); Fri, 7 Jan 2022 17:11:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47633 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230429AbiAGWLY (ORCPT ); Fri, 7 Jan 2022 17:11:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641593483; 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=W74pDxNFjz7NcYMYnihFwM/9aHZKzCb3JGwhZFxTX/A=; b=arbrR+A1RwTd/HKVEhKAhzFCCVZjC7leEmOM/JsSWOdRCXD7coLa7qz+KWzrFN2iBYl26k /LYSfcASE6HNRyP22SPb/GXjMIv6DBqfGLBaQdlpuGSj3Hl/zSc5F0LEuZ3CQ7KrGHgaVr 9U9ytFVhSe0TkfyDp6+yvOBSp1S7dWI= 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-153--Ek9M7tiPZyU-5nhbahfwQ-1; Fri, 07 Jan 2022 17:11:22 -0500 X-MC-Unique: -Ek9M7tiPZyU-5nhbahfwQ-1 Received: by mail-ed1-f71.google.com with SMTP id g11-20020a056402090b00b003f8fd1ac475so5780874edz.1 for ; Fri, 07 Jan 2022 14:11:22 -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=W74pDxNFjz7NcYMYnihFwM/9aHZKzCb3JGwhZFxTX/A=; b=zTSLtIshCECTicfOKCDR/xK0U5r9xGfCpyZvuejAfhKDV3nuewNGyRiZmGLYLouM1t ZKqz0RqVkM601YRxinWsEsqvyNj2SFLr3RR9jSf8q9o7i7XRK/UMyuJZTNnbu7dIDYSw XFBHEtnwEGsSbowgqWJz5jAKZvFdKy675gVYlxcFNNE65vV7DUq9KIVejubqnajIaWdL Ur3SXsjYb5BrTUZVDY8Vn2TNy347JOuwugc/ZzXOl60wf6yP4nRKjHBkuTGFPyYZ6l1/ 3wVqqxe6ePTmXdJpJoaMXpktA1j9wQpDLPEjF/2AkccYsc+UM04Arsi8lkrBt5ZUe9g6 wpFg== X-Gm-Message-State: AOAM531onW+87HJoqwMTqhUHiLYasyFQaYtya9/S8QnKkLlbY8yKZKFs hEE1h7yIj6qCrtaG+wGdIHqfRIqT6RebFIn5EX3SUQHOhVdK1T0mLlRPnmQBZf0Ll6x5ImKG/jx 8HkimErhlrJ9W06eY X-Received: by 2002:a17:906:f01:: with SMTP id z1mr22139431eji.346.1641593480133; Fri, 07 Jan 2022 14:11:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRefX40qs5EO3OKkITmeknKrexgrVp35uaBM2Gaea+gDH6rWiowUPlZZ4VJEWYCVYtgR67vw== X-Received: by 2002:a17:906:f01:: with SMTP id z1mr22139392eji.346.1641593479180; Fri, 07 Jan 2022 14:11:19 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id j13sm2645087edw.89.2022.01.07.14.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 14:11:18 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 7B205181F2A; Fri, 7 Jan 2022 23:11:16 +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?= , syzbot+983941aa85af6ded1fd9@syzkaller.appspotmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf v2 1/3] xdp: check prog type before updating BPF link Date: Fri, 7 Jan 2022 23:11:13 +0100 Message-Id: <20220107221115.326171-1-toke@redhat.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The bpf_xdp_link_update() function didn't check the program type before updating the program, which made it possible to install any program type as an XDP program, which is obviously not good. Syzbot managed to trigger this by swapping in an LWT program on the XDP hook which would crash in a helper call. Fix this by adding a check and bailing out if the types don't match. Fixes: 026a4c28e1db ("bpf, xdp: Implement LINK_UPDATE for BPF XDP link") Reported-by: syzbot+983941aa85af6ded1fd9@syzkaller.appspotmail.com Acked-by: Andrii Nakryiko Signed-off-by: Toke Høiland-Jørgensen --- net/core/dev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index c4708e2487fb..2078d04c6482 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9656,6 +9656,12 @@ static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog, goto out_unlock; } old_prog = link->prog; + if (old_prog->type != new_prog->type || + old_prog->expected_attach_type != new_prog->expected_attach_type) { + err = -EINVAL; + goto out_unlock; + } + if (old_prog == new_prog) { /* no-op, don't disturb drivers */ bpf_prog_put(new_prog); From patchwork Fri Jan 7 22:11:14 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: 12707104 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 A4613C433FE for ; Fri, 7 Jan 2022 22:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230441AbiAGWLY (ORCPT ); Fri, 7 Jan 2022 17:11:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37257 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230409AbiAGWLY (ORCPT ); Fri, 7 Jan 2022 17:11:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641593483; 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=lDjSnWSJKmRxgKiKPbIJ63KDFOjFZvuZYRiZmSeBluE=; b=BFzRjX0FNn/ELuxZonJpg4Dkdr0vxtxsl5oErvZ0OPpUbd6Ju5OE4VnPy0hNBeYztCOWPJ g9eSTyjnGa8njpt6+CvivdWsMiWL2Mg5BU6hOWo1wp+07gyTqSD+mDyTkEEZAdaQEZofqh qb0c4E7KAPkBKbeJHiWt4ytJVgZplww= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-591-FP-W3eR1MyG8ERfbVJ0X1w-1; Fri, 07 Jan 2022 17:11:22 -0500 X-MC-Unique: FP-W3eR1MyG8ERfbVJ0X1w-1 Received: by mail-ed1-f72.google.com with SMTP id v18-20020a056402349200b003f8d3b7ee8dso5748066edc.23 for ; Fri, 07 Jan 2022 14:11:22 -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=lDjSnWSJKmRxgKiKPbIJ63KDFOjFZvuZYRiZmSeBluE=; b=ElBdkuE5XL7oKl4KZg+qLk1nnsIgS5YOxnOGqyBhdpxu9rh35dVyOgJJT4igDo9/0m 2CpZY2H2gLsRXQqMSPiZbrUhfOtEWjQgsYXO/XA5uWGDH/NOwFXIdiE6vQ+KYNNcSoXZ +DmwnHlZks69kzgzxqTxZuFfL9uu/QgaSls/PEJgPd2N0+HYLTxBcacZJOqfPQSGpV/V 5YHJVWMExkc//sUNhuVOfwCIqL/Z0cIsnOmNhli6IbQSLHzpqmItDhfBH+FZK9mBiVuN FZLrmNdCagt9Vauma0FhKo/glLEPih6pkrR8jk4vRo6JCexDBCn7efM20qXee/1cJAYI 8Avw== X-Gm-Message-State: AOAM532QUKURUoCYm7uOcprAyxnd7b34ylagF5oYyBUZAvAys5GiQYer el4ThejGuFgv/jOjddrMcFXcXFJr5aDGwU7NhOh6qzXqn3ShHlSWDosIOSJNrjXA8S8rYDbRwCa 2fV5jBPMWXYZA/i5V X-Received: by 2002:aa7:cc04:: with SMTP id q4mr42929016edt.313.1641593480485; Fri, 07 Jan 2022 14:11:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1EdHnFGEQQrtlMaq4SdEv0CgZj6huekFI6+wJjDvqJps3II7hQ9oiRzFNR331tz9y5Puing== X-Received: by 2002:aa7:cc04:: with SMTP id q4mr42928952edt.313.1641593479391; Fri, 07 Jan 2022 14:11:19 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id o8sm78453edc.85.2022.01.07.14.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 14:11:18 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id DBBC2181F2C; Fri, 7 Jan 2022 23:11:16 +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 v2 2/3] bpf/selftests: convert xdp_link test to ASSERT_* macros Date: Fri, 7 Jan 2022 23:11:14 +0100 Message-Id: <20220107221115.326171-2-toke@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220107221115.326171-1-toke@redhat.com> References: <20220107221115.326171-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 Convert the selftest to use the preferred ASSERT_* macros instead of the deprecated CHECK(). v2: - Don't add if statements around checks if they weren't there before. Signed-off-by: Toke Høiland-Jørgensen --- .../selftests/bpf/prog_tests/xdp_link.c | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_link.c b/tools/testing/selftests/bpf/prog_tests/xdp_link.c index 983ab0b47d30..eec0bf83546b 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_link.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_link.c @@ -8,46 +8,47 @@ void serial_test_xdp_link(void) { - __u32 duration = 0, id1, id2, id0 = 0, prog_fd1, prog_fd2, err; DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts, .old_fd = -1); struct test_xdp_link *skel1 = NULL, *skel2 = NULL; + __u32 id1, id2, id0 = 0, prog_fd1, prog_fd2; struct bpf_link_info link_info; struct bpf_prog_info prog_info; struct bpf_link *link; + int err; __u32 link_info_len = sizeof(link_info); __u32 prog_info_len = sizeof(prog_info); skel1 = test_xdp_link__open_and_load(); - if (CHECK(!skel1, "skel_load", "skeleton open and load failed\n")) + if (!ASSERT_OK_PTR(skel1, "skel_load")) goto cleanup; prog_fd1 = bpf_program__fd(skel1->progs.xdp_handler); skel2 = test_xdp_link__open_and_load(); - if (CHECK(!skel2, "skel_load", "skeleton open and load failed\n")) + if (!ASSERT_OK_PTR(skel2, "skel_load")) goto cleanup; prog_fd2 = bpf_program__fd(skel2->progs.xdp_handler); memset(&prog_info, 0, sizeof(prog_info)); err = bpf_obj_get_info_by_fd(prog_fd1, &prog_info, &prog_info_len); - if (CHECK(err, "fd_info1", "failed %d\n", -errno)) + if (!ASSERT_OK(err, "fd_info1")) goto cleanup; id1 = prog_info.id; memset(&prog_info, 0, sizeof(prog_info)); err = bpf_obj_get_info_by_fd(prog_fd2, &prog_info, &prog_info_len); - if (CHECK(err, "fd_info2", "failed %d\n", -errno)) + if (!ASSERT_OK(err, "fd_info2")) goto cleanup; id2 = prog_info.id; /* set initial prog attachment */ err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, prog_fd1, XDP_FLAGS_REPLACE, &opts); - if (CHECK(err, "fd_attach", "initial prog attach failed: %d\n", err)) + if (!ASSERT_OK(err, "fd_attach")) goto cleanup; /* validate prog ID */ err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0); - CHECK(err || id0 != id1, "id1_check", - "loaded prog id %u != id1 %u, err %d", id0, id1, err); + if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val")) + goto cleanup; /* BPF link is not allowed to replace prog attachment */ link = bpf_program__attach_xdp(skel1->progs.xdp_handler, IFINDEX_LO); @@ -62,7 +63,7 @@ void serial_test_xdp_link(void) /* detach BPF program */ opts.old_fd = prog_fd1; err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, XDP_FLAGS_REPLACE, &opts); - if (CHECK(err, "prog_detach", "failed %d\n", err)) + if (!ASSERT_OK(err, "prog_detach")) goto cleanup; /* now BPF link should attach successfully */ @@ -73,24 +74,23 @@ void serial_test_xdp_link(void) /* validate prog ID */ err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0); - if (CHECK(err || id0 != id1, "id1_check", - "loaded prog id %u != id1 %u, err %d", id0, id1, err)) + if (!ASSERT_OK(err, "id1_check_err") || !ASSERT_EQ(id0, id1, "id1_check_val")) goto cleanup; /* BPF prog attach is not allowed to replace BPF link */ opts.old_fd = prog_fd1; err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, prog_fd2, XDP_FLAGS_REPLACE, &opts); - if (CHECK(!err, "prog_attach_fail", "unexpected success\n")) + if (!ASSERT_ERR(err, "prog_attach_fail")) goto cleanup; /* Can't force-update when BPF link is active */ err = bpf_set_link_xdp_fd(IFINDEX_LO, prog_fd2, 0); - if (CHECK(!err, "prog_update_fail", "unexpected success\n")) + if (!ASSERT_ERR(err, "prog_update_fail")) goto cleanup; /* Can't force-detach when BPF link is active */ err = bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0); - if (CHECK(!err, "prog_detach_fail", "unexpected success\n")) + if (!ASSERT_ERR(err, "prog_detach_fail")) goto cleanup; /* BPF link is not allowed to replace another BPF link */ @@ -110,40 +110,34 @@ void serial_test_xdp_link(void) skel2->links.xdp_handler = link; err = bpf_get_link_xdp_id(IFINDEX_LO, &id0, 0); - if (CHECK(err || id0 != id2, "id2_check", - "loaded prog id %u != id2 %u, err %d", id0, id1, err)) + if (!ASSERT_OK(err, "id2_check_err") || !ASSERT_EQ(id0, id2, "id2_check_val")) goto cleanup; /* updating program under active BPF link works as expected */ err = bpf_link__update_program(link, skel1->progs.xdp_handler); - if (CHECK(err, "link_upd", "failed: %d\n", err)) + if (!ASSERT_OK(err, "link_upd")) goto cleanup; memset(&link_info, 0, sizeof(link_info)); err = bpf_obj_get_info_by_fd(bpf_link__fd(link), &link_info, &link_info_len); - if (CHECK(err, "link_info", "failed: %d\n", err)) + if (!ASSERT_OK(err, "link_info")) goto cleanup; - CHECK(link_info.type != BPF_LINK_TYPE_XDP, "link_type", - "got %u != exp %u\n", link_info.type, BPF_LINK_TYPE_XDP); - CHECK(link_info.prog_id != id1, "link_prog_id", - "got %u != exp %u\n", link_info.prog_id, id1); - CHECK(link_info.xdp.ifindex != IFINDEX_LO, "link_ifindex", - "got %u != exp %u\n", link_info.xdp.ifindex, IFINDEX_LO); + ASSERT_EQ(link_info.type, BPF_LINK_TYPE_XDP, "link_type"); + ASSERT_EQ(link_info.prog_id, id1, "link_prog_id"); + ASSERT_EQ(link_info.xdp.ifindex, IFINDEX_LO, "link_ifindex"); err = bpf_link__detach(link); - if (CHECK(err, "link_detach", "failed %d\n", err)) + if (!ASSERT_OK(err, "link_detach")) goto cleanup; memset(&link_info, 0, sizeof(link_info)); err = bpf_obj_get_info_by_fd(bpf_link__fd(link), &link_info, &link_info_len); - if (CHECK(err, "link_info", "failed: %d\n", err)) - goto cleanup; - CHECK(link_info.prog_id != id1, "link_prog_id", - "got %u != exp %u\n", link_info.prog_id, id1); + + ASSERT_OK(err, "link_info"); + ASSERT_EQ(link_info.prog_id, id1, "link_prog_id"); /* ifindex should be zeroed out */ - CHECK(link_info.xdp.ifindex != 0, "link_ifindex", - "got %u != exp %u\n", link_info.xdp.ifindex, 0); + ASSERT_EQ(link_info.xdp.ifindex, 0, "link_ifindex"); cleanup: test_xdp_link__destroy(skel1); From patchwork Fri Jan 7 22:11:15 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: 12707106 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 B3781C4332F for ; Fri, 7 Jan 2022 22:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230448AbiAGWL2 (ORCPT ); Fri, 7 Jan 2022 17:11:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:54322 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230429AbiAGWL0 (ORCPT ); Fri, 7 Jan 2022 17:11:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641593485; 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=omVKaNcy5fAR+P8CusXzfyn6nmrKkdfnGWZtZt9VL2k=; b=CcJxrSiTiig2SoPXns65u67PGVFyQohNlHYHv8noAgHi5LoPsaMg+bNyTC1jZpWY5WvPey Ih0n89NIOARV9E0m9ZP5L/RYg5wbNbuUcxbJGx8Ys5i9xKmzhe0UKo96DUA7u77IyG+XS2 9ZVx+V32ohJfvOhin5esGobRUDGx8Kc= 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-355-hyZRS1uEO3G1gAKYi3sebw-1; Fri, 07 Jan 2022 17:11:24 -0500 X-MC-Unique: hyZRS1uEO3G1gAKYi3sebw-1 Received: by mail-ed1-f71.google.com with SMTP id v18-20020a056402349200b003f8d3b7ee8dso5748152edc.23 for ; Fri, 07 Jan 2022 14:11:24 -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=omVKaNcy5fAR+P8CusXzfyn6nmrKkdfnGWZtZt9VL2k=; b=BqKpAjfU/BSgTqztqveFc2RSsl0FNpmic2bABozPQifKc+gV7XgfY2yugJ8uyDa5RC 6ZZSMRbdkdphl3OhZME0m9NNSdqFC5gZC0b3hgvqaMyMkViJbfno3+Yr9f0E/48hkXVK 2WXaYbFGjSyDCaX53GP3qUgxydRBtjd5MT1/bB7iSLBsMAV66tVA5l1wZgc9+Wct5wN7 IDXYh8EY+VlrSpQePR/ICZbiEcD1Fs71JGFNzgWSfktRzcu57KL8Qn+JKdM/16PsZwoV 47DBCu+jcxMLjtc4xv1czXWpx3K1wdEjlVnc2KQFraD3AWysZNvaS34nwE1vKer5WO2U Qktg== X-Gm-Message-State: AOAM5333vQM2DVOb4iPM9ok8tJKFtPKBIRdmzRCxVBrgPK+qg6N2SL3M UBg915QD91KNEe5KBThm2OF6IkN39ttYTG9aXTB+Q0sdGvaJ94YwlECT08jgKoJejmFhTjECupW +h/3t2q7SnRJ3bIua X-Received: by 2002:a05:6402:154:: with SMTP id s20mr65522105edu.148.1641593481125; Fri, 07 Jan 2022 14:11:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKzpJCWoqaZSxUYfC+gJ25uxor1OuK6byXmPFu4l+4AGwMSieKYCB5o2yckQxwbmLbVn0IGg== X-Received: by 2002:a05:6402:154:: with SMTP id s20mr65521979edu.148.1641593478704; Fri, 07 Jan 2022 14:11:18 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id g7sm1744790ejt.29.2022.01.07.14.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 14:11:17 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 4F592181F2E; Fri, 7 Jan 2022 23:11:17 +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 v2 3/3] bpf/selftests: Add check for updating XDP bpf_link with wrong program type Date: Fri, 7 Jan 2022 23:11:15 +0100 Message-Id: <20220107221115.326171-3-toke@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220107221115.326171-1-toke@redhat.com> References: <20220107221115.326171-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 Add a check to the xdp_link selftest that the kernel rejects replacing an XDP program with a different program type on link update. v2: - Split this out into its own patch. Signed-off-by: Toke Høiland-Jørgensen --- tools/testing/selftests/bpf/prog_tests/xdp_link.c | 5 +++++ tools/testing/selftests/bpf/progs/test_xdp_link.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_link.c b/tools/testing/selftests/bpf/prog_tests/xdp_link.c index eec0bf83546b..b2b357f8c74c 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_link.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_link.c @@ -127,6 +127,11 @@ void serial_test_xdp_link(void) ASSERT_EQ(link_info.prog_id, id1, "link_prog_id"); ASSERT_EQ(link_info.xdp.ifindex, IFINDEX_LO, "link_ifindex"); + /* updating program under active BPF link with different type fails */ + err = bpf_link__update_program(link, skel1->progs.tc_handler); + if (!ASSERT_ERR(err, "link_upd_invalid")) + goto cleanup; + err = bpf_link__detach(link); if (!ASSERT_OK(err, "link_detach")) goto cleanup; diff --git a/tools/testing/selftests/bpf/progs/test_xdp_link.c b/tools/testing/selftests/bpf/progs/test_xdp_link.c index ee7d6ac0f615..64ff32eaae92 100644 --- a/tools/testing/selftests/bpf/progs/test_xdp_link.c +++ b/tools/testing/selftests/bpf/progs/test_xdp_link.c @@ -10,3 +10,9 @@ int xdp_handler(struct xdp_md *xdp) { return 0; } + +SEC("tc") +int tc_handler(struct __sk_buff *skb) +{ + return 0; +}