On 11/17/26 15:29, netdev-bot+sashiko@kernel.org wrote:
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] nf_flow_offload_validate()
(net/netfilter/nf_flow_table_offload.c:931-939) checks the neighbour…
- [Low] nf_flow_offload_validate()
(net/netfilter/nf_flow_table_offload.c:929 and 934) is documented as…
--
net: flow_offload: allow drivers to validate and invalidate cached paths
This adds optional invalidate and validate callbacks to struct
flow_cls_offload. Offload drivers can use them to ask the flowtable owner
whether a cached path is still valid, and to tear the owning flow down.
Netfilter now keeps direct-path dst references for hardware flowtables and
implements both callbacks, checking dst cookies and direct Ethernet
neighbours in each direction.
quoted
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 4365859220e6a..1f3adf70f5987 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -885,6 +885,62 @@ static int nf_flow_offload_alloc(const struct flow_offload_work *offload,
[ ... ]
quoted
+static int nf_flow_offload_validate(unsigned long cookie)
+{
+ struct flow_offload *flow = nf_flow_offload_cookie_flow(cookie);
+ unsigned int dir;
+
+ for (dir = 0; dir < FLOW_OFFLOAD_DIR_MAX; dir++) {
+ struct flow_offload_tuple *tuple = &flow->tuplehash[dir].tuple;
+ struct flow_offload_tuple *other = &flow->tuplehash[!dir].tuple;
+ struct dst_entry *dst = tuple->dst_cache;
+ struct neighbour *neigh;
+ u8 mac[ETH_ALEN];
+ bool valid;
+
+ if (!dst)
+ return -EOPNOTSUPP;
[ ... ]
quoted
+ if (dst->dev->ifindex != tuple->out.ifidx)
+ return -EOPNOTSUPP;
+ neigh = dst_neigh_lookup(dst, &other->src_v4);
+ if (!neigh)
+ return -ESTALE;
[Severity: Medium]
Can this lookup change the neighbour table? For IPv4, dst_neigh_lookup()
goes through ipv4_dst_neigh_lookup()->ip_neigh_gw4(), which creates an
entry when the noref lookup misses:
include/net/route.h:ip_neigh_gw4() {
...
neigh = __ipv4_neigh_lookup_noref(dev, (__force u32)daddr);
if (unlikely(!neigh)) {
struct neigh_table *tbl = arp_table(dev_net(dev));
neigh = __neigh_create(tbl, &daddr, dev, false);
}
...
}
So validation can allocate a neighbour with GFP_ATOMIC, run forced GC
under tbl->lock, and insert a new NUD_NONE entry into the ARP table.
It also looks like two cases that are not provably stale end up returning
-ESTALE. The header documents the contract as:
Return 0 for a valid path, -ESTALE for a demonstrably stale path,
or -EOPNOTSUPP when validation is unavailable.
The first case is neighbour creation failing (-ENOBUFS at gc_thresh3, or
-ENOMEM). dst_neigh_lookup() turns the ERR_PTR into NULL, and the
!neigh branch above returns -ESTALE.
The second case is an entry that was garbage collected while the flow kept
forwarding. The software DIRECT path uses the cached out.h_dest and never
confirms the neighbour, so the entry can age out. Periodic GC can remove it
above gc_thresh1, and forced GC can remove it above gc_thresh2. The next
validate then creates a NUD_NONE entry, fails the NUD_VALID test below, and
returns -ESTALE, even though the next hop and MAC have not changed.
The consumer, fa_replace() in drivers/net/ethernet/broadcom/bcm-ns-fa.c
(added later in this series by "net: bgmac: add Northstar IPv4 TCP/UDP NAT
flowtable offload"), calls cls->invalidate() on -ESTALE. That runs
flow_offload_teardown() on a healthy flow.
A flow that the driver declined keeps being offered through
flow_offload_refresh(), roughly once per HZ. Under neighbour table pressure
this could keep tearing such flows down.
That driver's own fa_route_check() uses the lookup-only ipv4_neigh_lookup()
and returns -EOPNOTSUPP on a miss. Would a noref lookup under RCU, such as
__ipv4_neigh_lookup_noref() or __ipv6_neigh_lookup_noref(), returning
-EOPNOTSUPP on a miss, fit the documented contract better?
quoted
+ neigh_ha_snapshot(mac, neigh, dst->dev);
[Severity: Low]
Should these dst->dev accesses use dst_dev_rcu()? This callback runs under
RCU while dst_dev_put() can concurrently republish the device:
net/core/dst.c:dst_dev_put() {
...
rcu_assign_pointer(dst->dev_rcu, blackhole_netdev);
...
}
The ifindex check and neigh_ha_snapshot() each do a plain load of
dst->dev, and ipv4_dst_neigh_lookup() does a third load through
dst_dev_rcu(). KCSAN will report the plain loads, and the three loads can
see different net_devices within one validation pass.
There's no memory safety problem here. blackhole_netdev has addr_len set
to ETH_ALEN, so mac[] is fully written, and -ESTALE is the right answer for
a route that has moved to blackhole.
Would taking a single dev = dst_dev_rcu(dst) snapshot, or passing
neigh->dev to neigh_ha_snapshot(), avoid the race?
quoted
+ valid = (READ_ONCE(neigh->nud_state) & NUD_VALID) &&
+ ether_addr_equal(mac, tuple->out.h_dest);
+ neigh_release(neigh);
+ if (!valid)
+ return -ESTALE;
+ }
+ return 0;
+}
[ ... ]
[Medium] validation creating neighbours / reporting -ESTALE
Agreed. dst_neigh_lookup() can create an entry (and run forced GC), and turns a creation failure or a garbage collected entry into -ESTALE, which makes the owner tear down a healthy flow. v2 looks up the next hop with __ipv4_neigh_lookup_noref() under RCU, never creating an entry, and returns -EOPNOTSUPP when there is none, since the path is then not proven stale.
It also returns -EOPNOTSUPP for non-IPv4 tuples, as the next hop address used is an IPv4 one.
[Low] dst->dev accesses
Agreed. v2 takes a single dst_dev_rcu() snapshot under rcu_read_lock() and uses it for the ifindex check, the neighbour lookup and neigh_ha_snapshot().
pw-bot: cr
--
Florian