From patchwork Mon May 11 18:52:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 219449 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=-7.2 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 5ED1AC47255 for ; Mon, 11 May 2020 18:52:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CCE2206DB for ; Mon, 11 May 2020 18:52:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="JJ7RBd3Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731286AbgEKSwt (ORCPT ); Mon, 11 May 2020 14:52:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731273AbgEKSwq (ORCPT ); Mon, 11 May 2020 14:52:46 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACFA6C061A0C for ; Mon, 11 May 2020 11:52:45 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id k1so12327509wrx.4 for ; Mon, 11 May 2020 11:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DMqKMKWuzCcR6FxP9hi6qzxvVY3wjBoadkJ8o2Mh5D0=; b=JJ7RBd3YRIwSXmyf5NPu//CnAnU+v4tsq2Btmu/NTeC81ikDA8I9wPfKjWSeUe6jm8 aqxRm1wU3VDslngOuNnoizn6g8CnmaBQmqyq8O5RpodbpwaEuRInIWINHDWNkbhf/mT/ lLtxPlZfJsLpJh6jeM4C49jrOJ46iSLLjnm2g= 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=DMqKMKWuzCcR6FxP9hi6qzxvVY3wjBoadkJ8o2Mh5D0=; b=aG8L+qKby4yMISoT1oT29Uc3toqckSFD89qZ8xsQ6B0Voe0HQ63Q4umZvdBRFCYHGZ z1Yh48RbLBzC9XeD6f7JZ8Y7c+L//NIBYiVNcntg/1w1QPGMIGrP5SsvOmHZVy9z2iko 358jDnx1KgKi11qUS8jaQJi1+LndwgfI9ccmR3DNgEsnhpfvyplKslV1IYqRQQJ/kf6L NejBTJ+H2bbdr5iRHAz7T4Q/ReMJhdrqv3xES56CtlXf5kwv7W+3zeLrjuvgKhHMDe07 Whfakgdu1NPFdT4fDILzYY+4dw7jYImjC/uozoFFmh5wSGKHCK679rupJ/r/gOY6XdGd MMYQ== X-Gm-Message-State: AGi0PubI5P8RAUFjwYs7miWC9mvDqpZ1cb5sjROuh0/OQzaJdtcy4IBT UbHZDidlhaNDOdmJSyTLQd9yEpye9Zg= X-Google-Smtp-Source: APiQypLCY6N3PM2wsnBC3way/PtTOY12KkcMxt0ZEytY46n8Gass3dyNRQCQPGuQZvfwdqopEEB8wg== X-Received: by 2002:a5d:4e0a:: with SMTP id p10mr20116949wrt.215.1589223163698; Mon, 11 May 2020 11:52:43 -0700 (PDT) Received: from cloudflare.com ([2a02:a310:c262:aa00:b35e:8938:2c2a:ba8b]) by smtp.gmail.com with ESMTPSA id y10sm15892107wrd.95.2020.05.11.11.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2020 11:52:43 -0700 (PDT) From: Jakub Sitnicki To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: dccp@vger.kernel.org, kernel-team@cloudflare.com, Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Eric Dumazet , Gerrit Renker , Jakub Kicinski , Andrii Nakryiko , Martin KaFai Lau Subject: [PATCH bpf-next v2 15/17] selftests/bpf: Add verifier tests for bpf_sk_lookup context access Date: Mon, 11 May 2020 20:52:16 +0200 Message-Id: <20200511185218.1422406-16-jakub@cloudflare.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200511185218.1422406-1-jakub@cloudflare.com> References: <20200511185218.1422406-1-jakub@cloudflare.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Exercise verifier access checks for bpf_sk_lookup context fields. Signed-off-by: Jakub Sitnicki --- Notes: v2: - Adjust for fields renames in struct bpf_sk_lookup. .../selftests/bpf/verifier/ctx_sk_lookup.c | 694 ++++++++++++++++++ 1 file changed, 694 insertions(+) create mode 100644 tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c diff --git a/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c b/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c new file mode 100644 index 000000000000..223163172fa9 --- /dev/null +++ b/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c @@ -0,0 +1,694 @@ +{ + "valid 1,2,4-byte read bpf_sk_lookup remote_ip4", + .insns = { + /* 4-byte read */ + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip4)), + /* 2-byte read */ + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip4)), + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip4) + 2), + /* 1-byte read */ + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip4)), + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip4) + 3), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte read bpf_sk_lookup remote_ip4", + .insns = { + /* 8-byte read */ + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte write bpf_sk_lookup remote_ip4", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x7f000001U), + /* 4-byte write */ + BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 4-byte write bpf_sk_lookup remote_ip4", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x7f000001U), + /* 4-byte write */ + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte write bpf_sk_lookup remote_ip4", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x7f000001U), + /* 2-byte write */ + BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte write bpf_sk_lookup remote_ip4", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x7f000001U), + /* 1-byte write */ + BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "valid 1,2,4-byte read bpf_sk_lookup local_ip4", + .insns = { + /* 4-byte read */ + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip4)), + /* 2-byte read */ + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip4)), + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip4) + 2), + /* 1-byte read */ + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip4)), + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip4) + 3), + BPF_MOV64_IMM(BPF_REG_0, 0), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte read bpf_sk_lookup local_ip4", + .insns = { + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte write bpf_sk_lookup local_ip4", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x7f000001U), + BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 4-byte write bpf_sk_lookup local_ip4", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x7f000001U), + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte write bpf_sk_lookup local_ip4", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x7f000001U), + BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte write bpf_sk_lookup local_ip4", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x7f000001U), + BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_ip4)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "valid 1,2,4-byte read bpf_sk_lookup remote_ip6", + .insns = { + /* 4-byte read */ + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip6[0])), + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip6[3])), + /* 2-byte read */ + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip6[0])), + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip6[3]) + 2), + /* 1-byte read */ + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip6[0])), + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip6[3]) + 3), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte read bpf_sk_lookup remote_ip6", + .insns = { + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte write bpf_sk_lookup remote_ip6", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x00000001U), + BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 4-byte write bpf_sk_lookup remote_ip6", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x00000001U), + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte write bpf_sk_lookup remote_ip6", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x00000001U), + BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte write bpf_sk_lookup remote_ip6", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x00000001U), + BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "valid 1,2,4-byte read bpf_sk_lookup local_ip6", + .insns = { + /* 4-byte read */ + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip6[0])), + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip6[3])), + /* 2-byte read */ + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip6[0])), + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip6[3]) + 2), + /* 1-byte read */ + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip6[0])), + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip6[3]) + 3), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte read bpf_sk_lookup local_ip6", + .insns = { + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte write bpf_sk_lookup local_ip6", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x00000001U), + BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 4-byte write bpf_sk_lookup local_ip6", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x00000001U), + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte write bpf_sk_lookup local_ip6", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x00000001U), + BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte write bpf_sk_lookup local_ip6", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 0x00000001U), + BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_ip6[0])), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "valid 4-byte read bpf_sk_lookup remote_port", + .insns = { + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_port)), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte read bpf_sk_lookup remote_port", + .insns = { + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte read bpf_sk_lookup remote_port", + .insns = { + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte read bpf_sk_lookup remote_port", + .insns = { + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, remote_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte write bpf_sk_lookup remote_port", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 4-byte write bpf_sk_lookup remote_port", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte write bpf_sk_lookup remote_port", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte write bpf_sk_lookup remote_port", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, remote_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "valid 4-byte read bpf_sk_lookup local_port", + .insns = { + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_port)), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte read bpf_sk_lookup local_port", + .insns = { + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte read bpf_sk_lookup local_port", + .insns = { + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte read bpf_sk_lookup local_port", + .insns = { + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, local_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte write bpf_sk_lookup local_port", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 4-byte write bpf_sk_lookup local_port", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte write bpf_sk_lookup local_port", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte write bpf_sk_lookup local_port", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, local_port)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "valid 4-byte read bpf_sk_lookup family", + .insns = { + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, family)), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte read bpf_sk_lookup family", + .insns = { + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, family)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte read bpf_sk_lookup family", + .insns = { + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, family)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte read bpf_sk_lookup family", + .insns = { + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, family)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte write bpf_sk_lookup family", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, family)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 4-byte write bpf_sk_lookup family", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, family)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte write bpf_sk_lookup family", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, family)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte write bpf_sk_lookup family", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, family)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "valid 4-byte read bpf_sk_lookup protocol", + .insns = { + BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, protocol)), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte read bpf_sk_lookup protocol", + .insns = { + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, protocol)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte read bpf_sk_lookup protocol", + .insns = { + BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, protocol)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte read bpf_sk_lookup protocol", + .insns = { + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, + offsetof(struct bpf_sk_lookup, protocol)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 8-byte write bpf_sk_lookup protocol", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, protocol)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 4-byte write bpf_sk_lookup protocol", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, protocol)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 2-byte write bpf_sk_lookup protocol", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_H, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, protocol)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +}, +{ + "invalid 1-byte write bpf_sk_lookup protocol", + .insns = { + BPF_MOV64_IMM(BPF_REG_0, 1234), + BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, + offsetof(struct bpf_sk_lookup, protocol)), + BPF_EXIT_INSN(), + }, + .errstr = "invalid bpf_context access", + .result = REJECT, + .prog_type = BPF_PROG_TYPE_SK_LOOKUP, +},