ovs_ct_copy_action() keeps the timeout policy of the action's conntrack template only so that skb_nfct_cached() can compare it with the policy of a later connection; the pointer is never dereferenced through this copy. It is read with rcu_dereference() outside an RCU read-side critical section, so adding a ct action with a timeout policy makes lockdep complain: WARNING: suspicious RCU usage net/openvswitch/conntrack.c:1435 suspicious rcu_dereference_check() usage! Call Trace: ovs_ct_copy_action (net/openvswitch/conntrack.c:1435) __ovs_nla_copy_actions (net/openvswitch/flow_netlink.c:3478) ovs_nla_copy_actions (net/openvswitch/flow_netlink.c:3617) ovs_flow_cmd_new (net/openvswitch/datapath.c:1058) genl_family_rcv_msg_doit (net/netlink/genetlink.c:1114) Use rcu_access_pointer() both when storing the identity and when comparing it, and document that the stored pointer must not be dereferenced. Fixes: 7177895154e6 ("openvswitch: Fix conntrack cache with timeout") Signed-off-by: Kyuwon Cho <kyuw…@skku.edu> --- Changes in v2: - Target net-next, as requested by Ilya Maximets. - Use rcu_access_pointer() for the comparison in skb_nfct_cached() too. - Document that nf_ct_timeout is an identity token that must not be dereferenced. v1: https://lore.kernel.org/all/1796…@skku.edu/ review reply: https://lore.kernel.org/all/1796…@skku.edu/ The issue was found by an LLM-guided test generator that we are developing as a research prototype. It reproduces with CONFIG_PROVE_RCU as any user in its own user and network namespace: a conntrack timeout policy created through nfnetlink_cttimeout, an OVS datapath, and a flow whose ct action names that policy. With the patch lockdep stays quiet. A reproducer is available on request. Found and tested on mainline fe6ff8d5d675 (v7.4-rc5, with KASAN); this version is against net-next. net/openvswitch/conntrack.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c index d3326edcabf7..1d7584b44229 100644 --- a/net/openvswitch/conntrack.c +++ b/net/openvswitch/conntrack.c @@ -71,6 +71,7 @@ struct ovs_conntrack_info { struct md_mark mark; struct md_labels labels; char timeout[CTNL_TIMEOUT_NAME_MAX]; + /* Identity token only; do not dereference. */ struct nf_ct_timeout *nf_ct_timeout; #if IS_ENABLED(CONFIG_NF_NAT) struct nf_nat_range2 range; /* Only present for SRC NAT and DST NAT. */ @@ -592,7 +593,7 @@ static bool skb_nfct_cached(struct net *net, timeout_ext = nf_ct_timeout_find(ct); if (!timeout_ext || info->nf_ct_timeout != - rcu_dereference(timeout_ext->timeout)) + rcu_access_pointer(timeout_ext->timeout)) return false; } /* Force conntrack entry direction to the current packet? */ @@ -1432,8 +1433,8 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr, "Failed to associated timeout policy '%s'", ct_info.timeout); else - ct_info.nf_ct_timeout = rcu_dereference( - nf_ct_timeout_find(ct_info.ct)->timeout); + ct_info.nf_ct_timeout = + rcu_access_pointer(nf_ct_timeout_find(ct_info.ct)->timeout); }
-- 2.43.0