From patchwork Sat Dec 28 18:00:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Enache X-Patchwork-Id: 13922484 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-106101.protonmail.ch (mail-106101.protonmail.ch [79.135.106.101]) (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 6271D2111 for ; Sat, 28 Dec 2024 18:00:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735408862; cv=none; b=mhluJGswS4U7x1FKq3uZKzYjs3KTqEybGuO0o8nLhE0NyviwE3vF4QjpENYpZaCnzHmhHn2MtMXQ7/BjuVlegCiY+HwK5zzz7Q4F+tbKn1UpPS5PabURN7lUauTjKI65MivSPw9Ep2iu8F7qC9H9UJtWEEXnvf7LeMD4e77ohM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735408862; c=relaxed/simple; bh=xZZlX136M1U1/RIpLsfe8GB76Wp9kOWatRvJuMtWhMI=; h=Date:To:From:Subject:Message-ID:MIME-Version:Content-Type; b=Aa+3nFQ9CO06/iOOg3RUj8xTN7qNTq917PTQZ22k4g5oiJqcLOqM5F9lHMpTAGiYVFkrp5sYmDb1iztVHSUQeITKSyFoYN2OkFEfvHb5p7K0ZzxQyGDHmDIYVHTgCD8nIu4t8boEjFne4MqowowurG6Q/FU1wHPKcD91L6KjzM0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=RVWtGLyS; arc=none smtp.client-ip=79.135.106.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="RVWtGLyS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1735408855; x=1735668055; bh=/wTsBFqgSQdInXSya0vTG0Kxn3CJmdb/QApsN1g/pxI=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=RVWtGLyS4dHN7n+k447HyExCNI/aB7qgw6jukwVtTRvyY3md+BrsEoNe9E6oov+b0 jSHwop5ws24u+U73tnP+R/79uEMCXhngn1h0mIxpXgasgyzzbc4W9OAfXZ+jOcy0Tj seXrdBegY/o6ydRXh0Z4xT0pjOCUhz8S1zTAriEMWii0vBkTMLZta59CFGwGVN+83u ANIOYpqC8EfyBt10qDoN91DHvGBXX9PK8oxKnbXU5pHRVxUsnww2qX/FFH6ZCep0RU 6UWr5RxbiePmoHLH97Igl3FSuttf7jRIhD8JLMP4Y0cUGJMubJDFDuOAS1+faqIofc FTa/wzviO103w== Date: Sat, 28 Dec 2024 18:00:48 +0000 To: "bpf@vger.kernel.org" From: Andrei Enache Subject: [PATCH v2 bpf-next] bpf: Use non-executable memfds for maps Message-ID: Feedback-ID: 46877017:user:proton X-Pm-Message-ID: 23de1dfb87eb4c543a3adb93ef4e44af2869afe2 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net This patch enables use of non-executable memfds for bpf maps. [1] As this is a recent kernel feature, the code checks errno to make sure it is available. --- Changes in v2: - Rebase on dad704e - Link to v1: https://lore.kernel.org/bpf/6qGQ7n8-hGVRUbVaU4K2NOdK93nEC-Ytb1ZCWhJyHoeIJgs0plTiTHLLQ8ghWSxjdhsu7VRiTD8SSqEW0eJyssE0FGOp4fn3wNG7TS-jsq8=@proton.me/ [1] https://lwn.net/Articles/918106/ [2] Signed-off-by: Andrei Enache --- tools/lib/bpf/libbpf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) return -errno; return fd; diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 66173ddb5..490b41e2d 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1732,11 +1732,22 @@ static int sys_memfd_create(const char *name, unsigned flags) #define MFD_CLOEXEC 0x0001U #endif +#ifndef MFD_NOEXEC_SEAL +#define MFD_NOEXEC_SEAL 0x0008U +#endif + static int create_placeholder_fd(void) { int fd; + int memfd; + + memfd = sys_memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC | MFD_NOEXEC_SEAL); + + /* MFD_NOEXEC_SEAL is missing from older kernels */ + if (errno == EINVAL) + memfd = sys_memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC); - fd = ensure_good_fd(sys_memfd_create("libbpf-placeholder-fd", MFD_CLOEXEC)); + fd = ensure_good_fd(memfd); if (fd < 0)