From patchwork Fri Aug 16 13:23:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13766283 X-Patchwork-Delegate: bpf@iogearbox.net Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazolkn19012037.outbound.protection.outlook.com [52.103.32.37]) (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 BF9D41991AA; Fri, 16 Aug 2024 13:24:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.32.37 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723814695; cv=fail; b=FC0KkvkcnkoTwUZEKzg0ZoTw3nVBnB2gpT329LsUftm/DxfNtOokZuhz84ONvdNLNTYSstLBN/XhzJwQ0gc+JXw24gJq/i2pi2iMnIJruk1qcPiMKgffRXcZ7oVVeonQCQSEodEIDzR8Z+HOrnZMEg1RFejipokzio+wNa/YIHU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723814695; c=relaxed/simple; bh=DIPaif9KOnQCMu4st9jInd6mAz04X2wRYi3ybIXxK8s=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=MkSFU/rZDI7qNkxmt1Vg6UvggcwQKwwKKHDufosp2Ug2OjYHZ8Rd/6erZW6V7gcXoGzGG3P2fUWJnrdzqfTRtbPM3oMDsKFv6TkGEKuCyWjHZ/5ZcnceXQFoj3H5fw5fLVz9rXnfZPvDUtIDMiBalE5QHvtLd7sKGoXZL0cfQFU= 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=foCai1ZX; arc=fail smtp.client-ip=52.103.32.37 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="foCai1ZX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dCcD+7rSSWKeHjypyw+JLYcqTa5DKpSpggDu/6ZAmwEChGgb1/M4z2uk0wkn5PrWZhiOINSZqjxipQcYtUKDmhGaUC6yxDOdxG/ckptfhyECYivh121T8sgYLNjdiHjixalBIRooCOI8iRHtcuXPTWqpWmNtqKHUuPpnXGTTQvFcexhbqvcFvS0e9Gv5UcCfZ3DVICPiDOyA4yrxPSQSbZJpSw5sExs7/kWiHb/ZEIeIdRJIb3G/DQ/tQYI3Qv+P414b9XXzEy/MFKJujqxBLeleOUtktTc1sqP9y8ethOCxfQ1R9tL9pdrARUkonkHlxxqHrdMftdwLRzvu3bvEmg== 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=j/XQ47pUxDZdsoP4M7Icy3OjxlBgUE7ZciSA7rr6XPQ=; b=Kru/YLk8mZPmlXYBxz94KdarraMv0D1fr9quYZr+e5MsL/2gT8YkP7rbOYliRXqAiM4bX2Rk1/kCWAr7MLmilv4DkNEIbHU7HyP8QIo+6/zQaFb5WFIwabLhbVQ4mdKlj/WdgYRwVcYRlfZ9LXYDPVlOorMAkxciig1eO2JghQm9WNVNDPR/Cs9eD+DVfUKqTtsXLwY8bEWzgRtjyMbL7hfKqwuU5UW8T5WF99FFz+Ebf2bDNpsERCEztOHpne3PqlGmSVov/VZl2A4pmbIvhzhObsd0JzezTWSutPT8MQCiGcM/kZ9v2LOgXtI9zf7lAD15lqwfpudDG8TRn+737w== 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=j/XQ47pUxDZdsoP4M7Icy3OjxlBgUE7ZciSA7rr6XPQ=; b=foCai1ZXvnWv/LZX3NVSIj0CGt7THC9xrZ6pcgf9jP4IeFMorVlkJ08TPxnZZ3/+Ti7iwNX4d/bEAjy8cWaEZvKXbRG6hCemB3I4bHYESWlOPsum36enIOleBkJSDZkyPDQuasYfY7TiZyUU8p8IbSyf006OCELPS0YXT98Ql99sgBnm7rcOI3kKQ4NllcYjH81G3aXwaq8YGGhQ6B6Jw6IoTMDWbM0+dTOA9af3h9P5XxeGDz+TUqQcKV+FN3Ynta19GgkORdNYaMsOURH9wBIkOzyKkWWKInm01rsteu1T0lXsa9QvgExSpafpmVVWWR4w6FV2pCw4Wnn6UxOixg== Received: from AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) by PA6PR03MB10532.eurprd03.prod.outlook.com (2603:10a6:102:3d9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Fri, 16 Aug 2024 13:24:51 +0000 Received: from AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7]) by AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7%6]) with mapi id 15.20.7875.016; Fri, 16 Aug 2024 13:24:50 +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 Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 1/2] bpf: Relax KF_ACQUIRE kfuncs strict type matching constraint on non-zero offset pointers Date: Fri, 16 Aug 2024 14:23:17 +0100 Message-ID: X-Mailer: git-send-email 2.39.2 X-TMN: [wyO3448nLk3qM8VrpKpIF1KMGgHcIb9n] X-ClientProxiedBy: SG2PR04CA0188.apcprd04.prod.outlook.com (2603:1096:4:14::26) To AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) X-Microsoft-Original-Message-ID: <20240816132317.87475-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_|PA6PR03MB10532:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a5b9045-dbb0-49a8-67b6-08dcbdf6cd96 X-Microsoft-Antispam: BCL:0;ARA:14566002|8060799006|461199028|15080799003|19110799003|5072599009|440099028|3412199025; X-Microsoft-Antispam-Message-Info: f9ehTovk8rXCQOg89CjJ7NcO9iiW6fLRwOqA03ajZq10XQy0p6fk8aqy6lVrnvteajhqb41z2vQKM33fymDxfJfJ4cT+o9//3qiXfv96givuIeY1u6/Js979Vn8PWmAK7DrtWGj0wLso9Gwo30TPpAtCSRPbF6oMJ9LbKxezPDkkJexcaRAh75LYppAFTXWiY5ytBkIS+6wIPrqtVaGrCLMOE6Ys6ujCql/rLYQ45+mqav9hNgc6SyUC/IXFj3HKVfdHwhrfuR9X7dP5v+OMhSzbzLyhVT7rOImvgKSFgQjl5B9+vj/29AStMNuSsKkl6NnRw+pkMc7JGIXef/bMZPObgxh1ks1M64jBLnaJfV6NQ3/3Uwq6+KClvouYVl2EDFGmJURgNkabVp8m/YpjOvsRaZbfwsBiwKR2O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Nvb0LW61Y1z8TX9aDIJp4pJH3Shc2nw9KTjgKKebYKkSkhULd1xSTson/HAvoTio1yh74e6QCIvD1Q+1ixj3y5BrSH3rYdAY9ysaCBvtEUsc9CWuyRfbXvcO0DEgRv2KmnI5r8BfaBKuxxFeeK+QEQp+8XOZHxZ7p8LmazBZ5fcF3088EZErwlc5UHqXCD6vZ0Y+bfYY6IHvUPnHDbC+Hk3Cv8I5cWqzwkSw8miNWN43PoSPrqcSDkymM5c1I91Py1h+M5cRPPIP1jaBYdrqTuDnfupcD2gpLYtIhP9Xhu4WODhmRyiR0aXBHdCxegB+X0Lh0NxUx/eG4+TVJvu5dBL6GgKLp48H46ONb9MmNXPK7K8zMJ6ru08QtGXn7FRyDqCFI+Dfr5i2sywEetvunsexT41WUaWDgb1jtV9sxBiKadnXUWw5BG/WrWWwuxlEm7TcGLqr4YNThG0q5TKSMEwTWps4U2lON1m+W6OQClYPqApW0/+6HRFmL/yIaL30p1agfBZ7cl8z0ryy8o1nMu2Hlqjvd4f39Fjt29BLyjOSTHytbbppspjfmpdES1UDaQ8oVl2Ys3XaVgk/+c2g6ak X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a5b9045-dbb0-49a8-67b6-08dcbdf6cd96 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5848.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 13:24:50.6718 (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: PA6PR03MB10532 X-Patchwork-Delegate: bpf@iogearbox.net Currently the non-zero offset pointer constraint for KF_TRUSTED_ARGS kfuncs has been relaxed in commit 605c96997d89 ("bpf: relax zero fixed offset constraint on KF_TRUSTED_ARGS/KF_RCU"), which means that non-zero offset does not affect whether a pointer is valid. But currently we still cannot pass non-zero offset pointers to KF_ACQUIRE kfuncs. This is because KF_ACQUIRE kfuncs requires strict type matching, but 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. This patch makes KF_ACQUIRE kfuncs not require strict type matching on non-zero offset pointers. [0]: https://lore.kernel.org/bpf/AM6PR03MB5848CA39CB4B7A4397D380B099B12@AM6PR03MB5848.eurprd03.prod.outlook.com/ Signed-off-by: Juntong Deng --- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index ebec74c28ae3..3a14002d24a0 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -11484,7 +11484,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) || + if ((is_kfunc_acquire(meta) && !reg->off) || (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 Fri Aug 16 13:27:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juntong Deng X-Patchwork-Id: 13766304 X-Patchwork-Delegate: bpf@iogearbox.net Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2078.outbound.protection.outlook.com [40.92.89.78]) (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 4803D38F91; Fri, 16 Aug 2024 13:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.89.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723815022; cv=fail; b=LEXumiWo8AqOgBqsAotRGzsZIkiZW82Bzd3enDYdlpcSYLqgFITU3hf22lfocy4TUar/sibJ/T66bOoUEvdKQh3lRTgl89THVySP4tI5vA2ceiYkVHsTEPJbAJlLJvmlX3v+k06U+D5po7WJs+Tjfu8vFx//bNNXhNET8bnt1zQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723815022; c=relaxed/simple; bh=W9UUy4sq698REGpFb/ZT/J9nFi34ad5lo3r9ZIEgKr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=mhEyjvYOZizuPh7frJV2aHOEJj11vh21j7kYIFpIqpS1aBfLUdAxOSMeu5OU/6YBeM9/3gH43OTIJ0spet0PVq86Y0UHe6S0UXuccl/jtlyJam++9BrFFEXIf+8zT4TkoxaJ7F9JGm2oVwRXLDqMQq1l7OOOgxM2D1oPOXYPvAI= 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=MpKrGBgT; arc=fail smtp.client-ip=40.92.89.78 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="MpKrGBgT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nnnAoP5Q0lsAPKunOF17eHpBX6hzLjqEWtiM7mBn3buaaLPU0GCUALiJ5v0eGNyq6oPfRlADTXxDG2+6hU9mrLc8/f00LkzZWkqHvqyKFftUdthAreI9F0ldA0+Tefkvu5BckaI/jcFVirFO5Xltwm+l5vJgieUksmqHG4XjN6bM8LGpbC5z4CN77yxywbpDgKHU9Edc+omQizugkNrzp1xfBsI25ORQuyS2qlUnP/Cz/TZFgMk37Do9AX5Sm46ksNcUl6c0NEScYRqg8Nxcm4VWQRhtY2FVpKIZ+L2Q+AkW5j9JFQYomelXI15GQyEeUv6QUSS1iWCKdpQx7MdrBQ== 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=blutEk5NaIEsjjxv4y8HcBLZ0ek1xwg8JjcdxgqAY/A=; b=GpnGistHZN83/3/8RA6gDkYTrAWtWy/QFX3dKtU4DDEtirCWmIb0NvsWNlRX/aq2xT+9tlOvGrraYutrRZyWZfipg8+1HajKOSqffvM96Wn7xkf/Oo9CCg2UD9ShP5PtKmJUjg28bQaKcrB4Ea2hdEOZPC50Cd1ns/iTIlDOX+8GuWmeTh+TFGR7KehQYn+lgSw9BOdMXR6l1na34AHphKBZYOzuC9g7USZYUmJSoerexdtxBDfYhzvrlD0jYss37p3ZfiQFi5FqR8YlUcLqssf6dofnEbF3ecgxT9Vf2m7DKSMSBxf8c89cbY2JXQCFsA6XRoFqc4iNJ84SVjyTYg== 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=blutEk5NaIEsjjxv4y8HcBLZ0ek1xwg8JjcdxgqAY/A=; b=MpKrGBgTKeSs7yY4lPquqpgj8w2V2cKgG/PlVhtup/Eluu9t7oquMRboAPRW+vl6aDgHAcjp8Goxg8Uop2IUYp9C/d/GeLUv6+c+R0rrp+HFwRmLyeNPd+uRJXS+sIKueUuIfC3xm9fvV4vrSzi7VHIeDaKl4mt4EtZQg4t5eJm44EGf7nBKDfLurYcTtfzaAo8D3NRDrubIDb3GezMgnvBs5inUc8nfu3ZcMJfZinEV1SoJPTZIbJ6nZBgD3KNxcv6E+ASq7KloKmSnb8U6Eob6LnTaqW/2ErCrBGmmfOGNPTnw/aNe8bxmEF55V2TMwY5xvk05TAEVrAiEzkGvmg== Received: from AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) by DB9PR03MB7788.eurprd03.prod.outlook.com (2603:10a6:10:2cf::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Fri, 16 Aug 2024 13:30:17 +0000 Received: from AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7]) by AM6PR03MB5848.eurprd03.prod.outlook.com ([fe80::4b97:bbdb:e0ac:6f7%6]) with mapi id 15.20.7875.016; Fri, 16 Aug 2024 13:30:17 +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 Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/2] selftests/bpf: Add test for non-zero offset pointer as KF_ACQUIRE kfuncs argument Date: Fri, 16 Aug 2024 14:27:37 +0100 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-TMN: [EGe+5b4KG4e6ctrVoTJDZAoCPO5aWYhc] X-ClientProxiedBy: SG2PR03CA0126.apcprd03.prod.outlook.com (2603:1096:4:91::30) To AM6PR03MB5848.eurprd03.prod.outlook.com (2603:10a6:20b:e4::10) X-Microsoft-Original-Message-ID: <20240816132737.88005-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_|DB9PR03MB7788:EE_ X-MS-Office365-Filtering-Correlation-Id: bc4c0a58-b39a-46bf-81a6-08dcbdf790ea X-Microsoft-Antispam: BCL:0;ARA:14566002|19110799003|15080799003|5072599009|461199028|8060799006|3412199025|440099028; X-Microsoft-Antispam-Message-Info: 9aawJcROkUuxvAcbPBW1/XzMtVXA3Uh+cs7yp2tPw66BaV9qIKBDyo4teeFb6YIFJLt2A0DQoH9LY8nrGS2fd3ZJMPFh/upzXSIfoGl/dOd9HP2plcrRNAPM7uYFwAfvg34YvPN8AeU7spvC9n1mlYuT+hkxfZItBgdSNV9QBL5s8yxrJ0edE+t4b5CHLojq8/FbyAljYWpFGgq1V7XswiSyaa/CTrm/2kUbsYaj1t2VhfEb4uBJlG7ZyME31/UJewwe4KRdIGCZMz0EaX2HUNLcArDlBPelGDf6hcee+QhvI1jfUONJCTVq8i3DhY7Cz4LGWYLq45+2mtF6JWL9ApSy+8ux6T7CLLiWC8uxUzAHD751MZ/fpwMeNMKJZ4He/6ynZzSXmPall7jwdFx+mkwx5m0prgja/fX7PIlJAmxsp4Vl8loCh435LDJlagmMAi2pcA1dHX6JXd/tMKzbxvnuPOqoKjMGda8dXRQmqsBB/3U0o9IGaAViFPgHYOlYM1qRhNMyn7QcGqyj+yLNKg5qzdpsPbge4lDl/8VsDgaRfn75JHiQEBfgxC6q/pISqTa0QHJUPSzG6Av+zHqVrLW1+ioAbQ5pjfuXi3R3zCwaPfsJl+5EHEeiSgdrfkTlBvE0gef+NUx/tJiJC2FUx8L/lyTgtFzNf2l6Q/pwA77pw9Af02UNBarGHNlBRNlPsSvvlpy62ww904JA6ac12A== X-MS-Exchange-AntiSpam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T94fEx4RlQrxOR4Y2vwWx84UEFXOKv0i/B4SgQpoke+P6zMSNCRGfvN0kly9i3b6y4PQiltaTm5yfcY80JZHXsDrfq9BH+BDQmdgHoM3jh3c/J+djSfPU1LOuPPVxG1p4PAmaEcYK7mknw2g0qy4aA8ahR+s9gizKfXFMnDnptpw73c/SOl8P7mEXIM2bFSd3F7LVZFkpg0KWqwRBSIl1M6w9SjBfu9BZvFg7aHdnAsUEPpVSsa42C3w8bR3FMlFv X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc4c0a58-b39a-46bf-81a6-08dcbdf790ea X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5848.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 13:30:16.9456 (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: DB9PR03MB7788 X-Patchwork-Delegate: bpf@iogearbox.net This patch adds a test case for non-zero offset pointer as KF_ACQUIRE kfuncs argument. Currently KF_ACQUIRE kfuncs should support passing in pointers like &sk->sk_write_queue and not be rejected by the verifier. Signed-off-by: Juntong Deng --- .../selftests/bpf/bpf_testmod/bpf_testmod.c | 11 ++++++++++ .../bpf/bpf_testmod/bpf_testmod_kfunc.h | 3 +++ .../selftests/bpf/prog_tests/nested_trust.c | 4 ++++ .../selftests/bpf/progs/nested_acquire.c | 21 +++++++++++++++++++ 4 files changed, 39 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 a80b0d2c6f38..d742b91af270 100644 --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c @@ -176,6 +176,15 @@ __bpf_kfunc void bpf_kfunc_dynptr_test(struct bpf_dynptr *ptr, { } +__bpf_kfunc struct sk_buff *bpf_kfunc_nested_acquire_test(struct sk_buff_head *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) { @@ -533,6 +542,8 @@ BTF_ID_FLAGS(func, bpf_iter_testmod_seq_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_testmod_seq_destroy, KF_ITER_DESTROY) BTF_ID_FLAGS(func, bpf_kfunc_common_test) BTF_ID_FLAGS(func, bpf_kfunc_dynptr_test) +BTF_ID_FLAGS(func, bpf_kfunc_nested_acquire_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..7213d77717c1 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,7 @@ 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_test(struct sk_buff_head *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..5e3a499afd6f --- /dev/null +++ b/tools/testing/selftests/bpf/progs/nested_acquire.c @@ -0,0 +1,21 @@ +// 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, struct sock *sk, struct sk_buff *skb) +{ + struct sk_buff *ptr; + + ptr = bpf_kfunc_nested_acquire_test(&sk->sk_write_queue); + + bpf_kfunc_nested_release_test(ptr); + return 0; +}