From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 6E8F4384CDA for ; Tue, 16 Jun 2026 22:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781649289; cv=none; b=aE05avTDrMfFa/d1NEDDE2U6T9NgrM9biYKn/GaLZ5N3oOBHmttpM3TPbD3WR9U4d5OmgMG9MueH5qpIDr4ts+0guoXY4iTfxkxxmvqHl1DKcxEp8g3oAZwNpf9Nikxexj2yE8o+/+MC6jLXRcDtJWmsuya+/40BO9LbZ5E6LgU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781649289; c=relaxed/simple; bh=MREMlX9+LgltRptf+kqR2KqPhCAifCYS3oH3GLnZZxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H/9WvORew+l0mjq8P6VaFq5OHCjsZ4nW9vDxVbl8Jwau6u9VbLt17H8Fcb039ixoh27un6GPOLpkqj3mKxAxdrEor0zBVaSyByS43hla2lViH5ImCXqi+JNN0bLclRfRb7mPm/nys1srJ4UReEW2pftZ6iLmx8giOZv/rLDPE3I= 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=i0GawATe; arc=none smtp.client-ip=209.85.216.53 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="i0GawATe" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-36bdda53d99so1942484a91.0 for ; Tue, 16 Jun 2026 15:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781649288; x=1782254088; 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; bh=ipTVbRJPrzwAu2tBqpowbpcPQxDZEeCQYuQNdgsgv14=; b=i0GawATehAtCjIJ0YgoTI1ZrS8nOQXtGatbWqSQFLsXgEoRhWnO4RHVqUWv3miNwgZ rz4AYj4ZeOyWSy+PGklpZ/shTz/EAz/YKiFAHyS9g31hAjfbEveczIDwnoVtjcj8TMIV 8ocGN6YViRoX/D0kj6fG5SxHi9+Fn5KvnYNz4kgJPCjOqXySJ5y5Ab7a5HkxhljyZYyD 6lc0RBJzQNqYPPog1v3/znpqMtpmW6Xu2Rpb+vAqabEYXOnV2cW4TLWIbH2M/9dqOUCu bXRdalvDHrXRDYR+YOSTSEW2DZ6J7bf18gqEwjzuT8tgoRzsYOCY8h4YBHHLZrQ/53hB LMFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781649288; x=1782254088; 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; bh=ipTVbRJPrzwAu2tBqpowbpcPQxDZEeCQYuQNdgsgv14=; b=h/d/xlI0AJTsH4WMZg1Ag+F7pfMKYa6dLKrAeRJwVicX00AQjvGaZuASPLu6TTiUXg CZp4ztDREidh1XWa2lu5IYBhvOHGBp97a6OXtdFE7jk01263T3qdOCFmhsvCxXmh2ix2 Nmz6thQkzYa8EDT9SvWb6MiZvxw/O7t5WfJ3TyNZMUXJLOYkcj5Z9FT7lwvDofBlXqKr CpNQOt5CkIQsg3YTwgJGBxHAD33TIzyk/GvTsPJAtOnEHk2NcFpa066DIVJV/oO7s8fI sEOwi2A4OWn7CrqedE81OiQtc7qMNGAtUJwcwR+kLuKQt0Mv3wJMUAP2IrMX/zeB9eQ9 7Ebg== X-Forwarded-Encrypted: i=1; AFNElJ9BFxPBGNk6ziPgBDmVNB7dhl9ldTgdV05XGISKKhTV+JuYHsD3jRDP+c6YMQJq6vKzEOJG8GXom640BHI=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3xHC67N9kFzMHf1a3y/6dDbxkm+qNc0CNm+a1WgXPtnufTyAB MHXvPN/rFJ0I/JxA1Lljb4MwlrjfGLvXw+96C37V6Qi4huZYsoIPkv9V X-Gm-Gg: AfdE7clVB2tioy3jF7u0HH4ukNuboQnnZTIrbl3kKnR61x0Gtqv2iYeIrPFKmVqhDPy qfjCZTE8cXuFK20QK3q1T3NA3sSRnYAT5IgqV5ALYzo8tVQyGxypMwKG4lAXokF/Q36B3zDgiNF JjpHjt26YpMpxeXeAD4NW3qz3BMn4eNLuM/5CxF/GTwDWRJVOpiNdj+ShWVXRHjBlnHRnqzDXqX gvYnhgxV0Pr/EryWA5/TH23cOZC3zdHi7u4Vso+g95FauDAWfDx5G7iZNv1hl+3lvkx1lZtZzOa 5jrnC0SVO4Y1qNAnKUVXs8GXCYaSjiZMWAr+sLUvbkRdMUqQ6D+Ybyx6vxq29Z+T0VqiZ1H1lwv NAk1rwFxuMkXr036EsDBVb1xCIBVGK9ohdoGMhWeJ0OWG4bxXz2XMyO3YtlzuAPNPnItJi+JwUV 5tdHq76SOwvCqvgA14O+D22d8Fnu9uPfqpb37dTpLmAcTaSYK+/pHAf72I/qfRg0xNoxE+gTA= X-Received: by 2002:a17:90b:2583:b0:35e:d015:d675 with SMTP id 98e67ed59e1d1-37c9345bc79mr1251791a91.7.1781649287777; Tue, 16 Jun 2026 15:34:47 -0700 (PDT) Received: from r912.tailbb6e1e.ts.net ([182.70.116.80]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-37c52092ee3sm4216898a91.0.2026.06.16.15.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2026 15:34:47 -0700 (PDT) From: Avinash Duduskar To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , John Fastabend , Stanislav Fomichev , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , David Ahern , Shuah Khan , Jesper Dangaard Brouer , Mykyta Yatsenko , Leon Hwang , KP Singh , Anton Protopopov , Amery Hung , Eyal Birger , Rong Tao , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 1/4] bpf: Initialize the l3mdev field for the fib lookup flow Date: Wed, 17 Jun 2026 04:04:23 +0530 Message-ID: <20260616223426.3568080-2-avinash.duduskar@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616223426.3568080-1-avinash.duduskar@gmail.com> References: <20260616223426.3568080-1-avinash.duduskar@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit bpf_ipv4_fib_lookup() and bpf_ipv6_fib_lookup() build the flow key on the stack with a bare "struct flowi4 fl4;" / "struct flowi6 fl6;" and fill it field by field, but never set flowi4_l3mdev / flowi6_l3mdev. On the non-DIRECT path the lookup goes through the fib rules whenever the netns has custom rules, which a VRF installs: bpf_ipv4_fib_lookup() -> fib_lookup() -> __fib_lookup() -> l3mdev_update_flow() reads !fl->flowi_l3mdev -> fib_rules_lookup() -> fib_rule_match() -> l3mdev_fib_rule_match() uses fl->flowi_l3mdev l3mdev_update_flow() resolves the l3mdev master from the ingress device only while the field is still zero: if (fl->flowi_iif > LOOPBACK_IFINDEX && !fl->flowi_l3mdev) { dev = dev_get_by_index_rcu(net, fl->flowi_iif); if (dev) fl->flowi_l3mdev = l3mdev_master_ifindex_rcu(dev); } Left at a nonzero stack value the resolution is skipped, and l3mdev_fib_rule_match() then tests that value as an ifindex, so the VRF master is not resolved and the rule fails to match: an ingress enslaved to a VRF can fail to select its table. The same value is also read just before that, by FIB rules matching on an L3 master device (l3mdev_fib_rule_iif_match()/_oif_match()), so an "ip rule iif/oif " mismatches the same way. The helper already initializes the other flow fields the rules path consumes (flowi4_mark, flowi4_tun_key.tun_id, flowi4_uid and the v6 counterparts); flowi*_l3mdev was added to that set afterwards and this helper was never updated to match. ip_route_input_slow() likewise zeroes the field before its input lookup. Do the same here. CONFIG_INIT_STACK_ALL_ZERO masks this by default, but it depends on compiler support (CC_HAS_AUTO_VAR_INIT_ZERO), so INIT_STACK_NONE builds, including older toolchains that fall back to it, are exposed. Built with INIT_STACK_ALL_PATTERN, a plain bpf_fib_lookup (no VLAN, no DIRECT) over a VRF slave whose destination is routed only in the VRF table returns BPF_FIB_LKUP_RET_NOT_FWDED, and resolves with this patch; reverting these two lines flips it back. The series' VRF selftests pass on the default config either way, so they do not exercise this fix. Fixes: 40867d74c374 ("net: Add l3mdev index to flow struct and avoid oif reset for port devices") Signed-off-by: Avinash Duduskar --- net/core/filter.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/filter.c b/net/core/filter.c index 9590877b0714..6fa172cb1348 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6162,6 +6162,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params, fl4.flowi4_dscp = inet_dsfield_to_dscp(params->tos); fl4.flowi4_scope = RT_SCOPE_UNIVERSE; fl4.flowi4_flags = 0; + fl4.flowi4_l3mdev = 0; fl4.flowi4_proto = params->l4_protocol; fl4.daddr = params->ipv4_dst; @@ -6307,6 +6308,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params, fl6.flowlabel = params->flowinfo; fl6.flowi6_scope = 0; fl6.flowi6_flags = 0; + fl6.flowi6_l3mdev = 0; fl6.mp_hash = 0; fl6.flowi6_proto = params->l4_protocol; base-commit: 140fa23df957b51385aa847986d44ad7f59b0563 -- 2.54.0