From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796174298; b=DKmAyXv03vdoCDYdOvWXxw8pqZ++1E+88yF2TffsQjfCQRBuNhGHefEUns+Dda1rUmft kyAvEcGq6BC1cOksJb2J2baMMErVF1QLEVdqlCKl7dzto0lSzoVC1N0SdnQZfbeB3ekTS Rk9y4Q1Vy+u2TIpukBkVXJeTKhn5FRIFupWGrc7uZ88r3gqxZonALs30kfBkRv/XRguGz ZKX3coS/KCpDwa5mGHd5p0wTmUSiZPJDdNmgRh6lBFPM5TMSBBfCAETqdJk7IBf48jM4V d72xQb2A+Jwz1PylOx4aQAWkXqxZxQiw4/w++AsSQqn1WZE+lSiF6pRlJciHs7yDuxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796174298; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bQm3LnnlkYPTDOEC/VY3LNFt12E7KT5MxyJB7bHsw/s=; b=1rkrV9C2FXyBgzEhiBEQKtYs+j+7sHVCW4iOeEIgd5U/Z4NImAmWY7091PKAycr+yrf9 tFdvohV6Mrq3FcmZQ9N1X9CTuYYxc2EK1cDbrKS6DnUZ121DlqNA+u2AMT2Z8wIy9OzK2 fccU+12LiNXeM1OPtMwjMCE6thZHpAUg0QswqAr1na/E7uG3YH2UQIElAWH3+LCrJ9VrJ LtRXSQV85xAt6WE7h9j0dqL0EM5BNWAvhBd0LXxjxkxBNuea48C4fKHVQr1g4qSSq6D0C XhzlQSWt9mW7+ZF/5gBoV7KVzaFjnC5fHc5hVmGT8x09ajXTEFVshR3trlCqdK9lzQA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PCQVlvs5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2A21606A32E for ; Wed, 2 Dec 2026 01:18:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PCQVlvs5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 105EA1F008A0; Wed, 2 Dec 2026 01:18:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796174298; bh=bQm3LnnlkYPTDOEC/VY3LNFt12E7KT5MxyJB7bHsw/s=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=PCQVlvs5flwKjhvJjcVQBcBbAeNwrx1HfTyPWZG9E/28kcc976iX13Pb9lSJgahqm ObuSKm1V369BxnIEBbjqVB7LSTk5opu18N9g4Ube1MjGQ1jakRfSqcCaAcJJb+yz2a HGWm5WPr5I1+oMCMggo6wFP4xwpvrzkTIJ7oWoz5S+egbz5HDVaas46jfBGcMPOLX9 HgYqGtxPmQD0ouH9JJFAnlEQMSUgZLio89YtHWv+4h0oGNOw9WrqzICd28XPhK6ptt g8g9AHPmQS3IY0OCciqM16R5iJJycuZpT5YyBsc72auLwaOMIeNzduHe8aR1xWFoz/ ch1rGuAIDrMMQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next 2/6] bpf: Check many main programs in one set of insns Reply-To: sashiko-reviews@lists.linux.dev To: "Alexei Starovoitov" , bpf@vger.kernel.org In-Reply-To: <20261202001639.2301557-3-alexei.starovoitov@gmail.com> References: <20261202001639.2301557-1-alexei.starovoitov@gmail.com> <20261202001639.2301557-3-alexei.starovoitov@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 01:18:17 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] bpf: missing sleepable_async_cb propagation in mark_sleepable_async_cb() -- commit e81391289aecdf18a4497171d32e314bcc48b1a9 Author: Alexei Starovoitov bpf: Check many main programs in one set of insns This commit extends the BPF verifier to verify multiple main program entry points within a single instruction buffer so that they can share common subprograms. > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index 15a73e3991f9f..58b30c1c2b0b1 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c [ ... ] > @@ -23902,11 +24052,27 @@ static int do_check_all(struct bpf_verifier_env= *env) [ ... ] > +/* Each main prog has passes of its own. They start from what the progs = before it wrote. */ > +static int do_check_mains(struct bpf_verifier_env *env) > +{ > + u64 max_cost =3D env->max_cost, max_mem =3D env->max_mem; > + int err =3D 0; > + > + for (; env->pass_main < env->main_cnt && !err; env->pass_main++) { > + env->max_cost =3D max_cost; > + env->max_mem =3D max_mem; > + bpf_flow_new_main(env); > + err =3D do_check_all(env); > + } > + err =3D err ?: bpf_flow_drop_guards(env); > if (!err && env->sleepable_async_cb) > mark_sleepable_async_cb(env); > - bpf_precision_free(env); > - kvfree(initial); > - kvfree(good_pass); > return err; > } [ ... ] > @@ -25057,6 +25232,138 @@ static int check_attach_btf_id(struct bpf_verif= ier_env *env) > return 0; > } > =20 > +static bool can_share_subprogs(struct bpf_verifier_env *env, const struc= t bpf_main_prog *main) > +{ > + const struct bpf_prog *prog =3D env->prog, *entry =3D main->prog; > + > + if (entry->type !=3D prog->type) > + return false; > + if (entry->type =3D=3D BPF_PROG_TYPE_STRUCT_OPS) > + return entry->aux->st_ops =3D=3D prog->aux->st_ops; > + return entry->expected_attach_type =3D=3D prog->expected_attach_type && > + entry->sleepable =3D=3D prog->sleepable; > +} [ ... ] > +/* An entry is a prog of one function. The code belongs to @prog. */ > +static int finish_entry(struct bpf_verifier_env *env, int s) > +{ > + struct bpf_subprog_info *sub =3D &env->subprog_info[s]; > + struct bpf_prog *prog =3D env->prog, *entry, *func =3D prog->aux->func[= s]; > + struct bpf_prog_aux *aux, *from =3D prog->aux; > + u32 i, start =3D func->aux->subprog_start; [ ... ] > + memcpy(aux_fields(aux, max_ctx_offset), aux_fields(from, max_ctx_offset= ), > + aux_fields_size(max_ctx_offset, cgroup_storage)); [ ... ] > + for (; aux->used_map_cnt < from->used_map_cnt; aux->used_map_cnt++) { > + if (bpf_prog_runs_sleepable(entry)) > + atomic64_inc(&aux->used_maps[aux->used_map_cnt]->sleepable_refcnt); > + bpf_map_inc(aux->used_maps[aux->used_map_cnt]); > + } > + > + /* Maps of progs were compared with the owner. Nothing here does tail c= alls. */ > + return bpf_prog_lock_ro(entry); > +} [Severity: Medium] Can a non-sleepable struct_ops entry miss sleepable_async_cb and map sleepable_refcnt accounting when the first entry in the load is sleepable? can_share_subprogs() allows struct_ops entries in the same load to mix sleepable and non-sleepable programs. When any entry registers a sleepable async callback, do_check_mains() calls mark_sleepable_async_cb(env) with env->prog->sleepable restored to the first entry's value: kernel/bpf/verifier.c:mark_sleepable_async_cb() { int i; if (bpf_prog_runs_sleepable(env->prog)) return; env->prog->aux->sleepable_async_cb =3D true; for (i =3D 0; i < env->used_map_cnt; i++) atomic64_inc(&env->used_maps[i]->sleepable_refcnt); } If the first entry is sleepable, mark_sleepable_async_cb() returns early without setting env->prog->aux->sleepable_async_cb =3D true. finish_entry() then copies sleepable_async_cb =3D=3D false into every entry, so for a non-sleepable entry in the same load bpf_prog_runs_sleepable(entry) is false: finish_entry() skips incrementing sleepable_refcnt on its used_maps, and freeing that entry uses call_rcu() instead of call_rcu_tasks_trace(). Setting env->prog->aux->sleepable_async_cb =3D true before the early return= in mark_sleepable_async_cb() would allow finish_entry() to propagate it to all entries without double-incrementing sleepable_refcnt on env->prog's maps. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202001639.2301= 557-1-alexei.starovoitov@gmail.com?part=3D2