Fix for CVE-2022-4269
Subsystems (4)
cover Fix for CVE-2022-4269
The following commits are needed to fix CVE-2022-4269:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fa6d639930ee5cd3f932cc314f3407f07a06582d
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=78dcdffe0418ac8f3f057f26fe71ccf4d8ed851f
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ca22da2fbd693b54dc8e3b7b54ccc9f7e9ba3640
Davide Caratti (2):
net/sched: act_mirred: better wording on protection against excessive
stack growth
act_mirred: use the backlog for nested calls to mirred ingress
wenxu (1):
net/sched: act_mirred: refactor the handle of xmit
include/net/sch_generic.h | 5 -- net/sched/act_mirred.c | 44 +++++++++++------ .../selftests/net/forwarding/tc_actions.sh | 48 ++++++++++++++++++- 3 files changed, 77 insertions(+), 20 deletions(-)
base-commit: f1b32fda06d2cfb8eea9680b0ba7a8b0d5b81eeb
Signature · 1 line
2.40.1
PATCH 1/3 net/sched: act_mirred: refactor the handle of xmit
From: wenxu <[email protected]>
[ Upstream commit fa6d639930ee5cd3f932cc314f3407f07a06582d ]
This one is prepare for the next patch.
--- include/net/sch_generic.h | 5 ----- net/sched/act_mirred.c | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-)
include/net/sch_generic.h +0 -5
@@ -1320,11 +1320,6 @@ void mini_qdisc_pair_init(struct mini_Qdisc_pair *miniqp, struct Qdisc *qdisc,void mini_qdisc_pair_block_init (struct mini_Qdisc_pair *miniqp,struct tcf_block *block); -static inline int skb_tc_reinsert (struct sk_buff *skb,struct tcf_result *res) -{ -return res->ingress ?netif_receive_skb (skb) :dev_queue_xmit (skb); -} -/* Make sure qdisc is no longer in SCHED state. */ static inline void qdisc_synchronize (const struct Qdisc *q) {
net/sched/act_mirred.c +15 -6
@@ -206,6 +206,18 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,return err; } +static int tcf_mirred_forward (bool want_ingress,struct sk_buff *skb) +{ +int err; + +if (!want_ingress) + err =dev_queue_xmit (skb); +else + err =netif_receive_skb (skb); + +return err; +} +static int tcf_mirred_act (struct sk_buff *skb,const struct tc_action *a,struct tcf_result *res) {
@@ -295,18 +307,15 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,/* let's the caller reinsert the packet, if possible */ if (use_reinsert) { res->ingress = want_ingress; -if (skb_tc_reinsert (skb, res)) + err =tcf_mirred_forward (res->ingress, skb); +if (err)tcf_action_inc_overlimit_qstats (&m->common);__this_cpu_dec (mirred_rec_level);return TC_ACT_CONSUMED ; } } -if (!want_ingress) - err =dev_queue_xmit (skb2); -else - err =netif_receive_skb (skb2); - + err =tcf_mirred_forward (want_ingress, skb2);if (err) { out:tcf_action_inc_overlimit_qstats (&m->common);
Signature · 1 line
2.40.1
PATCH 2/3 net/sched: act_mirred: better wording on protection against excessive stack growth
In reply to Dragos-Marian PanaitFrom: Davide Caratti <[email protected]>
[ Upstream commit 78dcdffe0418ac8f3f057f26fe71ccf4d8ed851f ]
with commit e2ca070f89ec ("net: sched: protect against stack overflow in TC act_mirred"), act_mirred protected itself against excessive stack growth using per_cpu counter of nested calls to tcf_mirred_act(), and capping it to MIRRED_RECURSION_LIMIT. However, such protection does not detect recursion/loops in case the packet is enqueued to the backlog (for example, when the mirred target device has RPS or skb timestamping enabled). Change the wording from "recursion" to "nesting" to make it more clear to readers.
Stable-dep-of: ca22da2fbd69 ("act_mirred: use the backlog for nested calls to mirred ingress")
--- net/sched/act_mirred.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
net/sched/act_mirred.c +8 -8
@@ -28,8 +28,8 @@static LIST_HEAD (mirred_list);static DEFINE_SPINLOCK (mirred_list_lock); -#define MIRRED_RECURSION_LIMIT 4 -static DEFINE_PER_CPU(unsigned int, mirred_rec_level); +#define MIRRED_NEST_LIMIT 4 +static DEFINE_PER_CPU(unsigned int, mirred_nest_level);static bool tcf_mirred_is_act_redirect (int action) {
@@ -225,7 +225,7 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,struct sk_buff *skb2 = skb;bool m_mac_header_xmit;struct net_device *dev; -unsigned int rec_level; +unsigned int nest_level;int retval, err =0 ;bool use_reinsert;bool want_ingress;
@@ -236,11 +236,11 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,int mac_len;bool at_nh; - rec_level =__this_cpu_inc_return (mirred_rec_level); -if (unlikely (rec_level >MIRRED_RECURSION_LIMIT )) { + nest_level =__this_cpu_inc_return (mirred_nest_level); +if (unlikely (nest_level >MIRRED_NEST_LIMIT )) {net_warn_ratelimited ("Packet exceeded mirred recursion limit on dev %s\n" ,netdev_name (skb->dev)); -__this_cpu_dec (mirred_rec_level); +__this_cpu_dec (mirred_nest_level);return TC_ACT_SHOT ; }
@@ -310,7 +310,7 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a, err =tcf_mirred_forward (res->ingress, skb);if (err)tcf_action_inc_overlimit_qstats (&m->common); -__this_cpu_dec (mirred_rec_level); +__this_cpu_dec (mirred_nest_level);return TC_ACT_CONSUMED ; } }
@@ -322,7 +322,7 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,if (tcf_mirred_is_act_redirect (m_eaction)) retval =TC_ACT_SHOT ; } -__this_cpu_dec (mirred_rec_level); +__this_cpu_dec (mirred_nest_level);return retval; }
Signature · 1 line
2.40.1
PATCH 3/3 act_mirred: use the backlog for nested calls to mirred ingress
In reply to Dragos-Marian PanaitFrom: Davide Caratti <[email protected]>
[ Upstream commit ca22da2fbd693b54dc8e3b7b54ccc9f7e9ba3640 ]
William reports kernel soft-lockups on some OVS topologies when TC mirred egress->ingress action is hit by local TCP traffic [1].
The same can also be reproduced with SCTP (thanks Xin for verifying), when client and server reach themselves through mirred egress to ingress, and one of the two peers sends a "heartbeat" packet (from within a timer).
Enqueueing to backlog proved to fix this soft lockup; however, as Cong noticed [2], we should preserve - when possible - the current mirred behavior that counts as "overlimits" any eventual packet drop subsequent to the mirred forwarding action [3]. A compromise solution might use the backlog only when tcf_mirred_act() has a nest level greater than one:
change tcf_mirred_forward() accordingly.
Also, add a kselftest that can reproduce the lockup and verifies TC mirred ability to account for further packet drops after TC mirred egress->ingress (when the nest level is 1).
[1] https://lore.kernel.org/netdev/33dc43f587ec1388ba456b4915c75f02a8aae226.1663945716.git.dcaratti@redhat.com/
[2] https://lore.kernel.org/netdev/Y0w%[email protected]/
[3] such behavior is not guaranteed: for example, if RPS or skb RX
timestamping is enabled on the mirred target device, the kernel
can defer receiving the skb and return NET_RX_SUCCESS inside
tcf_mirred_forward().
--- net/sched/act_mirred.c | 7 +++ .../selftests/net/forwarding/tc_actions.sh | 48 ++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-)
net/sched/act_mirred.c +7 -0
@@ -206,12 +206,19 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,return err; } +static bool is_mirred_nested (void ) +{ +return unlikely (__this_cpu_read (mirred_nest_level) >1 ); +} +static int tcf_mirred_forward (bool want_ingress,struct sk_buff *skb) {int err;if (!want_ingress) err =dev_queue_xmit (skb); +else if (is_mirred_nested ()) + err =netif_rx (skb);else err =netif_receive_skb (skb);
tools/testing/selftests/net/forwarding/tc_actions.sh +47 -1
60 lines not on this page · raw message
Signature · 1 line
2.40.1
Greg KH
maintainerQuoted 4 lines · Dragos-Marian Panait
The following commits are needed to fix CVE-2022-4269:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fa6d639930ee5cd3f932cc314f3407f07a06582d
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=78dcdffe0418ac8f3f057f26fe71ccf4d8ed851f
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ca22da2fbd693b54dc8e3b7b54ccc9f7e9ba3640
All now queued up, thanks.
greg k-h