Blame SOURCES/CVE-2023-4921.patch

65e7f7
From 84eda7845563ee9c0cc215fe9d0a3c67cb4903fd Mon Sep 17 00:00:00 2001
65e7f7
From: Ryan Sullivan <rysulliv@redhat.com>
65e7f7
Date: Thu, 1 Feb 2024 14:36:30 -0500
65e7f7
Subject: [KPATCH CVE-2023-4921] kpatch fixes for CVE-2023-4921
65e7f7
65e7f7
Kernels:
65e7f7
3.10.0-1160.95.1.el7
65e7f7
3.10.0-1160.99.1.el7
65e7f7
3.10.0-1160.102.1.el7
65e7f7
3.10.0-1160.105.1.el7
65e7f7
3.10.0-1160.108.1.el7
65e7f7
65e7f7
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-7/-/merge_requests/67
65e7f7
Approved-by: Joe Lawrence (@joe.lawrence)
65e7f7
Changes since last build:
65e7f7
[x86_64]:
65e7f7
igb_main.o: changed function: igb_configure
65e7f7
l2cap_core.o: changed function: l2cap_chan_hold
65e7f7
l2cap_core.o: changed function: l2cap_conn_get
65e7f7
l2cap_core.o: changed function: l2cap_global_chan_by_psm
65e7f7
l2cap_core.o: changed function: l2cap_recv_frame
65e7f7
l2cap_core.o: new function: klp_l2cap_le_sig_cmd
65e7f7
sch_atm.o: changed function: atm_tc_peek
65e7f7
sch_atm.o: changed function: sch_atm_dequeue
65e7f7
sch_drr.o: changed function: drr_dequeue
65e7f7
sch_dsmark.o: changed function: dsmark_peek
65e7f7
sch_hfsc.o: changed function: hfsc_enqueue
65e7f7
sch_hfsc.o: changed function: qdisc_peek_len
65e7f7
sch_multiq.o: changed function: multiq_peek
65e7f7
sch_prio.o: changed function: prio_peek
65e7f7
sch_qfq.o: changed function: qfq_dequeue
65e7f7
sch_qfq.o: changed function: qfq_enqueue
65e7f7
sch_red.o: changed function: red_peek
65e7f7
sch_sfb.o: changed function: sfb_peek
65e7f7
sch_tbf.o: changed function: tbf_dequeue
65e7f7
65e7f7
[ppc64le]:
65e7f7
l2cap_core.o: changed function: __l2cap_chan_add
65e7f7
l2cap_core.o: changed function: __l2cap_physical_cfm
65e7f7
l2cap_core.o: changed function: __set_monitor_timer
65e7f7
l2cap_core.o: changed function: __set_retrans_timer.part.24
65e7f7
l2cap_core.o: changed function: l2cap_ack_timeout
65e7f7
l2cap_core.o: changed function: l2cap_build_conf_req
65e7f7
l2cap_core.o: changed function: l2cap_chan_busy
65e7f7
l2cap_core.o: changed function: l2cap_chan_close
65e7f7
l2cap_core.o: changed function: l2cap_chan_connect
65e7f7
l2cap_core.o: changed function: l2cap_chan_del
65e7f7
l2cap_core.o: changed function: l2cap_chan_hold
65e7f7
l2cap_core.o: changed function: l2cap_chan_put
65e7f7
l2cap_core.o: changed function: l2cap_chan_send
65e7f7
l2cap_core.o: changed function: l2cap_chan_timeout
65e7f7
l2cap_core.o: changed function: l2cap_conn_add.part.28
65e7f7
l2cap_core.o: changed function: l2cap_conn_del
65e7f7
l2cap_core.o: changed function: l2cap_conn_start
65e7f7
l2cap_core.o: changed function: l2cap_connect
65e7f7
l2cap_core.o: changed function: l2cap_connect_cfm
65e7f7
l2cap_core.o: changed function: l2cap_connect_create_rsp
65e7f7
l2cap_core.o: changed function: l2cap_data_channel
65e7f7
l2cap_core.o: changed function: l2cap_disconn_cfm
65e7f7
l2cap_core.o: changed function: l2cap_do_create
65e7f7
l2cap_core.o: changed function: l2cap_do_start
65e7f7
l2cap_core.o: changed function: l2cap_ertm_resend
65e7f7
l2cap_core.o: changed function: l2cap_ertm_send
65e7f7
l2cap_core.o: changed function: l2cap_global_fixed_chan
65e7f7
l2cap_core.o: changed function: l2cap_handle_rej
65e7f7
l2cap_core.o: changed function: l2cap_handle_srej
65e7f7
l2cap_core.o: changed function: l2cap_logical_cfm
65e7f7
l2cap_core.o: changed function: l2cap_monitor_timeout
65e7f7
l2cap_core.o: changed function: l2cap_move_done
65e7f7
l2cap_core.o: changed function: l2cap_move_setup
65e7f7
l2cap_core.o: changed function: l2cap_parse_conf_rsp.constprop.36
65e7f7
l2cap_core.o: changed function: l2cap_pass_to_tx
65e7f7
l2cap_core.o: changed function: l2cap_process_reqseq
65e7f7
l2cap_core.o: changed function: l2cap_recv_frame
65e7f7
l2cap_core.o: changed function: l2cap_retrans_timeout
65e7f7
l2cap_core.o: changed function: l2cap_retransmit_all
65e7f7
l2cap_core.o: changed function: l2cap_rx
65e7f7
l2cap_core.o: changed function: l2cap_rx_state_recv
65e7f7
l2cap_core.o: changed function: l2cap_security_cfm
65e7f7
l2cap_core.o: changed function: l2cap_send_ack
65e7f7
l2cap_core.o: changed function: l2cap_send_efs_conf_rsp
65e7f7
l2cap_core.o: changed function: l2cap_send_i_or_rr_or_rnr
65e7f7
l2cap_core.o: changed function: l2cap_send_move_chan_cfm
65e7f7
l2cap_core.o: changed function: l2cap_send_move_chan_cfm_icid
65e7f7
l2cap_core.o: changed function: l2cap_send_move_chan_req
65e7f7
l2cap_core.o: changed function: l2cap_send_rr_or_rnr
65e7f7
l2cap_core.o: changed function: l2cap_send_sframe
65e7f7
l2cap_core.o: changed function: l2cap_send_srej
65e7f7
l2cap_core.o: changed function: l2cap_send_srej_tail
65e7f7
l2cap_core.o: changed function: l2cap_start_connection
65e7f7
l2cap_core.o: new function: l2cap_connect_req
65e7f7
sch_atm.o: changed function: atm_tc_bind_filter
65e7f7
sch_atm.o: changed function: atm_tc_change
65e7f7
sch_atm.o: changed function: atm_tc_delete
65e7f7
sch_atm.o: changed function: atm_tc_destroy
65e7f7
sch_atm.o: changed function: atm_tc_enqueue
65e7f7
sch_atm.o: changed function: atm_tc_find
65e7f7
sch_atm.o: changed function: atm_tc_graft
65e7f7
sch_atm.o: changed function: atm_tc_leaf
65e7f7
sch_atm.o: changed function: atm_tc_peek
65e7f7
sch_atm.o: changed function: atm_tc_put
65e7f7
sch_atm.o: changed function: atm_tc_reset
65e7f7
sch_atm.o: changed function: atm_tc_tcf_block
65e7f7
sch_atm.o: changed function: sch_atm_dequeue
65e7f7
sch_drr.o: changed function: drr_dequeue
65e7f7
sch_dsmark.o: changed function: dsmark_bind_filter
65e7f7
sch_dsmark.o: changed function: dsmark_change
65e7f7
sch_dsmark.o: changed function: dsmark_destroy
65e7f7
sch_dsmark.o: changed function: dsmark_dump_class
65e7f7
sch_dsmark.o: changed function: dsmark_init
65e7f7
sch_dsmark.o: changed function: dsmark_peek
65e7f7
sch_dsmark.o: changed function: dsmark_reset
65e7f7
sch_hfsc.o: changed function: hfsc_change_class
65e7f7
sch_hfsc.o: changed function: hfsc_dequeue
65e7f7
sch_hfsc.o: changed function: hfsc_enqueue
65e7f7
sch_multiq.o: changed function: multiq_peek
65e7f7
sch_prio.o: changed function: prio_peek
65e7f7
sch_qfq.o: changed function: qfq_dequeue
65e7f7
sch_qfq.o: changed function: qfq_enqueue
65e7f7
sch_red.o: changed function: red_peek
65e7f7
sch_sfb.o: changed function: sfb_peek
65e7f7
sch_tbf.o: changed function: tbf_dequeue
65e7f7
65e7f7
---------------------------
65e7f7
65e7f7
Modifications:
65e7f7
- redirected to qdisc_peek_dequeued() by modifying functions that
65e7f7
called '->peek(qdisc)' to call klp_cve_2023_4921_peek() rather than by
65e7f7
modifying plug_qdisc_ops
65e7f7
- don't remove existing WARN_ONCE instances to avoid kpatch-build
65e7f7
"unreconcilable difference" error in .data.once section
65e7f7
65e7f7
commit faf95907a10c29861882d7885b6e04ebe20057c8
65e7f7
Author: Davide Caratti <dcaratti@redhat.com>
65e7f7
Date:   Fri Oct 27 17:22:42 2023 +0200
65e7f7
65e7f7
    net: sched: sch_qfq: Fix UAF in qfq_dequeue()
