From patchwork Wed May 28 21:49:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blaise Boscaccy X-Patchwork-Id: 893015 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DED69221D86; Wed, 28 May 2025 21:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748469056; cv=none; b=U1mKw6kuRyYejRvm9hK5GxLqcjmquxiPc05QYqPSRndBHGeiB0HD14kz8Y1a/URmBl1nTauD57czRCY1jHzwbiz4QycTb9SAlbQmeVQiACxYh4YO0CT5w7f3dDQU1ntvlt5mhf9cEtmpttuHDIVzyznj2kAOD/5mF9RGEnAgE8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748469056; c=relaxed/simple; bh=Blo3ndz5JePi6aqSuyj+SYt3qoNJbS8rn9mKh/VSH3I=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pYYSoZzE7PbJHPcRW4DtVw5zV8+PmJwHSKjHZantm/n04bgbh/qv0lj6XU+5Eq03L19Afr+KWHziBsZrRy5uEggh6RjkD4vcvAZPMJsOej6wTBupp6UhYUe0a65nBonvpCy8IIuPNH/cwgZ/xijNZcQoKaSTa1Q92ZwGI+h7qfs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=ZgoSpT6e; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="ZgoSpT6e" Received: from narnia.corp.microsoft.com (unknown [40.78.13.173]) by linux.microsoft.com (Postfix) with ESMTPSA id 175DF207860D; Wed, 28 May 2025 14:50:51 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 175DF207860D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1748469054; bh=WkTKL+7T37zKr2IHdBcaL/FQsk6lpPmT3/Y3bsH0FvA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZgoSpT6ezmYwryw3jFVrT9nlWoP7ZDY5vesrO4gzq5cr7I9j3QDLSm01gNUIvNlk3 FzwkH8Q/GOfCzUd5qzM9VOPBXz8uKMGtz2clO3/H/7g/b3eTLAp/OYdAQJxtEh8Jp0 Xk7GXyWQtjk1gIIEvTCfjeCtRd1hkRQT2B+kTtQM= From: Blaise Boscaccy To: Paul Moore , bboscaccy@linux.microsoft.com, jarkko@kernel.org, zeffron@riotgames.com, xiyou.wangcong@gmail.com, kysrinivasan@gmail.com, code@tyhicks.com, linux-security-module@vger.kernel.org, roberto.sassu@huawei.com, James.Bottomley@hansenpartnership.com, Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , David Howells , Lukas Wunner , Ignat Korchagin , Quentin Monnet , Jason Xing , Willem de Bruijn , Anton Protopopov , Jordan Rome , Martin Kelly , Alan Maguire , Matteo Croce , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org Subject: [PATCH 2/3] bpf: Support light-skeleton signatures in autogenerated code Date: Wed, 28 May 2025 14:49:04 -0700 Message-ID: <20250528215037.2081066-3-bboscaccy@linux.microsoft.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250528215037.2081066-1-bboscaccy@linux.microsoft.com> References: <20250528215037.2081066-1-bboscaccy@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This adds optional signature UAPI support to lskels. Additionally map freezing support is added as well. Signed-off-by: Blaise Boscaccy --- tools/lib/bpf/skel_internal.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h index 4d5fa079b5d6..106103b1edc7 100644 --- a/tools/lib/bpf/skel_internal.h +++ b/tools/lib/bpf/skel_internal.h @@ -61,8 +61,12 @@ struct bpf_load_and_run_opts { struct bpf_loader_ctx *ctx; const void *data; const void *insns; + const void *signature; + const void *signature_maps; __u32 data_sz; __u32 insns_sz; + __u32 signature_sz; + __u32 signature_maps_sz; const char *errstr; }; @@ -263,6 +267,17 @@ static inline int skel_map_delete_elem(int fd, const void *key) return skel_sys_bpf(BPF_MAP_DELETE_ELEM, &attr, attr_sz); } +static inline int skel_map_freeze(int fd) +{ + const size_t attr_sz = offsetofend(union bpf_attr, map_fd); + union bpf_attr attr; + + memset(&attr, 0, attr_sz); + attr.map_fd = fd; + + return skel_sys_bpf(BPF_MAP_FREEZE, &attr, attr_sz); +} + static inline int skel_map_get_fd_by_id(__u32 id) { const size_t attr_sz = offsetofend(union bpf_attr, flags); @@ -308,7 +323,7 @@ static inline int skel_link_create(int prog_fd, int target_fd, static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts) { - const size_t prog_load_attr_sz = offsetofend(union bpf_attr, fd_array); + const size_t prog_load_attr_sz = offsetofend(union bpf_attr, signature_maps_size); const size_t test_run_attr_sz = offsetofend(union bpf_attr, test); int map_fd = -1, prog_fd = -1, key = 0, err; union bpf_attr attr; @@ -327,6 +342,13 @@ static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts) goto out; } + err = skel_map_freeze(map_fd); + if (err < 0) { + opts->errstr = "failed to freeze map"; + set_err; + goto out; + } + memset(&attr, 0, prog_load_attr_sz); attr.prog_type = BPF_PROG_TYPE_SYSCALL; attr.insns = (long) opts->insns; @@ -338,6 +360,10 @@ static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts) attr.log_size = opts->ctx->log_size; attr.log_buf = opts->ctx->log_buf; attr.prog_flags = BPF_F_SLEEPABLE; + attr.signature = (long) opts->signature; + attr.signature_size = opts->signature_sz; + attr.signature_maps = (long) opts->signature_maps; + attr.signature_maps_size = opts->signature_maps_sz; err = prog_fd = skel_sys_bpf(BPF_PROG_LOAD, &attr, prog_load_attr_sz); if (prog_fd < 0) { opts->errstr = "failed to load loader prog";