From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx2-f28.google.com (mail-yx2-f28.google.com [74.125.224.156]) (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 9D3AA2D6E58 for ; Tue, 6 Oct 2026 00:20:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.156 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791246061; cv=none; b=e24El7rKdmrs8txMFss3kbJDF2Uh9JFk2XkOATDeRhKGgwKTdhmvp2Z/bq0nRJWvKkFDo9/Zzs4P364I8YfxmdCGbQ6bJfBu41zeaqaFpXQDUNWBmWij+rjJ9pPit2oT7MTtEHx8GRiF4PI2qhYzlgaPuW0pLQF0KCdk06sExVc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791246061; c=relaxed/simple; bh=wMJGYrbUj4os94fJj06zWmFNGCmeZceTo1G4NZWQtDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L73yKQ2nt+NTkZ2nnhsvGa5codERsrpcauBGJ84pdiEhT05Bv11PK9zJKRQj9DVJWfdzh3jRKIUTF+p0rIBQvgRVvJufoNNRCrBaNB2jq1xsJzQDRAWkGXoLjawAf3wyEYkQsyZEl9c1m80zsr4J6xoHilrVzBjAJigLCSp+iKU= 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=SqV89hbz; arc=none smtp.client-ip=74.125.224.156 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="SqV89hbz" Received: by mail-yx2-f28.google.com with SMTP id 00721157ae682-8ab41af29caso18194367b3.3 for ; Mon, 05 Oct 2026 17:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791246058; x=1791850858; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=O0mktHpoo7c1ELqyZ2fb0sw3f8VVRQGSWUHz0tOcBE0=; b=SqV89hbzavHhGIssD2p5AQHPnfCwLN0yMUWNtydRwTqMcmkjHWN82v8rGu7rsnlww+ ceStMO1zrxDwScDe6AyowqiXy3JePIoIdxZw+1u4psoPN7zBztjnbbt7Z82ix8/R7r28 Pgxa/Wt4iaegw9bU9FJGg0QjjpqRRMq99cWwS1oAK/xueB1PVav7R7AyjbiSpmlmGgdy ddgE+MThcmfq2Qocvmdtxpf3szPhbgLQvkslKE9cIlzGHOcvBQQ2WzBh+GJbWitZsOJN O5Y3wAjta90PEJHAbDHSzdYX0t65gZEH9spyGFkawCLfEIr3cxGTzIDkMWckeWJ9EKo7 oxJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791246058; x=1791850858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=O0mktHpoo7c1ELqyZ2fb0sw3f8VVRQGSWUHz0tOcBE0=; b=PDaPvIu0OCBEzIf8tGxNY9phY5VtCDzb1wgtTViCCaKqJxR4VvqzTiHDkztlaG62OG lghHOcZ9thCmhRoYITwkG7+jtvytO30xJtJFwsG704LeSoNMxpRpj27EVqid96ruAA4J 3P/PlNUUhuHJh25LXxxSQaqmP/Sn3HWCRsNtdEGNq6q87YDrNXexoSnuFi19eYc946PL 3a/qhG1kqUl3QB6YGK0Jqu1fHOXdlibe/LDcM5t6q3h9KZaJm6goci5E63XdFaJdPVHR CYgBR/n21m7OrW1JCy5zs4AfNrJe0LzmSBq1mrnB78uG5LiO1KkZKv4Vk0ZwwXblkvah C66w== X-Forwarded-Encrypted: i=1; AKwUvByEVb2B7aJPV/i8+/sR4Pjz/ABNi3uvRkyAa1EKKDIyYI34+jQqNpvMnT9oGu8gj5HBc/g=@vger.kernel.org X-Gm-Message-State: AFq9FYIh2dOcRlSzZMGRK0spjYXY6JJe6ke7wGcz5rilsej6U8PcdxZ0 /NzYpyAzAJVqR6Kp52YSpro3QEHZO2YPjY0D0JCvdhDvXrghsJmxjGUB X-Gm-Gg: AYBFou2u7IxWmsKu4QpdHYZna4ED2yOC4oIxfKWoG/4VWZejaDE03NIILSqUGbavbiD eAcMojPCNX6OCX03tDxmkC7tBCFgT4cRYSDcz2IlslU9YPYeprAwpK5VDsy3gtdvJj4GaaYP/Iz oyDG1PfaZ8h84DS5CNJtfZzdtuMpebcZ+O/xO6tHgRHZFJVvirPXwAkZZCVVbEj34hKpt/3p2My BbayBOngsKkNk9hox+5bKxP/wWhHJPaVViXktjRxJA6SlFi01k0NRIdIfjJs5x253wfqKkpC+/f 4XnG+7SVqxR0sv/jFNFRO2aDvmdL6OcUp6bIo2ZvWWUObA0P5+CEJylJ0ZWIm0zXFbvi5ksYZb7 mRbvB0izOo7D8s2cqV0pLAbu1gWi7zOHZjOOSAbPTkcoHql6XQju8ulUCtXPfhjpLbQufg4IyQu 6M5TgiTxRfmjadXaIyWpVOV2hjtS0s7e5rBFDwNN9VZ75jyp2lguz1CaDY3LGAZzPGN1VkaLONr ZXZzX7i151J X-Received: by 2002:a05:690e:d0c:b0:677:c87c:d2f with SMTP id 956f58d0204a3-677c87c122dmr2826146d50.15.1791246058500; Mon, 05 Oct 2026 17:20:58 -0700 (PDT) Received: from zenbox ([2600:1700:18fb:6011:6dc9:4ffd:1851:60b1]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8ae33be0e58sm46636277b3.43.2026.10.05.17.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2026 17:20:56 -0700 (PDT) From: Justin Suess To: Christian Brauner , Alexander Viro , Jan Kara , NeilBrown , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu Cc: linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?G=C3=BCnther=20Noack?= , Paul Moore , James Morris , "Serge E . Hallyn" , Martin KaFai Lau , Eduard Zingerman , Yonghong Song , John Fastabend , Kumar Kartikeya Dwivedi , Jiri Olsa , Jeff Layton , Amir Goldstein , Mateusz Guzik , Shuah Khan , Tingmao Wang , Justin Suess Subject: [RFC PATCH bpf-next 10/12] bpf: support "__uninit" iterator arguments in generic kfuncs Date: Mon, 5 Oct 2026 20:20:17 -0400 Message-ID: <20261006002020.2890858-11-utilityemal77@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261006002020.2890858-1-utilityemal77@gmail.com> References: <20261006002020.2890858-1-utilityemal77@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Iterator constructors are recognised by their KF_ITER_NEW flag, which binds them to the bpf_iter__new() name and so to a single constructor per type. A kfunc that initializes an iterator from inputs that naming convention cannot express - e.g. another, already initialized iterator - therefore cannot be a constructor. Let such a kfunc mark its destination argument with the "__uninit" suffix already used for dynptr out-arguments: process_iter_arg() now decides per argument, rather than per kfunc, whether it initializes the iterator or operates on an initialized one. Only iterator-typed arguments are reclassified, so dynptr "__uninit" out-arguments are unaffected. The first user is the path ancestor iterator handover added by the next patch. Signed-off-by: Justin Suess --- kernel/bpf/verifier.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 066c4b838b85..3294b2a43167 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -8312,6 +8312,24 @@ static bool is_iter_destroy_kfunc(struct bpf_call_arg_meta *meta) return meta->kfunc_flags & KF_ITER_DESTROY; } +/* + * An "__uninit"-suffixed iterator argument of a kfunc that is not itself an + * iterator method: the kfunc initializes that iterator state, as a + * bpf_iter__new() does, but from inputs the constructor naming + * convention cannot express - e.g. another, already-initialized iterator. + * Only iterator-typed arguments qualify, so "__uninit" dynptr out-arguments + * are not reclassified. + */ +static bool is_kfunc_arg_iter_init(struct bpf_call_arg_meta *meta, int arg_idx, + const struct btf_param *arg) +{ + if (is_iter_kfunc(meta)) + return false; + + return btf_param_match_suffix(meta->btf, arg, "__uninit") && + btf_check_iter_arg(meta->btf, meta->func_proto, arg_idx) >= 0; +} + static bool is_kfunc_arg_iter(struct bpf_call_arg_meta *meta, int arg_idx, const struct btf_param *arg) { @@ -8322,7 +8340,11 @@ static bool is_kfunc_arg_iter(struct bpf_call_arg_meta *meta, int arg_idx, return arg_idx == 0; /* iter passed as an argument to a generic kfunc */ - return btf_param_match_suffix(meta->btf, arg, "__iter"); + if (btf_param_match_suffix(meta->btf, arg, "__iter")) + return true; + + /* iter state a generic kfunc initializes */ + return is_kfunc_arg_iter_init(meta, arg_idx, arg); } static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state *reg, @@ -8332,6 +8354,7 @@ static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state * struct bpf_func_state *state = bpf_func(env, reg); const struct btf_type *t; int spi, err, i, nr_slots, btf_id; + bool init; if (reg->type != PTR_TO_STACK) { verbose(env, "%s expected pointer to an iterator on stack\n", @@ -8363,8 +8386,16 @@ static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state * t = btf_type_by_id(meta->btf, btf_id); nr_slots = t->size / BPF_REG_SIZE; - if (is_iter_new_kfunc(meta)) { - /* bpf_iter__new() expects pointer to uninit iter state */ + /* + * Whether this argument is the iterator the call initializes, rather + * than an initialized one it operates on. + */ + init = is_iter_new_kfunc(meta) || + is_kfunc_arg_iter_init(meta, arg, + &btf_params(meta->func_proto)[arg]); + + if (init) { + /* expects a pointer to uninit iter state */ if (!is_iter_reg_valid_uninit(env, reg, nr_slots)) { verbose(env, "expected uninitialized iter_%s as %s\n", iter_type_str(meta->btf, btf_id), reg_arg_name(env, argno)); -- 2.55.0