Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1300144imm; Fri, 27 Jul 2018 14:55:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpclmY6dKHpQ4jKUqLVpLFhYYNOFyci6dqQuep9VbkzEbgZOfqx1NXii5CMUj1j6LRbcg9nZ X-Received: by 2002:a17:902:822:: with SMTP id 31-v6mr7435127plk.172.1532728520565; Fri, 27 Jul 2018 14:55:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532728520; cv=none; d=google.com; s=arc-20160816; b=nzhUT5XCWJakso/SXUPg5UvYaAvGPxEFt3PwbGJ2cp+7hHs9aTG7GCs991gI6wMNED 5wI7t0UEc1ghagkjzuOKe8FYJd/3ryXF98Skdo5dQA0QYIgE9XMv/lKJi7Oor9MLffjw XBZQ16tMmvqq+Qd4SSDgb8MhbFfM1Se+wKpYCx1fUpl5jwkuQTA6LYL8e5vYs0/kJtgW B5ofNMEjxRHUC22Zm67vaGsy9c178n42M0/fitavWxnhJfOGcthzoHxiS/Ydc77wYv6d UZ2oDETxTVxXZals1xjqoviRawhwL/tWOmeV/t4wztOJhVcPpZuvbe3GenhKVG++EvZ/ 2vEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :arc-authentication-results; bh=OxBUnppWZwyS1PHTrz7mdeFFjhqESokB5jieomfxA0o=; b=DIKLlOLSpaxJCn0AD6f9cabE7MZ8z6RJkqq3QZ+FgEvGx2P5zR4/XHdoVy98pQwRxI N+FDb8zg4Ae8rw2nMKodyAZQUmVHraaxvTq973d6c/+OyTrRMyATBQEsRFQ2FSTh3UJW SarQ8cFrNOjqw/fUOeSnWU/hCPHruw2N0ddt1BeNMTpb6ED7pEg9/tIOYK49RvX81LWp gNxOkSd/VKg3D/sXNlvvNmDW40rRjeAhxC2k07rC5vHlCi9J6Fe0FYu268FVTTx9mlqp +ScK/MZusUyrojdNBPgk2qsfIxV0QSp7tkxov0ee4J8PhEc2y92e7MeGPtn9FRp800ao JNnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=NiMO37GJ; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=SyC8DNah; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a66-v6si4526155pla.287.2018.07.27.14.55.06; Fri, 27 Jul 2018 14:55:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=NiMO37GJ; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector1-fb-com header.b=SyC8DNah; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390058AbeG0XR0 (ORCPT + 99 others); Fri, 27 Jul 2018 19:17:26 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:52368 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390006AbeG0XRZ (ORCPT ); Fri, 27 Jul 2018 19:17:25 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6RLjQuI006591; Fri, 27 Jul 2018 14:53:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=OxBUnppWZwyS1PHTrz7mdeFFjhqESokB5jieomfxA0o=; b=NiMO37GJ+qhHZZucBHW8tocRVTdoIZEdSi3IIMWx1YFP78YP/i0sYBa0zXe3RXIgA4Co +5/7J8rQ87fmDxyFe5aPOSgdzY72VQwEnYb4HEx3eR7/7vnDsBfn4hBp3lQQ2VXURrDr 5G8w/GWsxYIytID+w89lKl3UAaAm3qhuGNE= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2kgb58r2mv-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2018 14:53:15 -0700 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.32) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 27 Jul 2018 17:53:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OxBUnppWZwyS1PHTrz7mdeFFjhqESokB5jieomfxA0o=; b=SyC8DNahlQPF90QeO3KRQBe0+I1nv6KSPu9UZW1JW+ay/S0QqKqKzLWSAJAC59uyZnYvzZCVxS/hJSEA279wBDbELWTvvwJeIPGPIXWrECnzD3D6Z0yEK2AF+ko926f8azYddimdN1xHmgfwtFfJByaXdMwNdycQ+/VUkWXDqgQ= Received: from castle.thefacebook.com (2620:10d:c090:200::5:fd07) by CY1PR15MB0171.namprd15.prod.outlook.com (2a01:111:e400:58bb::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.17; Fri, 27 Jul 2018 21:53:10 +0000 From: Roman Gushchin To: CC: , , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH v4 bpf-next 12/14] selftests/bpf: add verifier cgroup storage tests Date: Fri, 27 Jul 2018 14:52:41 -0700 Message-ID: <20180727215243.3850-13-guro@fb.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180727215243.3850-1-guro@fb.com> References: <20180727215243.3850-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c090:200::5:fd07] X-ClientProxiedBy: MWHPR11CA0020.namprd11.prod.outlook.com (2603:10b6:301:1::30) To CY1PR15MB0171.namprd15.prod.outlook.com (2a01:111:e400:58bb::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0e1a1605-3733-4767-36c2-08d5f40b584b X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020);SRVR:CY1PR15MB0171; X-Microsoft-Exchange-Diagnostics: 1;CY1PR15MB0171;3:LTWeIF4PzaTPy3wpmZ4040Bb6cjVqpDfV2EOSR9C/nK90L3chkKxkLXGL6zATvQS0Mn2IDlsk+FqAW9ZiUjd5IlT3Xi9m/+XLjzQeQ6jBuPDDr3HkFryLLYdZHoaZt4RvFJWtNH1Z8uqMkuvZMj3IjzHNlQS9e3C+DmCwM6X8tazAZ0ddLv+VmX6o2jV6HS8btkwZWLrvZFAnFJ19LiW34XZ9ZuH04jZ7fdmZ/pqyNYEsgQC5imc/ZwRAAhSGtjs;25:TrVKXKKC/T8hX6jwO3uSATrXP+dHclNypAhsrzx0U08Dpb8bC/UJMSdjLBXg2b0Mfxm1Lc1VW3hPMHJ6T5Jwc4GHN1IugIhO+ArVztA1X8ZHhn1Ox2ZIb5WPg2YakYIawnrIXA25lG9l9KactJnxzsJHbSdoE9AZur6MDSg+CYSVPOcePdnQazF9teJxFrvdxw+n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W+oxev6MAv9r+aq4058rMmWwNEOjfK5yBuBpvL9MkLKw5ZpwjVmvZIx4bzcQWqG4DBYiQeyaxFAVRQt670/3h2fLqtoeGsL5G70a1jE/JTXPkvgA8hGnwZDdsahQBbzmlbaxf/DQMu+kHOhbwn8ylAHxDujf+cudEaMqxXqrE/LmHHzVoQFHUybsuKo9TL9cL0C4ozKAnvfVd070zfEhL1n8pD0JeMLE X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231311)(11241501184)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016);SRVR:CY1PR15MB0171;BCL:0;PCL:0;RULEID:;SRVR:CY1PR15MB0171; X-Forefront-PRVS: 07467C4D33 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(366004)(39860400002)(136003)(376002)(346002)(396003)(199004)(189003)(478600001)(36756003)(52116002)(76176011)(106356001)(52396003)(316002)(50226002)(53416004)(51416003)(6512007)(68736007)(50466002)(48376002)(105586002)(2361001)(4326008)(53936002)(25786009)(16586007)(54906003)(2351001)(97736004)(6506007)(386003)(305945005)(7736002)(11346002)(446003)(46003)(486006)(2616005)(69596002)(6666003)(186003)(16526019)(5660300001)(47776003)(476003)(6486002)(6916009)(8936002)(86362001)(6116002)(14444005)(1076002)(81156014)(8676002)(81166006)(2906002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:CY1PR15MB0171;H:castle.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?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v+VvSpzxfi3bsIGCB3f?= =?us-ascii?Q?Rs562YxZwAd60OqGncWBEbCkDTld0ibfMJUdrQqsRsM6g2mv+6YZa9Fka/x/?= =?us-ascii?Q?ekT3xv7q2XJO2ppI0/tJqk4kO2xgCr/AQFj9CNmb7QRXXbLZA58oN+jRMO4s?= =?us-ascii?Q?X1+SOuGzlzn5w8AteH/O+ymRFcKC0z6QnQwEl21XpN3UKD46+SEydyGiUhDr?= =?us-ascii?Q?vcALrtCFTgLhMnR4L4etk/NQu23FyczyhplOHLsib8hTsdU/xOXm86ChQRhE?= =?us-ascii?Q?OYxScdvSng+ONsE9LAFJuEqPyMFHvLrhP43ls0bbjuHIsx3OeNBzyz05NDt3?= =?us-ascii?Q?vHWwcWEAUtTVZzN5viS7IBy8aJ96ziexJ2zTFuJ0ZkveOGtbqgRSAepODzs4?= =?us-ascii?Q?s5mAKKXe7owXQ9Uq40GR52u4Bd4g6JxmGQLqWp1QNJZOMsucS1ioAj668YmM?= =?us-ascii?B?dz09?= X-Microsoft-Antispam-Message-Info: Cqk1gnix8vEY5yHbLS72gA8DeFhIrUIJHqOTpCY03mJEYl8RGtsO5GtY3YLT09As5E2D0P7MHieyHIKdqiSoKnSI/z79FiRlXEU3fvh+RmoVa6PABT0y8xfzhQhu9PM1fEVVWiMEBgXyGVzZHOihSMqb6qrRNXnEU7a+euoHuu5FxHZ60GgXzfDiLTRift7oM4Db0MH8rqk9QdI+vz5pR0GfbD5oU1mT2y+KCWErY/9cSUcvREUIc/TSV7f4QBfbHOgNjrlBTqLarvNxcKixSd9+tVKrLA7bLhI0r8v1E9HxovxxbZvbaUiL/+PNIHLptOb0zXgxul7GsugHQ5MULbcDeiAkR5RWuyv6MshsXjE= X-Microsoft-Exchange-Diagnostics: 1;CY1PR15MB0171;6:ZD16Pv3r8kmvATl1YiTCxUbyN4ndTRFKBH42kF+J7p+Gh22IT2jT1x8+x4xWQNLPCzT6uF4r1xLLTLdmF5janOpBo89G0EdQF4WWzclzajxHeg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OriginalArrivalTime: 27 Jul 2018 21:53:10.0750 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e1a1605-3733-4767-36c2-08d5f40b584b X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR15MB0171 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-27_09:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the following verifier tests to cover the cgroup storage functionality: 1) valid access to the cgroup storage 2) invalid access: use regular hashmap instead of cgroup storage map 3) invalid access: use invalid map fd 4) invalid access: try access memory after the cgroup storage 5) invalid access: try access memory before the cgroup storage 6) invalid access: call get_local_storage() with non-zero flags For tests 2)-6) check returned error strings. Expected output: $ ./test_verifier #0/u add+sub+mul OK #0/p add+sub+mul OK #1/u DIV32 by 0, zero check 1 OK ... #280/p valid cgroup storage access OK #281/p invalid cgroup storage access 1 OK #282/p invalid cgroup storage access 2 OK #283/p invalid per-cgroup storage access 3 OK #284/p invalid cgroup storage access 4 OK #285/p invalid cgroup storage access 5 OK ... #649/p pass modified ctx pointer to helper, 2 OK #650/p pass modified ctx pointer to helper, 3 OK Summary: 901 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Roman Gushchin Cc: Alexei Starovoitov Cc: Daniel Borkmann Acked-by: Martin KaFai Lau --- tools/testing/selftests/bpf/bpf_helpers.h | 2 + tools/testing/selftests/bpf/test_verifier.c | 123 +++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h index f2f28b6c8915..ccd959fd940e 100644 --- a/tools/testing/selftests/bpf/bpf_helpers.h +++ b/tools/testing/selftests/bpf/bpf_helpers.h @@ -133,6 +133,8 @@ static int (*bpf_rc_keydown)(void *ctx, unsigned int protocol, (void *) BPF_FUNC_rc_keydown; static unsigned long long (*bpf_get_current_cgroup_id)(void) = (void *) BPF_FUNC_get_current_cgroup_id; +static void *(*bpf_get_local_storage)(void *map, unsigned long long flags) = + (void *) BPF_FUNC_get_local_storage; /* llvm builtin functions that eBPF C program may use to * emit BPF_LD_ABS and BPF_LD_IND instructions diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index f5f7bcc96046..8549c1f92bef 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -50,7 +50,7 @@ #define MAX_INSNS BPF_MAXINSNS #define MAX_FIXUPS 8 -#define MAX_NR_MAPS 7 +#define MAX_NR_MAPS 8 #define POINTER_VALUE 0xcafe4all #define TEST_DATA_LEN 64 @@ -70,6 +70,7 @@ struct bpf_test { int fixup_prog1[MAX_FIXUPS]; int fixup_prog2[MAX_FIXUPS]; int fixup_map_in_map[MAX_FIXUPS]; + int fixup_cgroup_storage[MAX_FIXUPS]; const char *errstr; const char *errstr_unpriv; uint32_t retval; @@ -4630,6 +4631,104 @@ static struct bpf_test tests[] = { .result = REJECT, .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, + { + "valid cgroup storage access", + .insns = { + BPF_MOV64_IMM(BPF_REG_2, 0), + BPF_LD_MAP_FD(BPF_REG_1, 0), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, + BPF_FUNC_get_local_storage), + BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 0), + BPF_MOV64_REG(BPF_REG_0, BPF_REG_1), + BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 1), + BPF_EXIT_INSN(), + }, + .fixup_cgroup_storage = { 1 }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_CGROUP_SKB, + }, + { + "invalid cgroup storage access 1", + .insns = { + BPF_MOV64_IMM(BPF_REG_2, 0), + BPF_LD_MAP_FD(BPF_REG_1, 0), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, + BPF_FUNC_get_local_storage), + BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 0), + BPF_MOV64_REG(BPF_REG_0, BPF_REG_1), + BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 1), + BPF_EXIT_INSN(), + }, + .fixup_map1 = { 1 }, + .result = REJECT, + .errstr = "cannot pass map_type 1 into func bpf_get_local_storage", + .prog_type = BPF_PROG_TYPE_CGROUP_SKB, + }, + { + "invalid cgroup storage access 2", + .insns = { + BPF_MOV64_IMM(BPF_REG_2, 0), + BPF_LD_MAP_FD(BPF_REG_1, 1), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, + BPF_FUNC_get_local_storage), + BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 1), + BPF_EXIT_INSN(), + }, + .result = REJECT, + .errstr = "fd 1 is not pointing to valid bpf_map", + .prog_type = BPF_PROG_TYPE_CGROUP_SKB, + }, + { + "invalid per-cgroup storage access 3", + .insns = { + BPF_MOV64_IMM(BPF_REG_2, 0), + BPF_LD_MAP_FD(BPF_REG_1, 0), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, + BPF_FUNC_get_local_storage), + BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 256), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 1), + BPF_MOV64_IMM(BPF_REG_0, 0), + BPF_EXIT_INSN(), + }, + .fixup_cgroup_storage = { 1 }, + .result = REJECT, + .errstr = "invalid access to map value, value_size=64 off=256 size=4", + .prog_type = BPF_PROG_TYPE_CGROUP_SKB, + }, + { + "invalid cgroup storage access 4", + .insns = { + BPF_MOV64_IMM(BPF_REG_2, 0), + BPF_LD_MAP_FD(BPF_REG_1, 0), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, + BPF_FUNC_get_local_storage), + BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, -2), + BPF_MOV64_REG(BPF_REG_0, BPF_REG_1), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 1), + BPF_EXIT_INSN(), + }, + .fixup_cgroup_storage = { 1 }, + .result = REJECT, + .errstr = "invalid access to map value, value_size=64 off=-2 size=4", + .prog_type = BPF_PROG_TYPE_CGROUP_SKB, + }, + { + "invalid cgroup storage access 5", + .insns = { + BPF_MOV64_IMM(BPF_REG_2, 7), + BPF_LD_MAP_FD(BPF_REG_1, 0), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, + BPF_FUNC_get_local_storage), + BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_0, 0), + BPF_MOV64_REG(BPF_REG_0, BPF_REG_1), + BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 1), + BPF_EXIT_INSN(), + }, + .fixup_cgroup_storage = { 1 }, + .result = REJECT, + .errstr = "get_local_storage() doesn't support non-zero flags", + .prog_type = BPF_PROG_TYPE_CGROUP_SKB, + }, { "multiple registers share map_lookup_elem result", .insns = { @@ -12436,6 +12535,19 @@ static int create_map_in_map(void) return outer_map_fd; } +static int create_cgroup_storage(void) +{ + int fd; + + fd = bpf_create_map(BPF_MAP_TYPE_CGROUP_STORAGE, + sizeof(struct bpf_cgroup_storage_key), + TEST_DATA_LEN, 0, 0); + if (fd < 0) + printf("Failed to create array '%s'!\n", strerror(errno)); + + return fd; +} + static char bpf_vlog[UINT_MAX >> 8]; static void do_test_fixup(struct bpf_test *test, struct bpf_insn *prog, @@ -12448,6 +12560,7 @@ static void do_test_fixup(struct bpf_test *test, struct bpf_insn *prog, int *fixup_prog1 = test->fixup_prog1; int *fixup_prog2 = test->fixup_prog2; int *fixup_map_in_map = test->fixup_map_in_map; + int *fixup_cgroup_storage = test->fixup_cgroup_storage; if (test->fill_helper) test->fill_helper(test); @@ -12515,6 +12628,14 @@ static void do_test_fixup(struct bpf_test *test, struct bpf_insn *prog, fixup_map_in_map++; } while (*fixup_map_in_map); } + + if (*fixup_cgroup_storage) { + map_fds[7] = create_cgroup_storage(); + do { + prog[*fixup_cgroup_storage].imm = map_fds[7]; + fixup_cgroup_storage++; + } while (*fixup_cgroup_storage); + } } static void do_test_single(struct bpf_test *test, bool unpriv, -- 2.14.4