Ubuntu-focal-kernel/net/sched
Toke Høiland-Jørgensen d601838f0a sched: sch_cake: fix bulk flow accounting logic for host fairness
BugLink: https://bugs.launchpad.net/bugs/2081278

commit 546ea84d07e3e324644025e2aae2d12ea4c5896e upstream.

In sch_cake, we keep track of the count of active bulk flows per host,
when running in dst/src host fairness mode, which is used as the
round-robin weight when iterating through flows. The count of active
bulk flows is updated whenever a flow changes state.

This has a peculiar interaction with the hash collision handling: when a
hash collision occurs (after the set-associative hashing), the state of
the hash bucket is simply updated to match the new packet that collided,
and if host fairness is enabled, that also means assigning new per-host
state to the flow. For this reason, the bulk flow counters of the
host(s) assigned to the flow are decremented, before new state is
assigned (and the counters, which may not belong to the same host
anymore, are incremented again).

Back when this code was introduced, the host fairness mode was always
enabled, so the decrement was unconditional. When the configuration
flags were introduced the *increment* was made conditional, but
the *decrement* was not. Which of course can lead to a spurious
decrement (and associated wrap-around to U16_MAX).

AFAICT, when host fairness is disabled, the decrement and wrap-around
happens as soon as a hash collision occurs (which is not that common in
itself, due to the set-associative hashing). However, in most cases this
is harmless, as the value is only used when host fairness mode is
enabled. So in order to trigger an array overflow, sch_cake has to first
be configured with host fairness disabled, and while running in this
mode, a hash collision has to occur to cause the overflow. Then, the
qdisc has to be reconfigured to enable host fairness, which leads to the
array out-of-bounds because the wrapped-around value is retained and
used as an array index. It seems that syzbot managed to trigger this,
which is quite impressive in its own right.

This patch fixes the issue by introducing the same conditional check on
decrement as is used on increment.

The original bug predates the upstreaming of cake, but the commit listed
in the Fixes tag touched that code, meaning that this patch won't apply
before that.

Fixes: 7126399299 ("sch_cake: Make the dual modes fairer")
Reported-by: syzbot+7fe7b81d602cc1e6b94d@syzkaller.appspotmail.com
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://patch.msgid.link/20240903160846.20909-1-toke@redhat.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2024-09-27 10:50:31 +02:00
..
Kconfig net/sched: Retire dsmark qdisc 2024-04-26 10:54:05 +02:00
Makefile net/sched: Retire dsmark qdisc 2024-04-26 10:54:05 +02:00
act_api.c net/sched: act_api: fix possible infinite loop in tcf_idr_check_alloc() 2024-08-02 16:16:19 +02:00
act_bpf.c
act_connmark.c
act_csum.c
act_ct.c
act_ctinfo.c
act_gact.c
act_ife.c
act_ipt.c
act_meta_mark.c
act_meta_skbprio.c
act_meta_skbtcindex.c
act_mirred.c net/sched: act_mirred: Add carrier check 2023-08-09 12:25:24 +02:00
act_mpls.c net/sched: act_mpls: Fix warning during failed attribute validation 2023-02-01 15:23:48 +01:00
act_nat.c
act_pedit.c net/sched: act_pedit: Add size check for TCA_PEDIT_PARMS_EX 2023-10-02 12:12:08 +02:00
act_police.c net/sched: act_police: more accurate MTU policing 2022-08-26 11:10:55 +02:00
act_sample.c net/sched: act_sample: fix action bind logic 2023-05-12 17:15:14 +02:00
act_simple.c
act_skbedit.c
act_skbmod.c net/sched: act_skbmod: prevent kernel-infoleak 2024-06-07 15:01:39 +02:00
act_tunnel_key.c
act_vlan.c
cls_api.c net/sched: flower: Fix chain template offload 2024-09-27 10:50:28 +02:00
cls_basic.c
cls_bpf.c
cls_cgroup.c
cls_flow.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
cls_flower.c net/sched: flower: Fix chain template offload 2024-09-27 10:50:28 +02:00
cls_fw.c net/sched: cls_fw: No longer copy tcf_result on update to avoid use-after-free 2023-09-01 14:48:40 +02:00
cls_matchall.c
cls_route.c net/sched: cls_route: No longer copy tcf_result on update to avoid use-after-free 2023-09-01 14:48:40 +02:00
cls_u32.c net: sched: cls_u32: Fix match key mis-addressing 2023-10-30 11:41:49 +01:00
em_canid.c
em_cmp.c
em_ipset.c
em_ipt.c
em_meta.c
em_nbyte.c
em_text.c net: sched: em_text: fix possible memory leak in em_text_destroy() 2024-02-23 13:48:04 +01:00
em_u32.c
ematch.c net_sched: reject TCF_EM_SIMPLE case for complex ematch module 2023-02-01 15:23:09 +01:00
sch_api.c net/sched: fix a qdisc modification with ambiguous command request 2023-10-30 11:42:01 +01:00
sch_blackhole.c
sch_cake.c sched: sch_cake: fix bulk flow accounting logic for host fairness 2024-09-27 10:50:31 +02:00
sch_cbs.c
sch_choke.c
sch_codel.c
sch_drr.c
sch_etf.c
sch_fifo.c
sch_fq.c
sch_fq_codel.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
sch_generic.c net_sched: prevent NULL dereference if default qdisc setup failed 2023-07-10 17:22:10 +02:00
sch_gred.c
sch_hfsc.c net/sched: sch_hfsc: upgrade 'rt' to 'sc' when it becomes a inner curve 2024-01-05 14:29:56 +01:00
sch_hhf.c
sch_htb.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
sch_ingress.c net/sched: Reserve TC_H_INGRESS (TC_H_CLSACT) for ingress (clsact) Qdiscs 2023-08-09 12:25:37 +02:00
sch_mq.c
sch_mqprio.c net/sched: mqprio: Add length check for TCA_MQPRIO_{MAX/MIN}_RATE64 2023-10-30 11:41:46 +01:00
sch_multiq.c net: sched: sch_multiq: fix possible OOB write in multiq_tune() 2024-08-02 16:16:09 +02:00
sch_netem.c sch/netem: fix use after free in netem_dequeue 2024-09-27 10:50:30 +02:00
sch_pie.c
sch_plug.c net: sched: sch_qfq: Fix UAF in qfq_dequeue() 2023-10-02 12:12:17 +02:00
sch_prio.c
sch_qfq.c net: sched: sch_qfq: Fix UAF in qfq_dequeue() 2023-10-02 12:12:17 +02:00
sch_red.c net: sched: Fix use after free in red_enqueue() 2023-01-06 08:44:42 -08:00
sch_sfb.c sch_sfb: Also store skb len before calling child enqueue 2022-11-24 10:28:17 +01:00
sch_sfq.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
sch_skbprio.c
sch_taprio.c net/sched: taprio: always validate TCA_TAPRIO_ATTR_PRIOMAP 2024-08-02 16:16:10 +02:00
sch_tbf.c net: sched: tbf: don't call qdisc_put() while holding tree lock 2022-11-24 10:27:47 +01:00
sch_teql.c