[PATCH OLK-5.10] net/sched: act_ct: fix ref leak when switching zones

From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> mainline inclusion from mainline-v5.18-rc1 commit bcb74e132a76ce0502bb33d5b65533a4ed72d159 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBP2JY CVE: CVE-2022-49183 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- When switching zones or network namespaces without doing a ct clear in between, it is now leaking a reference to the old ct entry. That's because tcf_ct_skb_nfct_cached() returns false and tcf_ct_flow_table_lookup() may simply overwrite it. The fix is to, as the ct entry is not reusable, free it already at tcf_ct_skb_nfct_cached(). Reported-by: Florian Westphal <fw@strlen.de> Fixes: 2f131de361f6 ("net/sched: act_ct: Fix flow table lookup after ct clear or switching zones") Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Conflicts: net/sched/act_ct.c [conflicts due to not mergered 408bdcfce8df ("net: prefer nf_ct_put instead of nf_conntrack_put")] Signed-off-by: Wang Liang <wangliang74@huawei.com> --- net/sched/act_ct.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c index 52ba1b278c54..6524efee71e2 100644 --- a/net/sched/act_ct.c +++ b/net/sched/act_ct.c @@ -580,22 +580,25 @@ static bool tcf_ct_skb_nfct_cached(struct net *net, struct sk_buff *skb, if (!ct) return false; if (!net_eq(net, read_pnet(&ct->ct_net))) - return false; + goto drop_ct; if (nf_ct_zone(ct)->id != zone_id) - return false; + goto drop_ct; /* Force conntrack entry direction. */ if (force && CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL) { if (nf_ct_is_confirmed(ct)) nf_ct_kill(ct); - nf_conntrack_put(&ct->ct_general); - nf_ct_set(skb, NULL, IP_CT_UNTRACKED); - - return false; + goto drop_ct; } return true; + +drop_ct: + nf_conntrack_put(&ct->ct_general); + nf_ct_set(skb, NULL, IP_CT_UNTRACKED); + + return false; } /* Trim the skb to the length specified by the IP/IPv6 header, -- 2.34.1

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/17383 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/MBY... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/17383 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/MBY...
participants (2)
-
patchwork bot
-
Wang Liang