65e7f7
65e7f7
    JIRA: https://issues.redhat.com/browse/RHEL-14397
65e7f7
    CVE: CVE-2023-4921
65e7f7
    Upstream Status: net.git commit 8fc134fee27f2263988ae38920bc03da416b03d8
65e7f7
65e7f7
    commit 8fc134fee27f2263988ae38920bc03da416b03d8
65e7f7
    Author: valis <sec@valis.email>
65e7f7
    Date:   Fri Sep 1 12:22:37 2023 -0400
65e7f7
65e7f7
        net: sched: sch_qfq: Fix UAF in qfq_dequeue()
65e7f7
65e7f7
        When the plug qdisc is used as a class of the qfq qdisc it could trigger a
65e7f7
        UAF. This issue can be reproduced with following commands:
65e7f7
65e7f7
          tc qdisc add dev lo root handle 1: qfq
65e7f7
          tc class add dev lo parent 1: classid 1:1 qfq weight 1 maxpkt 512
65e7f7
          tc qdisc add dev lo parent 1:1 handle 2: plug
65e7f7
          tc filter add dev lo parent 1: basic classid 1:1
65e7f7
          ping -c1 127.0.0.1
65e7f7
65e7f7
        and boom:
65e7f7
65e7f7
        [  285.353793] BUG: KASAN: slab-use-after-free in qfq_dequeue+0xa7/0x7f0
65e7f7
        [  285.354910] Read of size 4 at addr ffff8880bad312a8 by task ping/144
65e7f7
        [  285.355903]
65e7f7
        [  285.356165] CPU: 1 PID: 144 Comm: ping Not tainted 6.5.0-rc3+ #4
