From patchwork Thu Apr 28 16:53:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12831052 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AACDBC433EF for ; Thu, 28 Apr 2022 16:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234322AbiD1Q5Q (ORCPT ); Thu, 28 Apr 2022 12:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231442AbiD1Q5P (ORCPT ); Thu, 28 Apr 2022 12:57:15 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF45E9D04F for ; Thu, 28 Apr 2022 09:54:00 -0700 (PDT) Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 23SG7bkY026710 for ; Thu, 28 Apr 2022 09:54:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=qYYfM4jpQsgZ1I4zj/9WHIp6BYyP77ofjCQWx+xmyUY=; b=ezndlwqYX3Ac5Ew5Lz4Kg3Msu4nXH3FCZ1iYugaIupijMUtmZkE79H2dxKKtserz1Y06 BrpGe1eiyCx0aKXd6AW7vO7gvfqLspd0X7puTM1ZXqmtQDjlWFf8VCvtaivVWE56AIuD jvCP8yyFJix/9HgfcrYQFganJHaGtl9CKqY= Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2173.outbound.protection.outlook.com [104.47.73.173]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3fqm5r40r4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Apr 2022 09:53:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FvDr2Z3exsFPQDHGLx5/UrhMWjxmChbfBUyadc6zoQXP6YN7ZYeZUupK3qS1fbCF00WEOypFm5t1PihesqjR+iWTUT5KPDKgGgZ1rtVb//nSxWtnxlbiNgNdAt4lePpIw063WQRb2qwQrQXkhjdndNTgBqGhmibcDaOOkSyM22fpREv3VYPh4kXu2Qmzi7O+zbIqu9xsLuIJGG7NH+Dth9suf93mdukC5yHcS6b4s84qaKeGoFiptvb6q2ME61q5Tpx02sdV0K6oPTCPpZcWIDkHVghwh25rOn1GpBYndzkgOId2I1OYZGUfyeTcCmXPNtF5dp/0qgvYOdIEVBgaVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=qYYfM4jpQsgZ1I4zj/9WHIp6BYyP77ofjCQWx+xmyUY=; b=LfR+Lu9GQKAgKMtlLi7TtP4FvbHzZMx+63MvkC7u2VAe2LoyOAnphMHrA7y3EBw0ZYvaq9qkPB2hT3Kej4uDv05tDh25MaCHE3+2enDTuLcMO/eLyjlhOf9k+iqNSlb9OuJ+0KoxvKdq/YKyDU8hXxXNrpI7xcmQtq42oNCHE25p5GbucFJ97RIAgSF7LExH8e9OymEG824frx1C37PThV7vouzlKA285b1S91yUkeROS1+QkmjpJ1DBASkfQ6dCdZuM89dchdNnJgKdEhQQaN41RKerMa7v4sofGNIgLWpaRMb+qv+8ilf4RIqLL45zXMqRvLg2lSc28pWsYtFbuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from SJ0PR15MB5154.namprd15.prod.outlook.com (2603:10b6:a03:423::6) by SJ0PR15MB4615.namprd15.prod.outlook.com (2603:10b6:a03:37c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 28 Apr 2022 16:53:56 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::b5e0:1df4:e09d:6b5b%4]) with mapi id 15.20.5186.020; Thu, 28 Apr 2022 16:53:56 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next 5/5] selftests/bpf: add tests for sleepable kprobes and uprobes Thread-Topic: [PATCH bpf-next 5/5] selftests/bpf: add tests for sleepable kprobes and uprobes Thread-Index: AQHYWyCMsgxlJnSFd0GLBqB/JA91PQ== Date: Thu, 28 Apr 2022 16:53:56 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8c8b085e-f00f-4fa3-f3b2-08da2937aefb x-ms-traffictypediagnostic: SJ0PR15MB4615:EE_ x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RpLh6jtWv37rydXAnaI64qJKSJZY4hBrNoC/eaT2gbiXCEbK6W4uH0P4wvRVRfZNISImNOf+pXDdxSu769Sj0nmMwg5cLcPhjRjk9JR1kRhsACnbS2pKzGbxqt2TOtlI4/oQFGXvZFY76vPV2+jAwiiAEst3hewcSHqLgL5osOI6a34C1KFMi4kQNaN7uGRImEKlEdAF5/fcnuKaD1rpEV9I/RUJubOJVZtzA791N10cF85Oa7lfNXpJB3OKzAWLJHE7ZH0cdI6cBKuW1XPrY4d+Q5yh7fN51t+P0it3+qzmVQ5wXNdnEYcC65mOjtXbeq/cdqaF8NEyRCTh/wndeN0cjk+t82ZMrEbCxeLzomVVmxGoMUVfOu5fEYK26AZmN9yGKsPZwBR/dDk3fC3vY8tDeyYwgGaJIePG/PQzMztTyXKZBuRiG/7nQ0k1E7tYJfxxrmnEbuKrad2v4Cq9Uw3+g1LyNyJ+Hcl/nPpDX+jPRSFbFumj2mtDr6a27JwFbsN9Bs02a+NVCcX/dak9Nsf+NN8vP2cFzIy7gUQ3EA7XpFfUd0E4JZulM0TtOj2bc22OQtAu309D1We700N9Q7byxoBWHuu67Af0vWK7jqRFeXZIyPsyqxtwYNfzcmf3faSsxvyImUIaNEYdlC+3M2Mka2KlsCoiqwkjL7NRBzcGJwDz1xLKyzHqWvZfO68bAHcEUC5GDAmLEkpGoMIifw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR15MB5154.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(38100700002)(2906002)(36756003)(38070700005)(86362001)(316002)(122000001)(5660300002)(66946007)(8936002)(6506007)(66556008)(76116006)(8676002)(64756008)(66446008)(83380400001)(66476007)(6486002)(71200400001)(186003)(26005)(6512007)(110136005)(2616005)(508600001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?9Z5UK9LIeRRmAUM2eaeXRUo?= =?iso-8859-1?q?j95FifswRgHoFYJsPA7sM5V1rUkS75L9p9YepMPVXQ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?q?EONv6lBzqruW6/sU7Fe1nyavDriE6B7T/xHIPK4BQgV22/JaBBE6GbQVss6q?= =?iso-8859-1?q?0CloPve1zB+fPDQGhMRF0IE6JpOC94YH2ZjKJXs3uHQatgscMIKLSb+G6A+n?= =?iso-8859-1?q?6ggYV9rIzsE18IGu+QfJHiMzf6g2M25wrRJwnAzznwsH3MA/X7w211gIlDXb?= =?iso-8859-1?q?dpRwvzMW1PJkxZqTwQhlR7p3P9pJzG3pVRSzJFT1G70ufIQcOhNB1I76YmXS?= =?iso-8859-1?q?r0SUH1nVLLOmEX1a/9kMctU19/AbHX0S/oEKWPLU+j2iW1JdImidCKsJ4eUx?= =?iso-8859-1?q?C3N5JMk126Dt6UCB9Yull2hVoBMqobGZE02UAW6fnOIsh0lIikPmJZQhEQtF?= =?iso-8859-1?q?uf5Gbe8fAKjhvYO5l1dC1RL6tlp0EE5IIs1HhPuCC70c6BMdccePoSC62u1r?= =?iso-8859-1?q?3rb/Ltdqp2p8R6EJCwPQIXZ2HwyeCdkTxTHvQlSnFKXbbt0AqBLnwHpOTQ2U?= =?iso-8859-1?q?FpLgO6grtPBDGea8m2+YJymaNkahxOJymmzgpHu8wrLRr7a+ZaRA5SO49zD2?= =?iso-8859-1?q?OdPSLHvT8YRqsWqsIX6C/pGoCdEDGPzp6ueWcmHr1butvlT9UlQ9rDhD248K?= =?iso-8859-1?q?P1tntWd/KbQl5/tSrGqV92hBiyCP1x971avC/f9IS03rynA4utYZgnK6wsyy?= =?iso-8859-1?q?7Ev3SOkb/H9lGGUG5xG4lWLOmsR5/g7RbUlnvkUWgIQ+GB3gnr2pq2D4ulEf?= =?iso-8859-1?q?QeUF2Kw/RpHf7LoXZUGanTunN+4WXqLeTp1mdWBt40JZv3XZviSOxhhgYz+U?= =?iso-8859-1?q?IMyFRAvV3358Ho06L6LfcrfbafDkzF9MVpVTigdB7j/v0AA=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR15MB5154.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c8b085e-f00f-4fa3-f3b2-08da2937aefb X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Apr 2022 16:53:56.1877 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 93ZxCm+eizIec9Yi9pkyJQT2ikUhszDjj3wxnyX/ysYQyRAAC8DwnKPtPNFiTmsf X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR15MB4615 X-Proofpoint-GUID: W_rs2MFWjGnhyq63fY0mHSI5ZqiBSycP X-Proofpoint-ORIG-GUID: W_rs2MFWjGnhyq63fY0mHSI5ZqiBSycP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-28_02,2022-04-28_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add tests that ensure sleepable kprobe programs cannot attach. Also attach both sleepable and non-sleepable uprobe programs to the same location (i.e. same bpf_prog_array). Signed-off-by: Delyan Kratunov --- .../selftests/bpf/prog_tests/attach_probe.c | 35 +++++++++++++++ .../selftests/bpf/progs/test_attach_probe.c | 44 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c index c0c6d410751d..c5c601537eea 100644 --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c @@ -17,6 +17,12 @@ static void trigger_func2(void) asm volatile (""); } +/* attach point for byname sleepable uprobe */ +static void trigger_func3(void) +{ + asm volatile (""); +} + void test_attach_probe(void) { DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts); @@ -143,6 +149,28 @@ void test_attach_probe(void) if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname2, "attach_uretprobe_byname2")) goto cleanup; + /* sleepable kprobes should not attach successfully */ + skel->links.handle_kprobe_sleepable = bpf_program__attach(skel->progs.handle_kprobe_sleepable); + if (!ASSERT_NULL(skel->links.handle_kprobe_sleepable, "attach_kprobe_sleepable")) + goto cleanup; + + /* test sleepable uprobe and uretprobe variants */ + skel->links.handle_uprobe_byname3_sleepable = bpf_program__attach(skel->progs.handle_uprobe_byname3_sleepable); + if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname3_sleepable, "attach_uprobe_byname3_sleepable")) + goto cleanup; + + skel->links.handle_uprobe_byname3 = bpf_program__attach(skel->progs.handle_uprobe_byname3); + if (!ASSERT_OK_PTR(skel->links.handle_uprobe_byname3, "attach_uprobe_byname3")) + goto cleanup; + + skel->links.handle_uretprobe_byname3_sleepable = bpf_program__attach(skel->progs.handle_uretprobe_byname3_sleepable); + if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname3_sleepable, "attach_uretprobe_byname3_sleepable")) + goto cleanup; + + skel->links.handle_uretprobe_byname3 = bpf_program__attach(skel->progs.handle_uretprobe_byname3); + if (!ASSERT_OK_PTR(skel->links.handle_uretprobe_byname3, "attach_uretprobe_byname3")) + goto cleanup; + /* trigger & validate kprobe && kretprobe */ usleep(1); @@ -156,6 +184,9 @@ void test_attach_probe(void) /* trigger & validate uprobe attached by name */ trigger_func2(); + /* trigger & validate sleepable uprobe attached by name */ + trigger_func3(); + ASSERT_EQ(skel->bss->kprobe_res, 1, "check_kprobe_res"); ASSERT_EQ(skel->bss->kretprobe_res, 2, "check_kretprobe_res"); ASSERT_EQ(skel->bss->uprobe_res, 3, "check_uprobe_res"); @@ -164,6 +195,10 @@ void test_attach_probe(void) ASSERT_EQ(skel->bss->uretprobe_byname_res, 6, "check_uretprobe_byname_res"); ASSERT_EQ(skel->bss->uprobe_byname2_res, 7, "check_uprobe_byname2_res"); ASSERT_EQ(skel->bss->uretprobe_byname2_res, 8, "check_uretprobe_byname2_res"); + ASSERT_EQ(skel->bss->uprobe_byname3_sleepable_res, 9, "check_uprobe_byname3_sleepable_res"); + ASSERT_EQ(skel->bss->uprobe_byname3_res, 10, "check_uprobe_byname3_res"); + ASSERT_EQ(skel->bss->uretprobe_byname3_sleepable_res, 11, "check_uretprobe_byname3_sleepable_res"); + ASSERT_EQ(skel->bss->uretprobe_byname3_res, 12, "check_uretprobe_byname3_res"); cleanup: test_attach_probe__destroy(skel); diff --git a/tools/testing/selftests/bpf/progs/test_attach_probe.c b/tools/testing/selftests/bpf/progs/test_attach_probe.c index af994d16bb10..265a23af74d4 100644 --- a/tools/testing/selftests/bpf/progs/test_attach_probe.c +++ b/tools/testing/selftests/bpf/progs/test_attach_probe.c @@ -14,6 +14,10 @@ int uprobe_byname_res = 0; int uretprobe_byname_res = 0; int uprobe_byname2_res = 0; int uretprobe_byname2_res = 0; +int uprobe_byname3_sleepable_res = 0; +int uprobe_byname3_res = 0; +int uretprobe_byname3_sleepable_res = 0; +int uretprobe_byname3_res = 0; SEC("kprobe/sys_nanosleep") int handle_kprobe(struct pt_regs *ctx) @@ -22,6 +26,13 @@ int handle_kprobe(struct pt_regs *ctx) return 0; } +SEC("kprobe.s/sys_nanosleep") +int handle_kprobe_sleepable(struct pt_regs *ctx) +{ + kprobe_res = 2; + return 0; +} + SEC("kretprobe/sys_nanosleep") int BPF_KRETPROBE(handle_kretprobe) { @@ -76,4 +87,37 @@ int handle_uretprobe_byname2(struct pt_regs *ctx) return 0; } +SEC("uprobe.s//proc/self/exe:trigger_func3") +int handle_uprobe_byname3_sleepable(struct pt_regs *ctx) +{ + uprobe_byname3_sleepable_res = 9; + return 0; +} + +/** + * same target as the uprobe.s above to force sleepable and non-sleepable + * programs in the same bpf_prog_array + */ +SEC("uprobe//proc/self/exe:trigger_func3") +int handle_uprobe_byname3(struct pt_regs *ctx) +{ + uprobe_byname3_res = 10; + return 0; +} + +SEC("uretprobe.s//proc/self/exe:trigger_func3") +int handle_uretprobe_byname3_sleepable(struct pt_regs *ctx) +{ + uretprobe_byname3_sleepable_res = 11; + return 0; +} + +SEC("uretprobe//proc/self/exe:trigger_func3") +int handle_uretprobe_byname3(struct pt_regs *ctx) +{ + uretprobe_byname3_res = 12; + return 0; +} + + char _license[] SEC("license") = "GPL";