android_kernel_motorola_sm6225/net/sched
Jamal Hadi Salim 866e43b0d6 net: sched: cls_u32: Fix match key mis-addressing
[ Upstream commit e68409db995380d1badacba41ff24996bd396171 ]

A match entry is uniquely identified with an "address" or "path" in the
form of: hashtable ID(12b):bucketid(8b):nodeid(12b).

When creating table match entries all of hash table id, bucket id and
node (match entry id) are needed to be either specified by the user or
reasonable in-kernel defaults are used. The in-kernel default for a table id is
0x800(omnipresent root table); for bucketid it is 0x0. Prior to this fix there
was none for a nodeid i.e. the code assumed that the user passed the correct
nodeid and if the user passes a nodeid of 0 (as Mingi Cho did) then that is what
was used. But nodeid of 0 is reserved for identifying the table. This is not
a problem until we dump. The dump code notices that the nodeid is zero and
assumes it is referencing a table and therefore references table struct
tc_u_hnode instead of what was created i.e match entry struct tc_u_knode.

Ming does an equivalent of:
tc filter add dev dummy0 parent 10: prio 1 handle 0x1000 \
protocol ip u32 match ip src 10.0.0.1/32 classid 10:1 action ok

Essentially specifying a table id 0, bucketid 1 and nodeid of zero
Tableid 0 is remapped to the default of 0x800.
Bucketid 1 is ignored and defaults to 0x00.
Nodeid was assumed to be what Ming passed - 0x000

dumping before fix shows:
~$ tc filter ls dev dummy0 parent 10:
filter protocol ip pref 1 u32 chain 0
filter protocol ip pref 1 u32 chain 0 fh 800: ht divisor 1
filter protocol ip pref 1 u32 chain 0 fh 800: ht divisor -30591

Note that the last line reports a table instead of a match entry
(you can tell this because it says "ht divisor...").
As a result of reporting the wrong data type (misinterpretting of struct
tc_u_knode as being struct tc_u_hnode) the divisor is reported with value
of -30591. Ming identified this as part of the heap address
(physmap_base is 0xffff8880 (-30591 - 1)).

The fix is to ensure that when table entry matches are added and no
nodeid is specified (i.e nodeid == 0) then we get the next available
nodeid from the table's pool.

After the fix, this is what the dump shows:
$ tc filter ls dev dummy0 parent 10:
filter protocol ip pref 1 u32 chain 0
filter protocol ip pref 1 u32 chain 0 fh 800: ht divisor 1
filter protocol ip pref 1 u32 chain 0 fh 800::800 order 2048 key ht 800 bkt 0 flowid 10:1 not_in_hw
  match 0a000001/ffffffff at 12
	action order 1: gact action pass
	 random type none pass val 0
	 index 1 ref 1 bind 1

Reported-by: Mingi Cho <mgcho.minic@gmail.com>
Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Link: https://lore.kernel.org/r/20230726135151.416917-1-jhs@mojatatu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-08-11 11:45:37 +02:00
..
act_api.c net: sched: limit TC_ACT_REPEAT loops 2022-02-23 11:58:41 +01:00
act_bpf.c
act_connmark.c
act_csum.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-05-17 11:13:24 +02:00
act_nat.c
act_pedit.c net/sched: act_pedit: Add size check for TCA_PEDIT_PARMS_EX 2023-08-11 11:45:14 +02:00
act_police.c
act_sample.c
act_simple.c
act_skbedit.c
act_skbmod.c net/sched: act_skbmod: Skip non-Ethernet packets 2021-07-28 11:13:48 +02:00
act_tunnel_key.c
act_vlan.c
cls_api.c net: sched: fix possible refcount leak in tc_chain_tmplt_add() 2023-06-14 10:57:13 +02:00
cls_basic.c
cls_bpf.c
cls_cgroup.c
cls_flow.c treewide: Remove uninitialized_var() usage 2023-08-11 11:45:01 +02:00
cls_flower.c net/sched: flower: fix possible OOB write in fl_set_geneve_opt() 2023-06-09 10:23:57 +02:00
cls_fw.c net/sched: cls_fw: Fix improper refcount update leads to use-after-free 2023-08-11 11:45:36 +02:00
cls_matchall.c
cls_route.c net_sched: cls_route: disallow handle of 0 2022-08-25 11:15:33 +02:00
cls_rsvp.c
cls_rsvp.h
cls_rsvp6.c
cls_u32.c net: sched: cls_u32: Fix match key mis-addressing 2023-08-11 11:45:37 +02:00
em_canid.c
em_cmp.c
em_ipset.c
em_ipt.c
em_meta.c
em_nbyte.c
em_text.c
em_u32.c
ematch.c net_sched: reject TCF_EM_SIMPLE case for complex ematch module 2023-01-18 11:30:32 +01:00
Kconfig net/sched: Retire tcindex classifier 2023-03-11 16:31:55 +01:00
Makefile net/sched: Retire tcindex classifier 2023-03-11 16:31:55 +01:00
sch_api.c net: sched: fix NULL pointer dereference in mq_attach 2023-06-09 10:23:56 +02:00
sch_atm.c net: sched: atm: dont intepret cls results when asked to drop 2023-01-18 11:30:50 +01:00
sch_blackhole.c
sch_cake.c treewide: Remove uninitialized_var() usage 2023-08-11 11:45:01 +02:00
sch_cbq.c treewide: Remove uninitialized_var() usage 2023-08-11 11:45:01 +02:00
sch_cbs.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_choke.c net: sched: validate stab values 2021-03-30 14:37:03 +02:00
sch_codel.c
sch_drr.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_dsmark.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_etf.c
sch_fifo.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_fq.c
sch_fq_codel.c treewide: Remove uninitialized_var() usage 2023-08-11 11:45:01 +02:00
sch_generic.c net: Fix data-races around weight_p and dev_weight_[rt]x_bias. 2022-09-05 10:26:30 +02:00
sch_gred.c net: sched: validate stab values 2021-03-30 14:37:03 +02:00
sch_hfsc.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_hhf.c
sch_htb.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_ingress.c net/sched: Reserve TC_H_INGRESS (TC_H_CLSACT) for ingress (clsact) Qdiscs 2023-06-09 10:23:56 +02:00
sch_mq.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_mqprio.c net/sched: mqprio: Add length check for TCA_MQPRIO_{MAX/MIN}_RATE64 2023-08-11 11:45:31 +02:00
sch_multiq.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_netem.c sch_netem: acquire qdisc lock in netem_change() 2023-06-28 10:15:30 +02:00
sch_pie.c
sch_plug.c
sch_prio.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_qfq.c net/sched: sch_qfq: account for stab overhead in qfq_enqueue 2023-08-11 11:45:36 +02:00
sch_red.c net: sched: Fix use after free in red_enqueue() 2022-11-10 17:46:52 +01:00
sch_sfb.c sch_sfb: Also store skb len before calling child enqueue 2022-09-15 12:17:06 +02:00
sch_sfq.c treewide: Remove uninitialized_var() usage 2023-08-11 11:45:01 +02:00
sch_skbprio.c
sch_tbf.c net: sched: rename qdisc_destroy() to qdisc_put() 2021-12-14 10:18:04 +01:00
sch_teql.c net: sched: sch_teql: fix null-pointer dereference 2021-04-14 08:22:33 +02:00