65e7f7
        [  285.357112] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
65e7f7
        [  285.358376] Call Trace:
65e7f7
        [  285.358773]  <IRQ>
65e7f7
        [  285.359109]  dump_stack_lvl+0x44/0x60
65e7f7
        [  285.359708]  print_address_description.constprop.0+0x2c/0x3c0
65e7f7
        [  285.360611]  kasan_report+0x10c/0x120
65e7f7
        [  285.361195]  ? qfq_dequeue+0xa7/0x7f0
65e7f7
        [  285.361780]  qfq_dequeue+0xa7/0x7f0
65e7f7
        [  285.362342]  __qdisc_run+0xf1/0x970
65e7f7
        [  285.362903]  net_tx_action+0x28e/0x460
65e7f7
        [  285.363502]  __do_softirq+0x11b/0x3de
65e7f7
        [  285.364097]  do_softirq.part.0+0x72/0x90
65e7f7
        [  285.364721]  </IRQ>
65e7f7
        [  285.365072]  <TASK>
65e7f7
        [  285.365422]  __local_bh_enable_ip+0x77/0x90
65e7f7
        [  285.366079]  __dev_queue_xmit+0x95f/0x1550
65e7f7
        [  285.366732]  ? __pfx_csum_and_copy_from_iter+0x10/0x10
65e7f7
        [  285.367526]  ? __pfx___dev_queue_xmit+0x10/0x10
65e7f7
        [  285.368259]  ? __build_skb_around+0x129/0x190
65e7f7
        [  285.368960]  ? ip_generic_getfrag+0x12c/0x170
65e7f7
        [  285.369653]  ? __pfx_ip_generic_getfrag+0x10/0x10
65e7f7
        [  285.370390]  ? csum_partial+0x8/0x20
65e7f7
        [  285.370961]  ? raw_getfrag+0xe5/0x140
65e7f7
        [  285.371559]  ip_finish_output2+0x539/0xa40
65e7f7
        [  285.372222]  ? __pfx_ip_finish_output2+0x10/0x10
65e7f7
        [  285.372954]  ip_output+0x113/0x1e0
65e7f7
        [  285.373512]  ? __pfx_ip_output+0x10/0x10
65e7f7
        [  285.374130]  ? icmp_out_count+0x49/0x60
65e7f7
        [  285.374739]  ? __pfx_ip_finish_output+0x10/0x10
65e7f7
        [  285.375457]  ip_push_pending_frames+0xf3/0x100
65e7f7
        [  285.376173]  raw_sendmsg+0xef5/0x12d0
65e7f7
        [  285.376760]  ? do_syscall_64+0x40/0x90
65e7f7
        [  285.377359]  ? __static_call_text_end+0x136578/0x136578
65e7f7
        [  285.378173]  ? do_syscall_64+0x40/0x90
65e7f7
        [  285.378772]  ? kasan_enable_current+0x11/0x20
65e7f7
        [  285.379469]  ? __pfx_raw_sendmsg+0x10/0x10
65e7f7
        [  285.380137]  ? __sock_create+0x13e/0x270
65e7f7
        [  285.380673]  ? __sys_socket+0xf3/0x180
65e7f7
        [  285.381174]  ? __x64_sys_socket+0x3d/0x50
65e7f7
        [  285.381725]  ? entry_SYSCALL_64_after_hwframe+0x6e/0xd8
65e7f7
        [  285.382425]  ? __rcu_read_unlock+0x48/0x70
65e7f7
        [  285.382975]  ? ip4_datagram_release_cb+0xd8/0x380
65e7f7
        [  285.383608]  ? __pfx_ip4_datagram_release_cb+0x10/0x10
65e7f7
        [  285.384295]  ? preempt_count_sub+0x14/0xc0
65e7f7
        [  285.384844]  ? __list_del_entry_valid+0x76/0x140
65e7f7
        [  285.385467]  ? _raw_spin_lock_bh+0x87/0xe0
65e7f7
        [  285.386014]  ? __pfx__raw_spin_lock_bh+0x10/0x10
65e7f7
        [  285.386645]  ? release_sock+0xa0/0xd0
65e7f7
        [  285.387148]  ? preempt_count_sub+0x14/0xc0
65e7f7
        [  285.387712]  ? freeze_secondary_cpus+0x348/0x3c0
65e7f7
        [  285.388341]  ? aa_sk_perm+0x177/0x390
65e7f7
        [  285.388856]  ? __pfx_aa_sk_perm+0x10/0x10
65e7f7
        [  285.389441]  ? check_stack_object+0x22/0x70
65e7f7
        [  285.390032]  ? inet_send_prepare+0x2f/0x120
65e7f7
        [  285.390603]  ? __pfx_inet_sendmsg+0x10/0x10
65e7f7
        [  285.391172]  sock_sendmsg+0xcc/0xe0
65e7f7
        [  285.391667]  __sys_sendto+0x190/0x230
65e7f7
        [  285.392168]  ? __pfx___sys_sendto+0x10/0x10
65e7f7
        [  285.392727]  ? kvm_clock_get_cycles+0x14/0x30
65e7f7
        [  285.393328]  ? set_normalized_timespec64+0x57/0x70
65e7f7
        [  285.393980]  ? _raw_spin_unlock_irq+0x1b/0x40
65e7f7
        [  285.394578]  ? __x64_sys_clock_gettime+0x11c/0x160
65e7f7
        [  285.395225]  ? __pfx___x64_sys_clock_gettime+0x10/0x10
