Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5139154rwb; Wed, 17 Aug 2022 11:47:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR485ive3xyA6xPShGYBsWlncPpwyS3Mi2vnPwaH/TFduhTGOzT3kTC0Rriocs6PPOY188Q1 X-Received: by 2002:a17:907:762f:b0:730:95d9:9955 with SMTP id jy15-20020a170907762f00b0073095d99955mr17019489ejc.505.1660762056093; Wed, 17 Aug 2022 11:47:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660762056; cv=none; d=google.com; s=arc-20160816; b=dR7iv4xKvLCvXZWF33BlkLAPHb/inP1VXS+KoLi0VuW2BYehOAfbyuqFoUvZBaY9B/ PxJDzKi8DlgvM7rCe6gxCx+UfayPpXVsG7MzfPoSfSRqfeSLcUxLvut+BQHwGTn+EWtO gz6dS2Gm30dXblOeAwzzJEL0/kkvZJudnf1jxN1lw+3Y8yJeX0qV/i1/E4Fo3UM6P540 Yt1rQCOSkWrda6V5LLASE9pDy/3xfiAEx0gerAq7Noe1XaLfsieEL4pqKtZjkC/zJh5d rjGLqgCktgb1UlZlDZL2b9I5/bGLoM4LJSK2fmIyenNcI5z0A9oFMCmfLe4io2dWwRgw wqLg== 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 :feedback-id:dkim-signature:dkim-signature; bh=5ZRUO9fZWr4iLqIUqA1TD+ufCzt/V4tcVExTpw7qFl8=; b=kGC29ZXTHrbyu138FKDBLlG5/+b6VMaJ51GithFcSRuGRZIdUihGU/ypffHfsDg8it oWKDLvoN8CSy4RtxhUrD1gKu30jJUUDa+Zw+P/38eFNuInevuL6v71kllxkLP4wHuvHr y50Hl83ENV76YnHybK0aKWhJ+R+WlVRoZpG9NVEjvuSaMIcNwvVpDItDveUiFv6q8Kwp de7jZolrseCh5XN1RzdZddxd+nmRmTJ17lpMqCzBL9PMGNEtW1eRn4QnjPmZ/QNm8hJs XtMpJ2n9gYtl/DAfI/Kt2C2NrvfLg3pGYx2BgyRpBE8iPpuoNMELPumFHdj3dFFrJkRv 2r1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=h3n3pAdJ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=eIgAPf1e; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w5-20020a50d785000000b0043bbb19a3b4si11149844edi.174.2022.08.17.11.47.08; Wed, 17 Aug 2022 11:47:36 -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=@dxuuu.xyz header.s=fm3 header.b=h3n3pAdJ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=eIgAPf1e; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241308AbiHQSoC (ORCPT + 99 others); Wed, 17 Aug 2022 14:44:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241146AbiHQSnd (ORCPT ); Wed, 17 Aug 2022 14:43:33 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C42452EF; Wed, 17 Aug 2022 11:43:21 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 474385C00A1; Wed, 17 Aug 2022 14:43:20 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 17 Aug 2022 14:43:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1660761800; x=1660848200; bh=5Z RUO9fZWr4iLqIUqA1TD+ufCzt/V4tcVExTpw7qFl8=; b=h3n3pAdJt3ejoO7aLQ BlGI2Pa9ucgv9iX0QmGpT5JfMFEi2agl22xNw9eeBxCGOeeb+n83rcz0226yiweq tkBhyouzK3Y4XppKGeKX4YXniUPzZ8xezN2Lj9PgOQ5QKz9gWYDgGu4Q3FPdbQmg C1P/wU0USGCyjPWP7N3mVyLjjWu6CIt0v6J4dfBo28BJva14Yowf0LZQbQ2zRwvH EsSh/4Ak79TbFVNXlP2Q9dYXah271U5TgKMXVzzwS6enjWu3bGd5fIqONTZQvBRV +8fd/kLxrE+CacFMFFkWxqgrqSTolJXNSJ0j6Zu3a3r/aT9HTyoSaDLnLQPlfojV R9tQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1660761800; x=1660848200; bh=5ZRUO9fZWr4iL qIUqA1TD+ufCzt/V4tcVExTpw7qFl8=; b=eIgAPf1eAe+D0ES+0UaLm/zfPLPSc RLQPOgO6ReGpfeae/muAL5y8M86z1gp0++TRno9JTxu2Oofyp0A6vEHBXCwssboe mRH+mOlaF0MQYS1J5XuZcFp8njOGtrthOu2SKq39xnByGaWEsqHMUpZvJ1xQBhTG 0TTM3oDEOIaPSiIPlNIS1qaJE0BDFyGmaerQN2R9/GJydfzvkQbTpJxhB271JMcI Y/HZh+oWSHtKaVWkA/d+Q/f9RkijsTV6H56zKhHMtLZRLAbJ4VgcOwz9nm6y+s6U Wqe48w4WxNHE3wlEMLcMfI7AMWAZskoC9x0LwjwnoNHowsjhawdMfwVGA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdehiedgudeftdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhephf fvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcu oegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpefgfefggeejhfduie ekvdeuteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 17 Aug 2022 14:43:19 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, memxor@gmail.com Cc: Daniel Xu , pablo@netfilter.org, fw@strlen.de, toke@kernel.org, netfilter-devel@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 4/4] selftests/bpf: Add tests for writing to nf_conn:mark Date: Wed, 17 Aug 2022 12:43:02 -0600 Message-Id: <7519a65ba6bd6e41ba0c580c81d4202c5982ea64.1660761470.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.37.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD, PDS_OTHER_BAD_TLD,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 Add a simple extension to the existing selftest to write to nf_conn:mark. Also add a failure test for writing to unsupported field. Signed-off-by: Daniel Xu --- tools/testing/selftests/bpf/prog_tests/bpf_nf.c | 1 + tools/testing/selftests/bpf/progs/test_bpf_nf.c | 6 ++++-- .../testing/selftests/bpf/progs/test_bpf_nf_fail.c | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_nf.c b/tools/testing/selftests/bpf/prog_tests/bpf_nf.c index 544bf90ac2a7..45389c39f211 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_nf.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_nf.c @@ -17,6 +17,7 @@ struct { { "set_status_after_insert", "kernel function bpf_ct_set_status args#0 expected pointer to STRUCT nf_conn___init but" }, { "change_timeout_after_alloc", "kernel function bpf_ct_change_timeout args#0 expected pointer to STRUCT nf_conn but" }, { "change_status_after_alloc", "kernel function bpf_ct_change_status args#0 expected pointer to STRUCT nf_conn but" }, + { "write_not_allowlisted_field", "no write support to nf_conn at off" }, }; enum { diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c index 2722441850cc..638b6642d20f 100644 --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c @@ -175,8 +175,10 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32, sizeof(opts_def)); if (ct) { test_exist_lookup = 0; - if (ct->mark == 42) - test_exist_lookup_mark = 43; + if (ct->mark == 42) { + ct->mark++; + test_exist_lookup_mark = ct->mark; + } bpf_ct_release(ct); } else { test_exist_lookup = opts_def.error; diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf_fail.c b/tools/testing/selftests/bpf/progs/test_bpf_nf_fail.c index bf79af15c808..0e4759ab38ff 100644 --- a/tools/testing/selftests/bpf/progs/test_bpf_nf_fail.c +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf_fail.c @@ -69,6 +69,20 @@ int lookup_insert(struct __sk_buff *ctx) return 0; } +SEC("?tc") +int write_not_allowlisted_field(struct __sk_buff *ctx) +{ + struct bpf_ct_opts___local opts = {}; + struct bpf_sock_tuple tup = {}; + struct nf_conn *ct; + + ct = bpf_skb_ct_lookup(ctx, &tup, sizeof(tup.ipv4), &opts, sizeof(opts)); + if (!ct) + return 0; + ct->status = 0xF00; + return 0; +} + SEC("?tc") int set_timeout_after_insert(struct __sk_buff *ctx) { -- 2.37.1