From patchwork Sat Feb 5 01:33:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 12735917 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 EEAC6C433F5 for ; Sat, 5 Feb 2022 01:33:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355169AbiBEBdu convert rfc822-to-8bit (ORCPT ); Fri, 4 Feb 2022 20:33:50 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:60250 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349644AbiBEBdu (ORCPT ); Fri, 4 Feb 2022 20:33:50 -0500 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 2150pRRK018547 for ; Fri, 4 Feb 2022 17:33:50 -0800 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3e0puag8xy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 04 Feb 2022 17:33:49 -0800 Received: from twshared18912.14.frc2.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:21d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Feb 2022 17:33:49 -0800 Received: by devbig019.vll3.facebook.com (Postfix, from userid 137359) id 0FBC41051E238; Fri, 4 Feb 2022 17:33:45 -0800 (PST) From: Andrii Nakryiko To: , , CC: , , Alan Maguire Subject: [PATCH v2 bpf-next 0/3] libbpf: support custom SEC() handlers Date: Fri, 4 Feb 2022 17:33:39 -0800 Message-ID: <20220205013342.1110746-1-andrii@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: erL_A8LeU000ifRvi2Ovg0vxyVhbpiSq X-Proofpoint-GUID: erL_A8LeU000ifRvi2Ovg0vxyVhbpiSq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-04_07,2022-02-03_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 priorityscore=1501 bulkscore=0 clxscore=1015 adultscore=0 suspectscore=0 mlxlogscore=967 lowpriorityscore=0 malwarescore=0 spamscore=0 impostorscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202050005 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Add ability for user applications and libraries to register custom BPF program SEC() handlers. See patch #2 for examples where this is useful. Patch #1 does some preliminary refactoring to allow exponsing program init, preload, and attach callbacks as public API. It also establishes a protocol to allow optional auto-attach behavior. This will also help the case of sometimes auto-attachable uprobes. Cc: Alan Maguire Andrii Nakryiko (3): libbpf: allow BPF program auto-attach handlers to bail out libbpf: support custom SEC() handlers selftests/bpf: add custom SEC() handling selftest tools/lib/bpf/libbpf.c | 299 ++++++++++++------ tools/lib/bpf/libbpf.h | 81 +++++ tools/lib/bpf/libbpf.map | 2 + .../bpf/prog_tests/custom_sec_handlers.c | 136 ++++++++ .../bpf/progs/test_custom_sec_handlers.c | 51 +++ 5 files changed, 480 insertions(+), 89 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/custom_sec_handlers.c create mode 100644 tools/testing/selftests/bpf/progs/test_custom_sec_handlers.c