From patchwork Wed Aug 28 19:48:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13781779 X-Patchwork-Delegate: bpf@iogearbox.net Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazolkn19012038.outbound.protection.outlook.com [52.103.32.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E01EC1A76CE; Wed, 28 Aug 2024 19:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.32.38 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724874581; cv=fail; b=h+4GO3lVCWNkZMd9A0529pY5Vvfqnp3JMrD5GjUgLiYhlw2Ls159i7Wmvwk8RY0FIdxkTLpAQpZaXL5T/ZY/V5GFOfjag72ga9veK/uLinQQafspXad7Y5cWntwfrFN8WTRV27kfg2VgGT5jOTs/hiTiQM8EMoBPpN0L72odpGs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724874581; c=relaxed/simple; bh=ZoKicK9oj7IU7ppsDSDQzxm4RrCh62YDD+8yFpPMz6Y=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=sq7THUL8b7BRv6SfgjoxLnvJVyFN9AM9/5YUMGCjVxTR2CUNJaIi3e2KpIBZyNmpLhAJw0zIMtLwRdRg6UdRSeclD4t9GFLENYQ88bLzgO1WPNpaCzghvUvuzKF01WoOo1cYpbYlzLikudXAO7OIGPyKlYG/VpAmksmas/82YSE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=MLICXYbE; arc=fail smtp.client-ip=52.103.32.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="MLICXYbE" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XOoKTnBWMh06lqafzERZcca/GQFW1q6eX8Zes+PIcMrV6UtjnmgiRpyggF+xXQau7myYZ3xl+E6e/OGsChDbGelJIcjNCUAfBB0DVMSoUYFsogSwLkU5oLUXvlGT3EiUaA+YHKEcOodOxP/cscXMNmShU8Y8OVxqzqvRa5uKh1L/LHjEi/BrgWmGJFzzINKCCTiM0ulk+HuDu7joJ6gAzCAK2CDIJ+4sj0MAxwHPRcHjruQXZBsxdbyUHMNvZ0ZZ+8b8y64AQQO8rikt/OA1cHj5cX1ZKEiVvujQSDWoOGniKFpPWWk/tpB0Zlvb0eHBVwgYmgOvoiljKFbISkA5Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=juFGlL8RNkGyKAsi+4qo6HpF4AJ7y67q2jLQ7zY7Ias=; b=RvSH2GHsHQUBeYiCu21m6zx311999ZoF1N7uyX3Npls+Ge2ClNWuny/W+6om7sMS2+Hcg1yi24A92fh1DCS7ho8rb6Qrps7vS9yM5XSSbEcYfkYUBsJyIRlCVJdmzBTAstIni642PS1Q8PAI4HdKeSYjveGh6iQ10QTdLATsLJUu4GkyItkowL0L58jd98W2DjtNnmSYX5sxwCY8v35UCbYgW1ZsvhZVH+mC6esQgdOD2RBv3C4Fw7/oBBLB1nlaOPG8UDDv1V84KLXg4cWOw2eXOb63Otwm0Ysdnv6SXLQU7y++9m61sCwH9i7z5rB7i8Ss0YnMpK1zdoS6Qu7UwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=juFGlL8RNkGyKAsi+4qo6HpF4AJ7y67q2jLQ7zY7Ias=; b=MLICXYbE0TdQNn8S3lgnXDAc+34BnEYPnRAAIixtda9sHchcPF9nwGcO2F2idmaVWOGGkPHom9Uj5PYkQoneGxYjt5XL0RfD4ETszQ8Cm82J8yi11J3cgAyMO+uAapGbnlnQAaezlPAeT7HnLVfZfsrUAQr1qVpIRLOX+hWc8AbhMIRMub44LHwkEHukUAl8TMGYYko2p1RJyYBAy4f8MRbhlciTB9HTLlscJujhIVvcmQLjzOy6Az+yFuorx5JJbW7r2bZoBBp9LzAKOExe58EzQQIpb00VTZDMNjGwo5n1vuUrS2zmEMtvA1QWN0HxrZuwl/hK1/yoGv9I+/7K2g== Received: from AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) by PAWPR03MB9785.eurprd03.prod.outlook.com (2603:10a6:102:2e4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.24; Wed, 28 Aug 2024 19:49:37 +0000 Received: from AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7]) by AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7%4]) with mapi id 15.20.7897.021; Wed, 28 Aug 2024 19:49:37 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, snorcht@gmail.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 1/2] bpf: Relax KF_ACQUIRE kfuncs strict type matching constraint Date: Wed, 28 Aug 2024 20:48:11 +0100 Message-ID: X-Mailer: git-send-email 2.39.2 X-TMN: [CN0PWSKvxgexGrenKCsp/GgYJd0mlCFi] X-ClientProxiedBy: LO4P123CA0085.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:190::18) To AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) X-Microsoft-Original-Message-ID: <20240828194811.49890-1-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5848:EE_|PAWPR03MB9785:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a5b16ed-ea33-4ca9-48a1-08dcc79a8bbb X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|8060799006|15080799006|5072599009|19110799003|3412199025|440099028; X-Microsoft-Antispam-Message-Info: NnVR/W7PH+ax0BPz2J172+EY6M7xxP3U6qgZ89Z9R23bvl8rz8lJhjYaFricGKbf8wjS5O3GvgnS+L3rbIjSUVj1avV5GJMdcIFWCdxTP6abOOrmIwB+LciBYOBrEI0V93lgMzYqtXmXdR0y/8AFbO12aa2k/xAO9TDDyfQnt1D6/tzVNapZWgicXnWJ4w0APnKzmEOEIlSNASEeI66ob3VgPArM2tZX0+hpd/b8BgB/XJURzEi1A4mnrGN7ge7ybjFM2XEzYl471pOst7Vna+dcVFBHp4JgS8KZVfgW9nutCBcccGP0FIsmVGPfIQIlyR4gXWg3942Rf7iWsB/ivaPSI5Evc5qu96iLXVX4GL9nbdLFNS9ceXGBG+GixAAojyO/3dxso/tS4UXC7Uqz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WDGYVb5k8DUQIaahG4jMqiyfubjDbrmrhF5Hn1tBiIxdzWNZqyg48Nx59vsSpHk8LDtE7h6Q/xUTq+4vx+cmJuZ1NPKxAlLzhEKhBfTRvCAog6lQTyLaz4cQwwXLdXCx3MxHLj0T4nY6a7qHH0ObYPyOW0B6sl/JdH+Elb7/pLSUM36EgYLPFz7HDx2NaizGzZUYIbbnJJe6A+b9Kzh4KJ5rN+IB+yqeloQb6p8N0AstPNDBaEWTOzXuEJpS9sv/faiVLjmKzhpDddmIPFEGS+ERU1cr1u/44h0MW4smczR1b0ctBJmYi2calpEI76Y+afofNDHE+u6gILpOYxd/QYzul07ye2q2wCOyKiYjy6swTRFGw3yJQwCOozxA2xo2d6mp9Ndb37d3scQPRZ9K8/Baf4XImg3Xsy8acnI5cWXb71dQFGYtNUTNVEterE79Guobk3jFmyVXngNoaSDGLQMKybnlTsZ7lO7c9dJhzM2eRlOtsp0Bz7/Co39+PvrcCoN8cMRV+0m2N73IGJvSHlftryun+surIw3eFfyw9hN+w6vx3T3Oogpraa4Ja5x6fQja9GbMNn0CuKzr1gKZLlGHqTiaucvsNs9OiEpicQUlflS6 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a5b16ed-ea33-4ca9-48a1-08dcc79a8bbb X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5848.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2024 19:49:37.0942 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR03MB9785 X-Patchwork-Delegate: bpf@iogearbox.net Currently we cannot pass zero offset (implicit cast) or non-zero offset pointers to KF_ACQUIRE kfuncs. This is because KF_ACQUIRE kfuncs requires strict type matching, but zero offset or non-zero offset does not change the type of pointer, which causes the ebpf program to be rejected by the verifier. This can cause some problems, one example is that bpf_skb_peek_tail kfunc [0] cannot be implemented by just passing in non-zero offset pointers. We cannot pass pointers like &sk->sk_write_queue (non-zero offset) or &sk->__sk_common (zero offset) to KF_ACQUIRE kfuncs. This patch makes KF_ACQUIRE kfuncs not require strict type matching. [0]: https://lore.kernel.org/bpf/AM6PR03MB5848CA39CB4B7A4397D380B099B12@AM6PR03MB5848.eurprd03.prod.outlook.com/ Signed-off-by: Juntong Deng --- v1 -> v2: Completely remove strict type matching for KF_ACQUIRE kfuncs kernel/bpf/verifier.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 5437dca56159..0f3b6fa3db39 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -11497,8 +11497,7 @@ static int process_kf_arg_ptr_to_btf_id(struct bpf_verifier_env *env, * btf_struct_ids_match() to walk the struct at the 0th offset, and * resolve types. */ - if (is_kfunc_acquire(meta) || - (is_kfunc_release(meta) && reg->ref_obj_id) || + if ((is_kfunc_release(meta) && reg->ref_obj_id) || btf_type_ids_nocast_alias(&env->log, reg_btf, reg_ref_id, meta->btf, ref_id)) strict_type_match = true; From patchwork Wed Aug 28 19:51:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13781780 X-Patchwork-Delegate: bpf@iogearbox.net Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazolkn19011034.outbound.protection.outlook.com [52.103.33.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09C85189511; Wed, 28 Aug 2024 19:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.33.34 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724874722; cv=fail; b=OaELbaoqQ9A5C3xfiQTT58xQ7OuRP+Bs5x4Sj111TILQ2tLu9+IofPVGUWxPbQivQ4Us0wOREhofl+o3xbzRGSMosfv9Bz4xGwfonRcsldYNB0FJCevURHeILufghimaoBsUgwnwzmF5FXcLwzEy5+EJcRxmfj2NkZ74gXAoFOQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724874722; c=relaxed/simple; bh=I+PRF25M7jfBqRgW2Ga7WKjqfRzrL9d3hmcjmGC05ks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=VxG/H0rd6kkVnYFmEYczmfyCuleQfqZlW3vo8/4XCYcecLKIHSYXadzOXyLTEVCFIMzz1aBlnniolBiiPstK/F6UnrEtgaenoXgGdUSyghzYDyr+s6aYLYx6nvpGsVPAJj0m84JRoYLNZjMHyV18pHRs36zBm3SD1tS+qoXUDmw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=GS0kQ2Cj; arc=fail smtp.client-ip=52.103.33.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="GS0kQ2Cj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EMHTIxIG5Cla0Y9BsGAhrE02NBIooSNtWFU6qhu5zlujjs2DYUShluDGW6iwPpk0WnTovNLC0jxyfhiTdlvDT0xDZwNgtFAK8SJVrmQkMH9rxN9fiogcKW0OnJqin1Y3HsX8Y4s9FdTGiaTUAPmDHRMQDuW05YXIG/pzY19CMFguYqViTrP5jmvv/TXEnec8XI90xMfiKWgZ+G0cwoCNG0/ifhMoaelJfQfN5SeiczET8aHdNI13TtS5ssdGKuSTe8hanU0ffkOVRXvqVwT8cuzlnOVIMVcMj8j/fNycRV4kY7iRhYn/kRyLYnh5Gc1VoHI5kGZmTEINHLX0R9O5Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XRzYS+j2NqWHTDb4LpZDygrfOUTmSmzG8CChrzTWgHI=; b=JimFrS4FyAT6lkx5MG2bx5lz2ix4M5XW6x6BeLBSykSgcE05aDhFDxWtQ1SlSuj335mXrxJfBtDQ2F34o93vUs2nGMAJU9XIQgl0DgBeWN7Kz81DWo9LcOAq9XTWtZtPZ8u3nGQjPHM28JKa6h+Tfx5cPZTe0/cw4GwZua9pCxxW9SO+7ZqDwpPcBd66kcAVMiexnFSypyou7hnQFeKoKUcrESrdOcdC0scU79MHmtrgXu1s+7TlR3tC8PT61CevGkf8VxRCAUEbhvAaGgSVYvGN2L9Xn6wUSRcnvBZH7EbK/8x+x+ruJ/WIvSFbBhkZq9BXUd/FkZuLa+uQzOszZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XRzYS+j2NqWHTDb4LpZDygrfOUTmSmzG8CChrzTWgHI=; b=GS0kQ2Cjuyn8sqnbc0eh3D8wzGxc7q7qrvbPxbHw2ArLcu6E9sfY8nPJzQ/GF/tAUtQFpkvuGrXD07vqaLRePAshWz8EVF3jdQu3C1E02LlA+mGYemW1anK3Y9eqXnGN0BHhRIc4mKttOnmpaUHZyzTxpM9EzRaObHkZ6EilGqF92O9VaNemeWfuuxxC51sWvVjMbqisaXOWYN559mVmDzEqzC7e3/7aYh1GEiCv6OW0M/udhyo4pa8hgimqqRJ3OBOWrekJzAnxltZChNCIruHMZFMIgDfNMnWay0zQFoX2xJ7srNjKuvU0XuHGUwTGKMIH5wtT38dsj4kVhBsp6A== Received: from AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) by PAWPR03MB9785.eurprd03.prod.outlook.com (2603:10a6:102:2e4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.24; Wed, 28 Aug 2024 19:51:58 +0000 Received: from AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7]) by AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7%4]) with mapi id 15.20.7897.021; Wed, 28 Aug 2024 19:51:58 +0000 From: Juntong Deng To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, memxor@gmail.com, snorcht@gmail.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 2/2] selftests/bpf: Add test for zero offset or non-zero offset pointers as KF_ACQUIRE kfuncs argument Date: Wed, 28 Aug 2024 20:51:32 +0100 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-TMN: [0BW342BtYrawydNSq+Wc5V8bxSrN52Gb] X-ClientProxiedBy: LO4P123CA0531.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2c5::15) To AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) X-Microsoft-Original-Message-ID: <20240828195132.50260-1-juntong.deng@outlook.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR03MB5848:EE_|PAWPR03MB9785:EE_ X-MS-Office365-Filtering-Correlation-Id: abc03ebf-59d0-4048-f9ff-08dcc79ae027 X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|8060799006|15080799006|5072599009|19110799003|3412199025|440099028; X-Microsoft-Antispam-Message-Info: ElpsPg1MvCmqFkQJfgQyZvxgx5exuwIsUW08NEhNhq2DgRU4jaLiUDZOMC5JZneOawjXvrUocDPjzsko2ZLk2wLDLNBZeK3mqoHPSY0GWB1tEp5Nupr7IdBDKSQN/OnTyKPvmMsiv1JP5JC2NhYRILU1ocq/CJrfOAUsCELWhKQo7x1DU7HEGIQSJnVplVYcwY0u79VSJfnugVffOY4Gpy/4X0UxBaGkcV4wmPwU9gO+uEtqtglwVWSxRj/xEP11di/dJsyj+Rk3wwSKHiUY+X7/YTBgf2B0ij8x0AF58o/EN5EXBSz4HHbPx1GsPRcgT7G1Hd2/YtoG2V9gS/ObPfQf2xb+Krs3zRoTIP1OaitrxlMRIgKs2XUhXtnsyjVvReXAWGPVgaIqXGPo4yTmbpEFNyYvp2nzfX3+KkqvKKDI9bx0q35Pzoiv7kALiHUPE4WMxQcExFlFnKGi40S2ixn8H+arFW76q6gbqqB8hLggI2e9AF+CPClTS5eiQDu5SXHUnv1TfTvjAEPspTJyJFGiRVZ0WXvl5aicJLmo7+vbksbnW+TMRh/XYOeeQEFR05KannER+b4rjGbP8aMVy9msdg/XrZiNfhHW5RXV3BXzDL1Ovkx+VMJ3MOcl7rCNdGqTBOTluJKZW8ZferJ7+rYsNtDek/vXjuiV7VrBxvnAMtfYsBbnJ3Lh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gKOC/CIGyzzFzHti753oAjTQ//XDSJRaHVyZeoBFnAnpMd7nZtazU9C3/8IC6n96vJMgBK7+sEj9tHuuhrW+R9qkUn8d9xCPTqRN6pc8oxJ+wFAf5eTdmIR2CvUoXy8PQ4LRJFNFkzqhaGGeiYftvWC2xptEUMZ1t98qHlsdQTZ1hwzL3DX9OZvN7riC7Qa0dKgajdQ/SEPu11r6j1J5ei77+iZ4w5fvUdfRa7BYBAd+eXaMxPAxZxHcHC0ltg+Q/KhRk9mFdKtzoXz5LeA+NysbxlEuewT9S90dJpLA1qLND X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: abc03ebf-59d0-4048-f9ff-08dcc79ae027 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5848.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2024 19:51:58.1941 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR03MB9785 X-Patchwork-Delegate: bpf@iogearbox.net This patch adds test cases for zero offset (implicit cast) or non-zero offset pointer as KF_ACQUIRE kfuncs argument. Currently KF_ACQUIRE kfuncs should support passing in pointers like &sk->sk_write_queue (non-zero offset) or &sk->__sk_common (zero offset) and not be rejected by the verifier. Signed-off-by: Juntong Deng --- .../selftests/bpf/bpf_testmod/bpf_testmod.c | 17 ++++++++++ .../bpf/bpf_testmod/bpf_testmod_kfunc.h | 4 +++ .../selftests/bpf/prog_tests/nested_trust.c | 4 +++ .../selftests/bpf/progs/nested_acquire.c | 33 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/nested_acquire.c diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c index bbf9442f0722..e8b34aeef232 100644 --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c @@ -183,6 +183,20 @@ __bpf_kfunc void bpf_kfunc_dynptr_test(struct bpf_dynptr *ptr, { } +__bpf_kfunc struct sk_buff *bpf_kfunc_nested_acquire_nonzero_offset_test(struct sk_buff_head *ptr) +{ + return NULL; +} + +__bpf_kfunc struct sk_buff *bpf_kfunc_nested_acquire_zero_offset_test(struct sock_common *ptr) +{ + return NULL; +} + +__bpf_kfunc void bpf_kfunc_nested_release_test(struct sk_buff *ptr) +{ +} + __bpf_kfunc struct bpf_testmod_ctx * bpf_testmod_ctx_create(int *err) { @@ -541,6 +555,9 @@ BTF_ID_FLAGS(func, bpf_iter_testmod_seq_destroy, KF_ITER_DESTROY) BTF_ID_FLAGS(func, bpf_iter_testmod_seq_value) BTF_ID_FLAGS(func, bpf_kfunc_common_test) BTF_ID_FLAGS(func, bpf_kfunc_dynptr_test) +BTF_ID_FLAGS(func, bpf_kfunc_nested_acquire_nonzero_offset_test, KF_ACQUIRE) +BTF_ID_FLAGS(func, bpf_kfunc_nested_acquire_zero_offset_test, KF_ACQUIRE) +BTF_ID_FLAGS(func, bpf_kfunc_nested_release_test, KF_RELEASE) BTF_ID_FLAGS(func, bpf_testmod_ctx_create, KF_ACQUIRE | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_testmod_ctx_release, KF_RELEASE) BTF_KFUNCS_END(bpf_testmod_common_kfunc_ids) diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod_kfunc.h b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod_kfunc.h index e587a79f2239..c6c314965bb1 100644 --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod_kfunc.h +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod_kfunc.h @@ -144,4 +144,8 @@ void bpf_kfunc_dynptr_test(struct bpf_dynptr *ptr, struct bpf_dynptr *ptr__nulla struct bpf_testmod_ctx *bpf_testmod_ctx_create(int *err) __ksym; void bpf_testmod_ctx_release(struct bpf_testmod_ctx *ctx) __ksym; +struct sk_buff *bpf_kfunc_nested_acquire_nonzero_offset_test(struct sk_buff_head *ptr) __ksym; +struct sk_buff *bpf_kfunc_nested_acquire_zero_offset_test(struct sock_common *ptr) __ksym; +void bpf_kfunc_nested_release_test(struct sk_buff *ptr) __ksym; + #endif /* _BPF_TESTMOD_KFUNC_H */ diff --git a/tools/testing/selftests/bpf/prog_tests/nested_trust.c b/tools/testing/selftests/bpf/prog_tests/nested_trust.c index 39886f58924e..54a112ad5f9c 100644 --- a/tools/testing/selftests/bpf/prog_tests/nested_trust.c +++ b/tools/testing/selftests/bpf/prog_tests/nested_trust.c @@ -4,9 +4,13 @@ #include #include "nested_trust_failure.skel.h" #include "nested_trust_success.skel.h" +#include "nested_acquire.skel.h" void test_nested_trust(void) { RUN_TESTS(nested_trust_success); RUN_TESTS(nested_trust_failure); + + if (env.has_testmod) + RUN_TESTS(nested_acquire); } diff --git a/tools/testing/selftests/bpf/progs/nested_acquire.c b/tools/testing/selftests/bpf/progs/nested_acquire.c new file mode 100644 index 000000000000..8e521a21d995 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/nested_acquire.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include "bpf_misc.h" +#include "../bpf_testmod/bpf_testmod_kfunc.h" + +char _license[] SEC("license") = "GPL"; + +SEC("tp_btf/tcp_probe") +__success +int BPF_PROG(test_nested_acquire_nonzero, struct sock *sk, struct sk_buff *skb) +{ + struct sk_buff *ptr; + + ptr = bpf_kfunc_nested_acquire_nonzero_offset_test(&sk->sk_write_queue); + + bpf_kfunc_nested_release_test(ptr); + return 0; +} + +SEC("tp_btf/tcp_probe") +__success +int BPF_PROG(test_nested_acquire_zero, struct sock *sk, struct sk_buff *skb) +{ + struct sk_buff *ptr; + + ptr = bpf_kfunc_nested_acquire_zero_offset_test(&sk->__sk_common); + + bpf_kfunc_nested_release_test(ptr); + return 0; +}