From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99E67370AD2 for ; Sun, 12 Jul 2026 04:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783829338; cv=none; b=jRHR1YuEB6Vbu1ELYRi9Dbb3Rik+zzcFizmhsWeoLLMoluZv/EOIW3tS/Oza6vOLnBGmHOvaoRkb9Z0++gH4iNks0crbRGO94F+3VAN5GOAtfSdWQIJFQkAYrau5hA2DMMMqMzpjbuOGZZk1UlLJjE7GTg9S8NaSdsy7Gpk0ub4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783829338; c=relaxed/simple; bh=tLYfqud9Alqsuxe2P8hqfcpiiFUye1isw4lqTTAq7GM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D/TwQnB5SaOT172lsiEOFlj/R0ohBR5x8JIpLLgXWNbDMVw3GXqFDrjF9HlWhU0iOQhbCTJbgtGeoDlOkINKRIYCuCj+GxTSvID1RTglwxiyoV/ULFHy3GFJbg8OT5kdhmgcf5IYFZwzmN46fEcv2b/oCeeg9nGZPdXnfkZY7dg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YTkMz0G2; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YTkMz0G2" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-381b831d535so2591318a91.0 for ; Sat, 11 Jul 2026 21:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783829336; x=1784434136; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QOcBwZZCQda0ksnOyTTPJoQylHUy+3FzULiJTSWI84w=; b=YTkMz0G2lYG3k+HO6Zfj+E3IkAtsfUbdK9IHOYMjpSdmm4TnpG+7vES9umMhfv8NCJ N3C6+LbQqBfvD+FfZDlhRSb8h+7DkD5bHI6tbEqtTdKJlCfAYMtdVR1gzVW8LU/NOnWB JKddzULTjjGuMMrXyflrBLLez5v/ddd35O/RURSsx/a3/aySno6DUV0mvDI4gh3UR0J5 Re0Do7cxZ/6U5vnv2/qk0PymakVQth/plYR90RlXb0Yp4spekAZ2Yw+AQiKIDhPXqxUQ 8b5Ilpa54+ugO9bR350EPNf+KodfVSDcytrkRnrWD0Xo7hVvR8tAvm7ZRdGnElLFFZyC 7Fqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783829336; x=1784434136; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QOcBwZZCQda0ksnOyTTPJoQylHUy+3FzULiJTSWI84w=; b=bU9tmEPfv9CNjfeFMmJVeNjcwpJICLmqTEX4UptyBULC3lSBh1O+Iuc0aNSG48+Rz/ 13kph40pkcB9BiTfx7DRIGfA6NepD2/0Zh/48YnocX5FsNk3pPYT12EMaA3/ogwhQGQg Z3GkWflmIPo+uMJtGQ3jqDLy8E9Tqntd1xGvCCRcsIx11XbVeakaKCWECKqyt2LWARek REvK57l/qLUt/Zm8RX38FZxytvgitBASbRRaY/ipG1JVKmDxXDev93gfns3skzVvT6Ny /dnNYw4MN9YNyVKo1esTjZsQMSRTKvuUGZNZ7fItWvOQFcUg1v0rSUAxVi/JTG5a+LWR Fm4Q== X-Forwarded-Encrypted: i=1; AHgh+RqWIqSUs7lSHzbVmbGApCB12uPMtDfdGbL/3u9ziCtT2HqdrBSjqdhytktB9mSYAkp4Z6QoWGvgkqE=@vger.kernel.org X-Gm-Message-State: AOJu0YxsSh1bJ6NyBrfDXTXpP2B+/+PIvPBQ6Fgtcj2Uu+jeqyz/vdTG josKq8KlvF73jb3+SbKCsrfkh31ob+rsSzhVmjN/bE0bsTvGP0sAFAaY X-Gm-Gg: AfdE7cl79KEBIA776i/Ta/5/07FWSViT/AU4QI6JaDCmhHcBNYgUbtz+J5EQoYO3336 +CQlZMhH8phYAAJG2jOf1MXx637dErGgq5rsnP5l0Eb1NNgds18g+zSn9asZnKSvtSEaAjeihl3 N1kUPUB34fWIsZMgXy+1ZDRjZpeojtLOatEl1v81HhpC5Xu9UKrjXAYh4mQTfWhwmlvD0ovAF3s hgxSpB079T9q9mug+2ho4D4Vb56SXZ4JB0Skn7ZhALAKpx111HAOmG+eE3PeO1BJAHkC1LhGBOC xDi29dCopL5zWx8gaukIWmVeIPwVkujN1u+CheEBcV2Js8xOsQ+WMOyhO0A9jEZqKA2CzRGiFob t++n1hoULa8qIxXsuwukXtzbIo3qjgCM+KBFg+dsvKw1BuymU/Heb2a3KwNltlqMuBZbIeC/ByT 9ebhGwEFETEWxyltUb X-Received: by 2002:a17:90b:39ad:b0:381:abcc:c8e9 with SMTP id 98e67ed59e1d1-38dc73bcfecmr4632607a91.7.1783829335997; Sat, 11 Jul 2026 21:08:55 -0700 (PDT) Received: from [127.0.0.2] ([98.35.8.117]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31174839f89sm56808928eec.10.2026.07.11.21.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2026 21:08:55 -0700 (PDT) From: Farid Zakaria Date: Sat, 11 Jul 2026 21:08:17 -0700 Subject: [PATCH v2 4/5] bpf: allow fs kfuncs for binfmt_misc_ops programs Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260711-binfmt-misc-bpf-v2-v2-4-d6591ceaf207@gmail.com> References: <20260711-binfmt-misc-bpf-v2-v2-0-d6591ceaf207@gmail.com> In-Reply-To: <20260711-binfmt-misc-bpf-v2-v2-0-d6591ceaf207@gmail.com> To: Christian Brauner , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Shuah Khan Cc: Andrii Nakryiko , Kees Cook , Alexander Viro , Jan Kara , Jonathan Corbet , Jann Horn , John Ericson , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Farid Zakaria X-Mailer: b4 0.14.3 From: Christian Brauner The fs kfuncs are currently exclusive to LSM programs. A binfmt_misc load program needs a subset of them to do anything interesting: to compute an interpreter relative to the binary's location it wants bpf_path_d_path() on bprm->file->f_path, and matching on per-binary metadata wants bpf_get_file_xattr() and friends. Register the fs kfunc set for struct_ops programs as well and extend the filter to admit binfmt_misc_ops programs. The xattr setters stay exclusive to LSM programs: a binary type handler decides how to run a binary, it has no business modifying filesystem state. This only takes effect in builds that have the fs kfunc set at all, i.e. CONFIG_BPF_LSM. Without it a binfmt_misc handler is limited to bprm fields and the file-backed dynptr, which are provided by the common kfunc set. Link: https://lore.kernel.org/20260704211409.1978485-1-farid.m.zakaria@gmail.com Signed-off-by: Christian Brauner (Amutable) --- fs/bpf_fs_kfuncs.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c index 768aca2dc..aa1fe988b 100644 --- a/fs/bpf_fs_kfuncs.c +++ b/fs/bpf_fs_kfuncs.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2024 Google LLC. */ +#include #include #include #include @@ -387,10 +388,20 @@ BTF_ID_FLAGS(func, bpf_remove_dentry_xattr, KF_SLEEPABLE) BTF_ID_FLAGS(func, bpf_real_inode, KF_SLEEPABLE | KF_RET_NULL) BTF_KFUNCS_END(bpf_fs_kfunc_set_ids) +/* Side-effecting kfuncs that stay exclusive to LSM programs. */ +BTF_SET_START(bpf_fs_kfunc_lsm_only_ids) +BTF_ID(func, bpf_set_dentry_xattr) +BTF_ID(func, bpf_remove_dentry_xattr) +BTF_SET_END(bpf_fs_kfunc_lsm_only_ids) + static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id) { - if (!btf_id_set8_contains(&bpf_fs_kfunc_set_ids, kfunc_id) || - prog->type == BPF_PROG_TYPE_LSM) + if (!btf_id_set8_contains(&bpf_fs_kfunc_set_ids, kfunc_id)) + return 0; + if (prog->type == BPF_PROG_TYPE_LSM) + return 0; + if (bpf_prog_is_binfmt_misc_ops(prog) && + !btf_id_set_contains(&bpf_fs_kfunc_lsm_only_ids, kfunc_id)) return 0; return -EACCES; } @@ -433,7 +444,13 @@ static const struct btf_kfunc_id_set bpf_fs_kfunc_set = { static int __init bpf_fs_kfuncs_init(void) { - return register_btf_kfunc_id_set(BPF_PROG_TYPE_LSM, &bpf_fs_kfunc_set); + int ret; + + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_LSM, &bpf_fs_kfunc_set); + if (ret || !IS_ENABLED(CONFIG_BINFMT_MISC_BPF)) + return ret; + return register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, + &bpf_fs_kfunc_set); } late_initcall(bpf_fs_kfuncs_init); -- 2.51.2