From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 C856A3ADBAD; Wed, 3 Jun 2026 11:07:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780484869; cv=none; b=RjPI7MQa+EOzx0vpT1d+Io6bi+qrk2NuleUjpgoc3ZdEg/X/aztC/iryvC0H4uZWT9E5hMYt7bpu06IiKs247B+goEKzawEcLeonCaUPwF4zgLWK6qxDf5lq/mZLSo2qqJN5zkOS6eLbTNiA5JL7Gyc7gNqD6sIhdbCkx39QD5w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780484869; c=relaxed/simple; bh=jW86Ime2ZE3LR5xw00SrH073v6DNBx3AB0H/Neh4g4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QWEfZ9z5DhO33bLNUt2sraAkFUweN+V68AduVZNII4VsMzkO6c3oiZp0ivjw5F3RITjEW5pWaCatWRXwsmClQ5J0JdaNYYX6+3srriq/PFHBpBy74XFuRt2VMVp5etofGcu/xdeOO3qPo6z5wHuVzj6qcJ7QTg3qI47ljXyq8ms= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a4BYmlKW; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="a4BYmlKW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4BA91F00893; Wed, 3 Jun 2026 11:07:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780484868; bh=uYCIQXxtgxBJrRX6byeACCmqsa9+njxzWz27aLSzh2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=a4BYmlKWePOpDOGPaWvNZrHc3H2QLrTwQ1iRSYUslrVH6z4LYDT31phvfBRWw8AOF 6canQxrTvYB8wt8Taqi9iWS0OWWcGDwp01zT4LVb69uUaA0ECtyxjhfO+fOd6dQij3 IbInVU7A8Dc8BE5dDddbqG/2wf34U6sdZ0YpwKDR5U+2Ik+5Ut4c4dLnP5ehV5yyyO U+O+bQx6+oc/beDFkXD581FWKaON1yFilsgtAWG5rghrFs8vypGCw2AvGmbvdAtozA PTJMYua1i3Nbxc9OmDRJsguqC9SNTzCgOEY6R8KXewUfy5OqZ7NR1RHndoYJyX3cyA rkAOVNDIQBfvw== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , Menglong Dong , Steven Rostedt Subject: [PATCHv7 bpf-next 11/29] bpf: Move sleepable verification code to btf_id_allow_sleepable Date: Wed, 3 Jun 2026 13:05:35 +0200 Message-ID: <20260603110554.29590-12-jolsa@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260603110554.29590-1-jolsa@kernel.org> References: <20260603110554.29590-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move sleepable verification code to btf_id_allow_sleepable function. It will be used in following changes. Adding code to retrieve type's name instead of passing it from bpf_check_attach_target function, because this function will be called from another place in following changes and it's easier to retrieve the name directly in here. Signed-off-by: Jiri Olsa --- kernel/bpf/verifier.c | 82 ++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 521ec2a9051e..9aae972b3b51 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -18706,6 +18706,55 @@ static bool is_tracing_multi_id(const struct bpf_prog *prog, u32 btf_id) return is_tracing_multi(prog->expected_attach_type) && bpf_multi_func_btf_id[0] == btf_id; } +static int btf_id_allow_sleepable(u32 btf_id, unsigned long addr, const struct bpf_prog *prog, + const struct btf *btf) +{ + const struct btf_type *t; + const char *tname; + + switch (prog->type) { + case BPF_PROG_TYPE_TRACING: + t = btf_type_by_id(btf, btf_id); + if (!t) + return -EINVAL; + tname = btf_name_by_offset(btf, t->name_off); + if (!tname) + return -EINVAL; + + /* + * *.multi sleepable programs will pass initial sleepable check, + * the actual attached btf ids are checked later during the link + * attachment. + */ + if (is_tracing_multi_id(prog, btf_id)) + return 0; + if (!check_attach_sleepable(btf_id, addr, tname)) + return 0; + /* + * fentry/fexit/fmod_ret progs can also be sleepable if they are + * in the fmodret id set with the KF_SLEEPABLE flag. + */ + else { + u32 *flags = btf_kfunc_is_modify_return(btf, btf_id, prog); + + if (flags && (*flags & KF_SLEEPABLE)) + return 0; + } + break; + case BPF_PROG_TYPE_LSM: + /* + * LSM progs check that they are attached to bpf_lsm_*() funcs. + * Only some of them are sleepable. + */ + if (bpf_lsm_is_sleepable_hook(btf_id)) + return 0; + break; + default: + break; + } + return -EINVAL; +} + int bpf_check_attach_target(struct bpf_verifier_log *log, const struct bpf_prog *prog, const struct bpf_prog *tgt_prog, @@ -19003,38 +19052,7 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, } if (prog->sleepable) { - ret = -EINVAL; - switch (prog->type) { - case BPF_PROG_TYPE_TRACING: - /* *.multi sleepable programs will pass initial sleepable check, - * the actual attached btf ids are checked later during the link - * attachment. - */ - if (is_tracing_multi_id(prog, btf_id)) - ret = 0; - if (!check_attach_sleepable(btf_id, addr, tname)) - ret = 0; - /* fentry/fexit/fmod_ret progs can also be sleepable if they are - * in the fmodret id set with the KF_SLEEPABLE flag. - */ - else { - u32 *flags = btf_kfunc_is_modify_return(btf, btf_id, - prog); - - if (flags && (*flags & KF_SLEEPABLE)) - ret = 0; - } - break; - case BPF_PROG_TYPE_LSM: - /* LSM progs check that they are attached to bpf_lsm_*() funcs. - * Only some of them are sleepable. - */ - if (bpf_lsm_is_sleepable_hook(btf_id)) - ret = 0; - break; - default: - break; - } + ret = btf_id_allow_sleepable(btf_id, addr, prog, btf); if (ret) { module_put(mod); bpf_log(log, "%s is not sleepable\n", tname); -- 2.54.0