65e7f7
        [  285.395908]  ? _copy_to_user+0x3e/0x60
65e7f7
        [  285.396432]  ? exit_to_user_mode_prepare+0x1a/0x120
65e7f7
        [  285.397086]  ? syscall_exit_to_user_mode+0x22/0x50
65e7f7
        [  285.397734]  ? do_syscall_64+0x71/0x90
65e7f7
        [  285.398258]  __x64_sys_sendto+0x74/0x90
65e7f7
        [  285.398786]  do_syscall_64+0x64/0x90
65e7f7
        [  285.399273]  ? exit_to_user_mode_prepare+0x1a/0x120
65e7f7
        [  285.399949]  ? syscall_exit_to_user_mode+0x22/0x50
65e7f7
        [  285.400605]  ? do_syscall_64+0x71/0x90
65e7f7
        [  285.401124]  entry_SYSCALL_64_after_hwframe+0x6e/0xd8
65e7f7
        [  285.401807] RIP: 0033:0x495726
65e7f7
        [  285.402233] Code: ff ff ff f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b8 0f 1f 00 41 89 ca 64 8b 04 25 18 00 00 00 85 c0 75 11 b8 2c 00 00 00 0f 09
65e7f7
        [  285.404683] RSP: 002b:00007ffcc25fb618 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
65e7f7
        [  285.405677] RAX: ffffffffffffffda RBX: 0000000000000040 RCX: 0000000000495726
65e7f7
        [  285.406628] RDX: 0000000000000040 RSI: 0000000002518750 RDI: 0000000000000000
65e7f7
        [  285.407565] RBP: 00000000005205ef R08: 00000000005f8838 R09: 000000000000001c
65e7f7
        [  285.408523] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000002517634
65e7f7
        [  285.409460] R13: 00007ffcc25fb6f0 R14: 0000000000000003 R15: 0000000000000000
65e7f7
        [  285.410403]  </TASK>
65e7f7
        [  285.410704]
65e7f7
        [  285.410929] Allocated by task 144:
65e7f7
        [  285.411402]  kasan_save_stack+0x1e/0x40
65e7f7
        [  285.411926]  kasan_set_track+0x21/0x30
65e7f7
        [  285.412442]  __kasan_slab_alloc+0x55/0x70
65e7f7
        [  285.412973]  kmem_cache_alloc_node+0x187/0x3d0
65e7f7
        [  285.413567]  __alloc_skb+0x1b4/0x230
65e7f7
        [  285.414060]  __ip_append_data+0x17f7/0x1b60
65e7f7
        [  285.414633]  ip_append_data+0x97/0xf0
65e7f7
        [  285.415144]  raw_sendmsg+0x5a8/0x12d0
65e7f7
        [  285.415640]  sock_sendmsg+0xcc/0xe0
65e7f7
        [  285.416117]  __sys_sendto+0x190/0x230
65e7f7
        [  285.416626]  __x64_sys_sendto+0x74/0x90
65e7f7
        [  285.417145]  do_syscall_64+0x64/0x90
65e7f7
        [  285.417624]  entry_SYSCALL_64_after_hwframe+0x6e/0xd8
65e7f7
        [  285.418306]
65e7f7
        [  285.418531] Freed by task 144:
65e7f7
        [  285.418960]  kasan_save_stack+0x1e/0x40
65e7f7
        [  285.419469]  kasan_set_track+0x21/0x30
65e7f7
        [  285.419988]  kasan_save_free_info+0x27/0x40
65e7f7
        [  285.420556]  ____kasan_slab_free+0x109/0x1a0
65e7f7
        [  285.421146]  kmem_cache_free+0x1c2/0x450
65e7f7
        [  285.421680]  __netif_receive_skb_core+0x2ce/0x1870
65e7f7
        [  285.422333]  __netif_receive_skb_one_core+0x97/0x140
65e7f7
        [  285.423003]  process_backlog+0x100/0x2f0
65e7f7
        [  285.423537]  __napi_poll+0x5c/0x2d0
65e7f7
        [  285.424023]  net_rx_action+0x2be/0x560
65e7f7
        [  285.424510]  __do_softirq+0x11b/0x3de
65e7f7
        [  285.425034]
65e7f7
        [  285.425254] The buggy address belongs to the object at ffff8880bad31280
65e7f7
        [  285.425254]  which belongs to the cache skbuff_head_cache of size 224
65e7f7
        [  285.426993] The buggy address is located 40 bytes inside of
65e7f7
        [  285.426993]  freed 224-byte region [ffff8880bad31280, ffff8880bad31360)
65e7f7
        [  285.428572]
65e7f7
        [  285.428798] The buggy address belongs to the physical page:
65e7f7
        [  285.429540] page:00000000f4b77674 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0xbad31
65e7f7
        [  285.430758] flags: 0x100000000000200(slab|node=0|zone=1)
65e7f7
        [  285.431447] page_type: 0xffffffff()
65e7f7
        [  285.431934] raw: 0100000000000200 ffff88810094a8c0 dead000000000122 0000000000000000
65e7f7
        [  285.432757] raw: 0000000000000000 00000000800c000c 00000001ffffffff 0000000000000000
65e7f7
        [  285.433562] page dumped because: kasan: bad access detected
65e7f7
        [  285.434144]
65e7f7
        [  285.434320] Memory state around the buggy address:
65e7f7
        [  285.434828]  ffff8880bad31180: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
65e7f7
        [  285.435580]  ffff8880bad31200: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
65e7f7
        [  285.436264] >ffff8880bad31280: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
65e7f7
        [  285.436777]                                   ^
