From patchwork Thu Apr 28 16:53:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12831053 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 31291C433F5 for ; Thu, 28 Apr 2022 16:54:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234725AbiD1Q5R (ORCPT ); Thu, 28 Apr 2022 12:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232001AbiD1Q5Q (ORCPT ); Thu, 28 Apr 2022 12:57:16 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 591FBAAB6D for ; Thu, 28 Apr 2022 09:54:01 -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 23SG7bkZ026710 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=U4NO8m8IDGi7so3m0I9LGYCHZWY79T35kWhM4cnGlpQ=; b=NPi79+D9OW/32bu6AksGmaK3LQW3FPnru6dBxXYiTDgPjRUCaiiLtqiH59Z5XONXmjvg nK516PjOIcsSMTWhh9QRzrUbXP0smqZlHSDFVB9SPyfTkEAWndvFfwgv8aqhdumn/ZJN unymSKvvCyEHbaqGwIgfZF+7998M7pU00Rs= 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-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Apr 2022 09:54:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lYRk2sXdrwy/Lmt+4q8qxLtaM+3WHY1gVMnVPuVHBMBLxhu7jmdQLSB1X1ZJNWSxMUopt5pSseL4RGKizBqrA+sNu9BEHUlsZwp7VJG8p9dDVe0ktV9tYsWqaybntR/u362iCD9uz8xfNktfvolvGfJhGUjLPBYb6wo83qYN+dAHvoXNlEFiO7WNkhzUvO78GiBXwJ++stElYpnEoSsk3ijhD7ChtB1gOMocBei0fh3z4T0msIxRqU9zDuFy+/ZNk3oLIX6UrBR3P3Jx2dSBxN4zbCcG3IZDE00knJEqj09EGytbsBLp6IVpqTd2SH3vzreew835Qx7TkrDgD2LVLg== 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=U4NO8m8IDGi7so3m0I9LGYCHZWY79T35kWhM4cnGlpQ=; b=NZ3HKE6v/wjE0WGiLzXiWuo3jn+odzyojHzL+e2Rxvj5AVG4i7Tj1PtyUfSB8iwg9JbrvJB15Wedd8zJFrNkoGhTW8kg0Sx8CYbMxdrE70sMeTq3dX1bbMVlRHTk9RV+b/6d5VENpAqFwZH7EN3vAK+2FtW0NwgSuq668271paU50jS1InlppSYMeQfbQZNL+avgN8v16dQuuCLTTvEtFkkMtqjk2p2dZGFnx1YGjnXRyhQy/J/jojSHysj+z6dD7d4EbrGkruwrvam3M/vHO2kFABnwBXScBYNuqyeQ0zMqgaEi3lno+mDekenTB1o8viSnG8HVrl6c68tf/NCI2A== 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:55 +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:55 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next 4/5] libbpf: add support for sleepable kprobe and uprobe programs Thread-Topic: [PATCH bpf-next 4/5] libbpf: add support for sleepable kprobe and uprobe programs Thread-Index: AQHYWyCLmUWuy8bCeUK1TVSeHWTI+g== Date: Thu, 28 Apr 2022 16:53:54 +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: 8c8a0781-aad4-42ff-a8ae-08da2937ae59 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: mWwHhUYIwnoPfy9V57Vd2RDdaoFlYy8l9q3nU/NmfPgVa/MqwQYwUZq7kzQkUCbKYiflwnFyyh96LLMVacNCvzMX+dxT7F3x1oYrDhmM4DcUqyiVs18vdcb5wZc9Kj1Lt7bZJJy2erZNb2vl9HPLQa/fWgDHzMlxHx7eliZM5/GwvJq+KMs4r1OFJKE3mO/oMWO60Qf8ExfNd5dWL6Ormx9wZxXD1BstPHeXyLE3wJ5zXYG3BYlj/cUeay4iliLROmZ516w39mUzcdjnWxgK/kBced5BJLiLKzNxPnrqGAaTDGke1HQkw1BAnAtQKSahAmJab19Ro1tw5cKoHjTZ1kl5tdCRBFCiJk6cdh+fH/ISynRIh67MiaL6FT1R0kyQjZdKCrrgwgBZ8ltDP5S/T0DVjg6s9Ibzc6js+6su7i84p33TNxNrIcQ+OZHrEAsjeYCz7cxhyd4S4Z+rXtTtNcmjgVwyS951HCZbG63MfT0396Y9Dgo4STyQXRLMxleJGvHRvyVshFPrHHgn6pumm6XjGDJLr7G3FKnUsQE2DCqJU+De/f6yAZISghAZEM/6IEWcJ1wlPEShU1vxMNx9vzlAFe2+zj5ZryYG3aJD62Er9SPe8yLGO+O/TawNTWbRRlFJMhu6TnNchou1C58mlwK0SVJpzMyJNiD4kR0oXO+nuXGa7T6uGuUHMaMsVi6JL/6Y3TLmDCTPUcELpBOLSw== 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?/XHmBy8ghjlJEqnPAzMh++4?= =?iso-8859-1?q?8afUnWDmey6gMy/u59XjofwwiQkOdtO4q04mSayM0tiE+6vy+pir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z1nUlMjhw02Ss6/TqvsbyDcutuq7w1vtPL1oY0aDLh3onLw8UeTY1tDpZKUl?= =?iso-8859-1?q?IMCfZkcRet1yWmbK1vr/aW451qNTbq7kkNFk3oSN7g+6TL1zEg5P+dGpq1cR?= =?iso-8859-1?q?BF7yo4NdtQa+BL8sro/FwfgVCpo/7NADSGPKyjBjX4fRAsLTyXFTfVYOy5kp?= =?iso-8859-1?q?28ijlqeDrjKl/5FzGrO4Pk2YTvLoe1b9jjdXzPST2UXyubyBhD1PpSrA63jk?= =?iso-8859-1?q?pPlvapE1BxBxgPTvVod00lpFf8Us73TUOIH2GJU7pSmcYGqdPpkGUfUQPcVs?= =?iso-8859-1?q?R/C4f1h5jl3TdVsvWFcw92CxFBl6eEyJ78DsUgCRKfp0+L8pxf77YzWgfTEV?= =?iso-8859-1?q?SKBWJBuiEjXlA+CFSMD9+ltD4NQ5ixoBCyyDg6LTNKxVcc3UL1PPTV5FjkHD?= =?iso-8859-1?q?OVY9t5lE6VBqjbV9Sjf4HbBhqGrIa/AOTrIFG00qyoGR9+6crXcW1i5fKlaR?= =?iso-8859-1?q?e1tLAzzvIOykjequbZ8a+WWnbtde9Gwrgfz4UAb+Z1zmhu+r/1tZj6uc7gis?= =?iso-8859-1?q?IBV/9jReXuSskB8W2MehwGEkAdLekmud6/Eysk5xKsl+KEYODY1dqlgU62Ye?= =?iso-8859-1?q?stfVtCnkdfWPyFmwXlRqRnyfv+tgvO1YiPkZS6INgf3y3WPEEOIQr5lkx14h?= =?iso-8859-1?q?kL/9G6efSDoe1inaqakHUMnk5iXQgKw1aEju4LuDZp0DatNq48IrzYJnr3Gr?= =?iso-8859-1?q?mYTBWwT6FsTdjZ+BSfq05iYU1VNmceRBtUL3FWFoE8c4C2qJLNFr2PIZExA/?= =?iso-8859-1?q?dvYPAc/mCyNhvS9/ALKN8PI2rmpYUgQM2a0nRfNljeKPalw=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: 8c8a0781-aad4-42ff-a8ae-08da2937ae59 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Apr 2022 16:53:55.1085 (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: Sr7UQMZRdq7D2ynlD96UjSWcjyGhQPH5ZyQJxXigl0/deJpfryQ3txQmcxPeif9m X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR15MB4615 X-Proofpoint-GUID: L4cXZK5rmAoaocwxY_tgn1XKEnmhgiQi X-Proofpoint-ORIG-GUID: L4cXZK5rmAoaocwxY_tgn1XKEnmhgiQi 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 section mappings for uprobe.s and kprobe.s programs. The latter cannot currently attach but they're still useful to open and load in order to validate that prohibition. Signed-off-by: Delyan Kratunov --- tools/lib/bpf/libbpf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 9a213aaaac8a..9e89a478d40e 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -8692,9 +8692,12 @@ static const struct bpf_sec_def section_defs[] = { SEC_DEF("sk_reuseport/migrate", SK_REUSEPORT, BPF_SK_REUSEPORT_SELECT_OR_MIGRATE, SEC_ATTACHABLE | SEC_SLOPPY_PFX), SEC_DEF("sk_reuseport", SK_REUSEPORT, BPF_SK_REUSEPORT_SELECT, SEC_ATTACHABLE | SEC_SLOPPY_PFX), SEC_DEF("kprobe/", KPROBE, 0, SEC_NONE, attach_kprobe), + SEC_DEF("kprobe.s/", KPROBE, 0, SEC_SLEEPABLE, attach_kprobe), SEC_DEF("uprobe+", KPROBE, 0, SEC_NONE, attach_uprobe), + SEC_DEF("uprobe.s+", KPROBE, 0, SEC_SLEEPABLE, attach_uprobe), SEC_DEF("kretprobe/", KPROBE, 0, SEC_NONE, attach_kprobe), SEC_DEF("uretprobe+", KPROBE, 0, SEC_NONE, attach_uprobe), + SEC_DEF("uretprobe.s+", KPROBE, 0, SEC_SLEEPABLE, attach_uprobe), SEC_DEF("kprobe.multi/", KPROBE, BPF_TRACE_KPROBE_MULTI, SEC_NONE, attach_kprobe_multi), SEC_DEF("kretprobe.multi/", KPROBE, BPF_TRACE_KPROBE_MULTI, SEC_NONE, attach_kprobe_multi), SEC_DEF("usdt+", KPROBE, 0, SEC_NONE, attach_usdt), @@ -10432,13 +10435,18 @@ static int attach_kprobe(const struct bpf_program *prog, long cookie, struct bpf const char *func_name; char *func; int n; + bool sleepable = false; opts.retprobe = str_has_pfx(prog->sec_name, "kretprobe/"); + sleepable = str_has_pfx(prog->sec_name, "kprobe.s/"); if (opts.retprobe) func_name = prog->sec_name + sizeof("kretprobe/") - 1; + else if (sleepable) + func_name = prog->sec_name + sizeof("kprobe.s/") - 1; else func_name = prog->sec_name + sizeof("kprobe/") - 1; + n = sscanf(func_name, "%m[a-zA-Z0-9_.]+%li", &func, &offset); if (n < 1) { pr_warn("kprobe name is invalid: %s\n", func_name); @@ -10957,7 +10965,7 @@ static int attach_uprobe(const struct bpf_program *prog, long cookie, struct bpf break; case 3: case 4: - opts.retprobe = strcmp(probe_type, "uretprobe") == 0; + opts.retprobe = str_has_pfx(probe_type, "uretprobe"); if (opts.retprobe && offset != 0) { pr_warn("prog '%s': uretprobes do not support offset specification\n", prog->name);