65e7f7
        [  285.437106]  ffff8880bad31300: fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
65e7f7
        [  285.437616]  ffff8880bad31380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
65e7f7
        [  285.438126] ==================================================================
65e7f7
        [  285.438662] Disabling lock debugging due to kernel taint
65e7f7
65e7f7
        Fix this by:
65e7f7
        1. Changing sch_plug's .peek handler to qdisc_peek_dequeued(), a
65e7f7
        function compatible with non-work-conserving qdiscs
65e7f7
        2. Checking the return value of qdisc_dequeue_peeked() in sch_qfq.
65e7f7
65e7f7
        Fixes: 462dbc9101ac ("pkt_sched: QFQ Plus: fair-queueing service at DRR cost")
65e7f7
        Reported-by: valis <sec@valis.email>
65e7f7
        Signed-off-by: valis <sec@valis.email>
65e7f7
        Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
65e7f7
        Link: https://lore.kernel.org/r/20230901162237.11525-1-jhs@mojatatu.com
65e7f7
        Signed-off-by: Paolo Abeni <pabeni@redhat.com>
65e7f7
65e7f7
    Signed-off-by: Davide Caratti <dcaratti@redhat.com>
65e7f7
65e7f7
commit eb76ae2165f95d31ad199d706840140b271c719e
65e7f7
Author: Davide Caratti <dcaratti@redhat.com>
65e7f7
Date:   Thu Jan 25 15:45:42 2024 +0100
65e7f7
65e7f7
    net: sched: sch_qfq: Use non-work-conserving warning handler
65e7f7
65e7f7
    JIRA: https://issues.redhat.com/browse/RHEL-14397
65e7f7
    Upstream Status: net.git commit 6d25d1dc76bf5943a5c1f4bb74d66d5eac58eb77
65e7f7
65e7f7
    commit 6d25d1dc76bf5943a5c1f4bb74d66d5eac58eb77
65e7f7
    Author: Liu Jian <liujian56@huawei.com>
65e7f7
    Date:   Mon Oct 23 14:47:29 2023 +0800
65e7f7
65e7f7
        net: sched: sch_qfq: Use non-work-conserving warning handler
65e7f7
65e7f7
        A helper function for printing non-work-conserving alarms is added in
65e7f7
        commit b00355db3f88 ("pkt_sched: sch_hfsc: sch_htb: Add non-work-conserving
65e7f7
         warning handler."). In this commit, use qdisc_warn_nonwc() instead of
65e7f7
        WARN_ONCE() to handle the non-work-conserving warning in qfq Qdisc.
65e7f7
65e7f7
        Signed-off-by: Liu Jian <liujian56@huawei.com>
65e7f7
        Link: https://lore.kernel.org/r/20231023064729.370649-1-liujian56@huawei.com
65e7f7
        Signed-off-by: Paolo Abeni <pabeni@redhat.com>
65e7f7
65e7f7
    Signed-off-by: Davide Caratti <dcaratti@redhat.com>
65e7f7
65e7f7
Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
65e7f7
---
65e7f7
 net/sched/klp_cve_2023_4921.h | 16 +++++++++++++
65e7f7
 net/sched/sch_atm.c           |  5 ++--
65e7f7
 net/sched/sch_drr.c           |  3 ++-
65e7f7
 net/sched/sch_dsmark.c        |  3 ++-
65e7f7
 net/sched/sch_hfsc.c          |  7 +++---
65e7f7
 net/sched/sch_multiq.c        |  4 +++-
65e7f7
 net/sched/sch_prio.c          |  6 ++++-
65e7f7
 net/sched/sch_qfq.c           | 43 ++++++++++++++++++++++++++---------
65e7f7
 net/sched/sch_red.c           |  3 ++-
65e7f7
 net/sched/sch_sfb.c           |  3 ++-
65e7f7
 net/sched/sch_tbf.c           |  3 ++-
65e7f7
 11 files changed, 73 insertions(+), 23 deletions(-)
65e7f7
 create mode 100644 net/sched/klp_cve_2023_4921.h
65e7f7
65e7f7
diff --git a/net/sched/klp_cve_2023_4921.h b/net/sched/klp_cve_2023_4921.h
65e7f7
new file mode 100644
65e7f7
index 000000000000..07a5624a487c
65e7f7
--- /dev/null
65e7f7
+++ b/net/sched/klp_cve_2023_4921.h
65e7f7
@@ -0,0 +1,16 @@
65e7f7
+#ifndef __KLP_CVE_2023_4921__
65e7f7
+#define __KLP_CVE_2023_4921__
65e7f7
+
65e7f7
+static inline struct sk_buff *klp_cve_2023_4921_peek(struct Qdisc *sch)
65e7f7
+{
65e7f7
+	/*
65e7f7
+	 * kpatch workaround: can't modify plug_qdisc_ops structure, so
65e7f7
+	 * provide a peek pivot based on the underlying qdisc ops id
65e7f7
+	 */
65e7f7
+	if (strcmp(sch->ops->id, "plug") == 0)
65e7f7
+		return qdisc_peek_dequeued(sch);
65e7f7
+
65e7f7
+	return sch->ops->peek(sch);
65e7f7
+}
65e7f7
+
65e7f7
+#endif
65e7f7
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c
65e7f7
index 7c8966a42794..d58c84b3fba2 100644
65e7f7
--- a/net/sched/sch_atm.c
65e7f7
+++ b/net/sched/sch_atm.c
65e7f7
@@ -16,6 +16,7 @@
65e7f7
 #include <net/netlink.h>
65e7f7
 #include <net/pkt_sched.h>
65e7f7
 #include <net/pkt_cls.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 /*
65e7f7
  * The ATM queuing discipline provides a framework for invoking classifiers
65e7f7
@@ -474,7 +475,7 @@ static void sch_atm_dequeue(unsigned long data)
65e7f7
 		 * If traffic is properly shaped, this won't generate nasty
65e7f7
 		 * little bursts. Otherwise, it may ... (but that's okay)
65e7f7
 		 */
65e7f7
-		while ((skb = flow->q->ops->peek(flow->q))) {
65e7f7
+		while ((skb = klp_cve_2023_4921_peek(flow->q))) {
65e7f7
 			if (!atm_may_send(flow->vcc, skb->truesize))
65e7f7
 				break;
65e7f7
 
65e7f7
@@ -528,7 +529,7 @@ static struct sk_buff *atm_tc_peek(struct Qdisc *sch)
65e7f7
 
65e7f7
 	pr_debug("atm_tc_peek(sch %p,[qdisc %p])\n", sch, p);
65e7f7
 
65e7f7
-	return p->link.q->ops->peek(p->link.q);
65e7f7
+	return klp_cve_2023_4921_peek(p->link.q);
65e7f7
 }
65e7f7
 
65e7f7
 static int atm_tc_init(struct Qdisc *sch, struct nlattr *opt)
65e7f7
diff --git a/net/sched/sch_drr.c b/net/sched/sch_drr.c
65e7f7
index 9bfe7b50115f..27dd8e610da2 100644
65e7f7
--- a/net/sched/sch_drr.c
65e7f7
+++ b/net/sched/sch_drr.c
65e7f7
@@ -17,6 +17,7 @@
65e7f7
 #include <net/sch_generic.h>
65e7f7
 #include <net/pkt_sched.h>
65e7f7
 #include <net/pkt_cls.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 struct drr_class {
65e7f7
 	struct Qdisc_class_common	common;
65e7f7
@@ -378,7 +379,7 @@ static struct sk_buff *drr_dequeue(struct Qdisc *sch)
65e7f7
 		goto out;
65e7f7
 	while (1) {
65e7f7
 		cl = list_first_entry(&q->active, struct drr_class, alist);
65e7f7
-		skb = cl->qdisc->ops->peek(cl->qdisc);
65e7f7
+		skb = klp_cve_2023_4921_peek(cl->qdisc);
65e7f7
 		if (skb == NULL) {
65e7f7
 			qdisc_warn_nonwc(__func__, cl->qdisc);
65e7f7
 			goto out;
65e7f7
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c
65e7f7
index df08e15e6f19..06b6e03f89ea 100644
65e7f7
--- a/net/sched/sch_dsmark.c
65e7f7
+++ b/net/sched/sch_dsmark.c
65e7f7
@@ -17,6 +17,7 @@
65e7f7
 #include <net/dsfield.h>
65e7f7
 #include <net/inet_ecn.h>
65e7f7
 #include <asm/byteorder.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 /*
65e7f7
  * classid	class		marking
65e7f7
@@ -327,7 +328,7 @@ static struct sk_buff *dsmark_peek(struct Qdisc *sch)
65e7f7
 
65e7f7
 	pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
65e7f7
 
65e7f7
-	return p->q->ops->peek(p->q);
65e7f7
+	return klp_cve_2023_4921_peek(p->q);
65e7f7
 }
65e7f7
 
65e7f7
 static int dsmark_init(struct Qdisc *sch, struct nlattr *opt)
65e7f7
diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c
65e7f7
index fb14b551f65d..466244c57737 100644
65e7f7
--- a/net/sched/sch_hfsc.c
65e7f7
+++ b/net/sched/sch_hfsc.c
65e7f7
@@ -67,6 +67,7 @@
65e7f7
 #include <net/pkt_sched.h>
65e7f7
 #include <net/pkt_cls.h>
65e7f7
 #include <asm/div64.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 /*
65e7f7
  * kernel internal service curve representation:
65e7f7
@@ -834,7 +835,8 @@ qdisc_peek_len(struct Qdisc *sch)
65e7f7
 	struct sk_buff *skb;
65e7f7
 	unsigned int len;
65e7f7
 
65e7f7
-	skb = sch->ops->peek(sch);
65e7f7
+	skb = klp_cve_2023_4921_peek(sch);
65e7f7
+
65e7f7
 	if (unlikely(skb == NULL)) {
65e7f7
 		qdisc_warn_nonwc("qdisc_peek_len", sch);
65e7f7
 		return 0;
65e7f7
@@ -1567,8 +1569,7 @@ hfsc_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free)
65e7f7
 		 * to invalidate the deadline.
65e7f7
 		 */
65e7f7
 		if (cl->cl_flags & HFSC_RSC)
65e7f7
-			cl->qdisc->ops->peek(cl->qdisc);
65e7f7
-
65e7f7
+			klp_cve_2023_4921_peek(cl->qdisc);
65e7f7
 	}
65e7f7
 
65e7f7
 	qdisc_qstats_backlog_inc(sch, skb);
65e7f7
diff --git a/net/sched/sch_multiq.c b/net/sched/sch_multiq.c
65e7f7
index 31e0a284eeff..8f6e85b2c8b8 100644
65e7f7
--- a/net/sched/sch_multiq.c
65e7f7
+++ b/net/sched/sch_multiq.c
65e7f7
@@ -26,6 +26,7 @@
65e7f7
 #include <net/netlink.h>
65e7f7
 #include <net/pkt_sched.h>
65e7f7
 #include <net/pkt_cls.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 struct multiq_sched_data {
65e7f7
 	u16 bands;
65e7f7
@@ -145,7 +146,8 @@ static struct sk_buff *multiq_peek(struct Qdisc *sch)
65e7f7
 		if (!netif_xmit_stopped(
65e7f7
 		    netdev_get_tx_queue(qdisc_dev(sch), curband))) {
65e7f7
 			qdisc = q->queues[curband];
65e7f7
-			skb = qdisc->ops->peek(qdisc);
65e7f7
+			skb = klp_cve_2023_4921_peek(qdisc);
65e7f7
+
65e7f7
 			if (skb)
65e7f7
 				return skb;
65e7f7
 		}
65e7f7
diff --git a/net/sched/sch_prio.c b/net/sched/sch_prio.c
65e7f7
index faf447b60b68..23526ef54f0c 100644
65e7f7
--- a/net/sched/sch_prio.c
65e7f7
+++ b/net/sched/sch_prio.c
65e7f7
@@ -21,6 +21,7 @@
65e7f7
 #include <net/netlink.h>
65e7f7
 #include <net/pkt_sched.h>
65e7f7
 #include <net/pkt_cls.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 struct prio_sched_data {
65e7f7
 	int bands;
65e7f7
@@ -103,7 +104,10 @@ static struct sk_buff *prio_peek(struct Qdisc *sch)
65e7f7
 
65e7f7
 	for (prio = 0; prio < q->bands; prio++) {
65e7f7
 		struct Qdisc *qdisc = q->queues[prio];
65e7f7
-		struct sk_buff *skb = qdisc->ops->peek(qdisc);
65e7f7
+		struct sk_buff *skb;
65e7f7
+
65e7f7
+		skb = klp_cve_2023_4921_peek(qdisc);
65e7f7
+
65e7f7
 		if (skb)
65e7f7
 			return skb;
65e7f7
 	}
65e7f7
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
65e7f7
index ca8c79456c80..134cd66225c0 100644
65e7f7
--- a/net/sched/sch_qfq.c
65e7f7
+++ b/net/sched/sch_qfq.c
65e7f7
@@ -18,6 +18,8 @@
65e7f7
 #include <net/sch_generic.h>
65e7f7
 #include <net/pkt_sched.h>
65e7f7
 #include <net/pkt_cls.h>
65e7f7
+#include <linux/string.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 
65e7f7
 /*  Quick Fair Queueing Plus
65e7f7
@@ -984,19 +986,24 @@ static void qfq_update_eligible(struct qfq_sched *q)
65e7f7
 }
65e7f7
 
65e7f7
 /* Dequeue head packet of the head class in the DRR queue of the aggregate. */
65e7f7
-static void agg_dequeue(struct qfq_aggregate *agg,
65e7f7
-			struct qfq_class *cl, unsigned int len)
65e7f7
+static struct sk_buff *agg_dequeue(struct qfq_aggregate *agg,
65e7f7
+				   struct qfq_class *cl, unsigned int len)
65e7f7
 {
65e7f7
-	qdisc_dequeue_peeked(cl->qdisc);
65e7f7
+	struct sk_buff *skb = qdisc_dequeue_peeked(cl->qdisc);
65e7f7
+
65e7f7
+	if (!skb)
65e7f7
+		return NULL;
65e7f7
 
65e7f7
 	cl->deficit -= (int) len;
65e7f7
 
65e7f7
 	if (cl->qdisc->q.qlen == 0) /* no more packets, remove from list */
65e7f7
 		list_del(&cl->alist);
65e7f7
-	else if (cl->deficit < qdisc_pkt_len(cl->qdisc->ops->peek(cl->qdisc))) {
65e7f7
+	else if (cl->deficit < qdisc_pkt_len(klp_cve_2023_4921_peek(cl->qdisc))) {
65e7f7
 		cl->deficit += agg->lmax;
65e7f7
 		list_move_tail(&cl->alist, &agg->active);
65e7f7
 	}
65e7f7
+
65e7f7
+	return skb;
65e7f7
 }
65e7f7
 
65e7f7
 static inline struct sk_buff *qfq_peek_skb(struct qfq_aggregate *agg,
65e7f7
@@ -1006,10 +1013,16 @@ static inline struct sk_buff *qfq_peek_skb(struct qfq_aggregate *agg,
65e7f7
 	struct sk_buff *skb;
65e7f7
 
65e7f7
 	*cl = list_first_entry(&agg->active, struct qfq_class, alist);
65e7f7
-	skb = (*cl)->qdisc->ops->peek((*cl)->qdisc);
65e7f7
-	if (skb == NULL)
65e7f7
-		WARN_ONCE(1, "qfq_dequeue: non-workconserving leaf\n");
65e7f7
-	else
65e7f7
+	skb = klp_cve_2023_4921_peek((*cl)->qdisc);
65e7f7
+	if (skb == NULL) {
65e7f7
+		/*
65e7f7
+		 * kpatch-build workaround: keep old WARN_ONCE to avoid
65e7f7
+		 * create-diff-object unreconcilable difference from
65e7f7
+		 * unsupported .data.once section change.
65e7f7
+		 */
65e7f7
+		WARN_ONCE(!jiffies, "qfq_dequeue: non-workconserving leaf\n");
65e7f7
+		qdisc_warn_nonwc("qfq_dequeue", (*cl)->qdisc);
65e7f7
+	} else
65e7f7
 		*len = qdisc_pkt_len(skb);
65e7f7
 
65e7f7
 	return skb;
65e7f7
@@ -1142,11 +1155,18 @@ static struct sk_buff *qfq_dequeue(struct Qdisc *sch)
65e7f7
 	if (!skb)
65e7f7
 		return NULL;
65e7f7
 
65e7f7
-	qdisc_qstats_backlog_dec(sch, skb);
65e7f7
 	sch->q.qlen--;
65e7f7
+
65e7f7
+	skb = agg_dequeue(in_serv_agg, cl, len);
65e7f7
+
65e7f7
+	if (!skb) {
65e7f7
+		sch->q.qlen++;
65e7f7
+		return NULL;
65e7f7
+	}
65e7f7
+
65e7f7
+	qdisc_qstats_backlog_dec(sch, skb);
65e7f7
 	qdisc_bstats_update(sch, skb);
65e7f7
 
65e7f7
-	agg_dequeue(in_serv_agg, cl, len);
65e7f7
 	/* If lmax is lowered, through qfq_change_class, for a class
65e7f7
 	 * owning pending packets with larger size than the new value
65e7f7
 	 * of lmax, then the following condition may hold.
65e7f7
@@ -1224,6 +1244,7 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
65e7f7
 	}
65e7f7
 	pr_debug("qfq_enqueue: cl = %x\n", cl->common.classid);
65e7f7
 
65e7f7
+
65e7f7
 	if (unlikely(cl->agg->lmax < qdisc_pkt_len(skb))) {
65e7f7
 		pr_debug("qfq: increasing maxpkt from %u to %u for class %u",
65e7f7
 			 cl->agg->lmax, qdisc_pkt_len(skb), cl->common.classid);
65e7f7
@@ -1252,7 +1273,7 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
65e7f7
 	agg = cl->agg;
65e7f7
 	/* if the queue was not empty, then done here */
65e7f7
 	if (cl->qdisc->q.qlen != 1) {
65e7f7
-		if (unlikely(skb == cl->qdisc->ops->peek(cl->qdisc)) &&
65e7f7
+		if (unlikely(skb == klp_cve_2023_4921_peek(cl->qdisc)) &&
65e7f7
 		    list_first_entry(&agg->active, struct qfq_class, alist)
65e7f7
 		    == cl && cl->deficit < qdisc_pkt_len(skb))
65e7f7
 			list_move_tail(&cl->alist, &agg->active);
65e7f7
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
65e7f7
index e4789760457a..eea80e402219 100644
65e7f7
--- a/net/sched/sch_red.c
65e7f7
+++ b/net/sched/sch_red.c
65e7f7
@@ -22,6 +22,7 @@
65e7f7
 #include <net/pkt_cls.h>
65e7f7
 #include <net/inet_ecn.h>
65e7f7
 #include <net/red.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 
65e7f7
 /*	Parameters, settable by user:
65e7f7
@@ -135,7 +136,7 @@ static struct sk_buff *red_peek(struct Qdisc *sch)
65e7f7
 	struct red_sched_data *q = qdisc_priv(sch);
65e7f7
 	struct Qdisc *child = q->qdisc;
65e7f7
 
65e7f7
-	return child->ops->peek(child);
65e7f7
+	return klp_cve_2023_4921_peek(child);
65e7f7
 }
65e7f7
 
65e7f7
 static void red_reset(struct Qdisc *sch)
65e7f7
diff --git a/net/sched/sch_sfb.c b/net/sched/sch_sfb.c
65e7f7
index aeb509bde740..f8d75735351f 100644
65e7f7
--- a/net/sched/sch_sfb.c
65e7f7
+++ b/net/sched/sch_sfb.c
65e7f7
@@ -27,6 +27,7 @@
65e7f7
 #include <net/pkt_sched.h>
65e7f7
 #include <net/pkt_cls.h>
65e7f7
 #include <net/inet_ecn.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 /*
65e7f7
  * SFB uses two B[l][n] : L x N arrays of bins (L levels, N bins per level)
65e7f7
@@ -445,7 +446,7 @@ static struct sk_buff *sfb_peek(struct Qdisc *sch)
65e7f7
 	struct sfb_sched_data *q = qdisc_priv(sch);
65e7f7
 	struct Qdisc *child = q->qdisc;
65e7f7
 
65e7f7
-	return child->ops->peek(child);
65e7f7
+	return klp_cve_2023_4921_peek(child);
65e7f7
 }
65e7f7
 
65e7f7
 /* No sfb_drop -- impossible since the child doesn't return the dropped skb. */
65e7f7
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
65e7f7
index 15a19519aa9c..9957adc1b951 100644
65e7f7
--- a/net/sched/sch_tbf.c
65e7f7
+++ b/net/sched/sch_tbf.c
65e7f7
@@ -21,6 +21,7 @@
65e7f7
 #include <net/netlink.h>
65e7f7
 #include <net/sch_generic.h>
65e7f7
 #include <net/pkt_sched.h>
65e7f7
+#include "klp_cve_2023_4921.h"
65e7f7
 
65e7f7
 
65e7f7
 /*	Simple Token Bucket Filter.
65e7f7
@@ -214,7 +215,7 @@ static struct sk_buff *tbf_dequeue(struct Qdisc *sch)
65e7f7
 	struct tbf_sched_data *q = qdisc_priv(sch);
65e7f7
 	struct sk_buff *skb;
65e7f7
 
65e7f7
-	skb = q->qdisc->ops->peek(q->qdisc);
65e7f7
+	skb = klp_cve_2023_4921_peek(q->qdisc);
65e7f7
 
65e7f7
 	if (skb) {
65e7f7
 		s64 now;
65e7f7
-- 
65e7f7
2.44.0
65e7f7
65e7f7