Skip to content
Snippets Groups Projects
  1. Dec 14, 2024
    • Kuniyuki Iwashima's avatar
      tipc: Fix use-after-free of kernel socket in cleanup_bearer(). · 650ee9a2
      Kuniyuki Iwashima authored
      
      [ Upstream commit 6a2fa133 ]
      
      syzkaller reported a use-after-free of UDP kernel socket
      in cleanup_bearer() without repro. [0][1]
      
      When bearer_disable() calls tipc_udp_disable(), cleanup
      of the UDP kernel socket is deferred by work calling
      cleanup_bearer().
      
      tipc_net_stop() waits for such works to finish by checking
      tipc_net(net)->wq_count.  However, the work decrements the
      count too early before releasing the kernel socket,
      unblocking cleanup_net() and resulting in use-after-free.
      
      Let's move the decrement after releasing the socket in
      cleanup_bearer().
      
      [0]:
      ref_tracker: net notrefcnt@000000009b3d1faf has 1/1 users at
           sk_alloc+0x438/0x608
           inet_create+0x4c8/0xcb0
           __sock_create+0x350/0x6b8
           sock_create_kern+0x58/0x78
           udp_sock_create4+0x68/0x398
           udp_sock_create+0x88/0xc8
           tipc_udp_enable+0x5e8/0x848
           __tipc_nl_bearer_enable+0x84c/0xed8
           tipc_nl_bearer_enable+0x38/0x60
           genl_family_rcv_msg_doit+0x170/0x248
           genl_rcv_msg+0x400/0x5b0
           netlink_rcv_skb+0x1dc/0x398
           genl_rcv+0x44/0x68
           netlink_unicast+0x678/0x8b0
           netlink_sendmsg+0x5e4/0x898
           ____sys_sendmsg+0x500/0x830
      
      [1]:
      BUG: KMSAN: use-after-free in udp_hashslot include/net/udp.h:85 [inline]
      BUG: KMSAN: use-after-free in udp_lib_unhash+0x3b8/0x930 net/ipv4/udp.c:1979
       udp_hashslot include/net/udp.h:85 [inline]
       udp_lib_unhash+0x3b8/0x930 net/ipv4/udp.c:1979
       sk_common_release+0xaf/0x3f0 net/core/sock.c:3820
       inet_release+0x1e0/0x260 net/ipv4/af_inet.c:437
       inet6_release+0x6f/0xd0 net/ipv6/af_inet6.c:489
       __sock_release net/socket.c:658 [inline]
       sock_release+0xa0/0x210 net/socket.c:686
       cleanup_bearer+0x42d/0x4c0 net/tipc/udp_media.c:819
       process_one_work kernel/workqueue.c:3229 [inline]
       process_scheduled_works+0xcaf/0x1c90 kernel/workqueue.c:3310
       worker_thread+0xf6c/0x1510 kernel/workqueue.c:3391
       kthread+0x531/0x6b0 kernel/kthread.c:389
       ret_from_fork+0x60/0x80 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:244
      
      Uninit was created at:
       slab_free_hook mm/slub.c:2269 [inline]
       slab_free mm/slub.c:4580 [inline]
       kmem_cache_free+0x207/0xc40 mm/slub.c:4682
       net_free net/core/net_namespace.c:454 [inline]
       cleanup_net+0x16f2/0x19d0 net/core/net_namespace.c:647
       process_one_work kernel/workqueue.c:3229 [inline]
       process_scheduled_works+0xcaf/0x1c90 kernel/workqueue.c:3310
       worker_thread+0xf6c/0x1510 kernel/workqueue.c:3391
       kthread+0x531/0x6b0 kernel/kthread.c:389
       ret_from_fork+0x60/0x80 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:244
      
      CPU: 0 UID: 0 PID: 54 Comm: kworker/0:2 Not tainted 6.12.0-rc1-00131-gf66ebf37d69c #7 91723d6f74857f70725e1583cba3cf4adc716cfa
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014
      Workqueue: events cleanup_bearer
      
      Fixes: 26abe143 ("net: Modify sk_alloc to not reference count the netns of kernel sockets.")
      Reported-by: default avatarsyzkaller <syzkaller@googlegroups.com>
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Link: https://patch.msgid.link/20241127050512.28438-1-kuniyu@amazon.com
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      650ee9a2
    • Ivan Solodovnikov's avatar
      dccp: Fix memory leak in dccp_feat_change_recv · c99507ff
      Ivan Solodovnikov authored
      
      [ Upstream commit 22be4727 ]
      
      If dccp_feat_push_confirm() fails after new value for SP feature was accepted
      without reconciliation ('entry == NULL' branch), memory allocated for that value
      with dccp_feat_clone_sp_val() is never freed.
      
      Here is the kmemleak stack for this:
      
      unreferenced object 0xffff88801d4ab488 (size 8):
        comm "syz-executor310", pid 1127, jiffies 4295085598 (age 41.666s)
        hex dump (first 8 bytes):
          01 b4 4a 1d 80 88 ff ff                          ..J.....
        backtrace:
          [<00000000db7cabfe>] kmemdup+0x23/0x50 mm/util.c:128
          [<0000000019b38405>] kmemdup include/linux/string.h:465 [inline]
          [<0000000019b38405>] dccp_feat_clone_sp_val net/dccp/feat.c:371 [inline]
          [<0000000019b38405>] dccp_feat_clone_sp_val net/dccp/feat.c:367 [inline]
          [<0000000019b38405>] dccp_feat_change_recv net/dccp/feat.c:1145 [inline]
          [<0000000019b38405>] dccp_feat_parse_options+0x1196/0x2180 net/dccp/feat.c:1416
          [<00000000b1f6d94a>] dccp_parse_options+0xa2a/0x1260 net/dccp/options.c:125
          [<0000000030d7b621>] dccp_rcv_state_process+0x197/0x13d0 net/dccp/input.c:650
          [<000000001f74c72e>] dccp_v4_do_rcv+0xf9/0x1a0 net/dccp/ipv4.c:688
          [<00000000a6c24128>] sk_backlog_rcv include/net/sock.h:1041 [inline]
          [<00000000a6c24128>] __release_sock+0x139/0x3b0 net/core/sock.c:2570
          [<00000000cf1f3a53>] release_sock+0x54/0x1b0 net/core/sock.c:3111
          [<000000008422fa23>] inet_wait_for_connect net/ipv4/af_inet.c:603 [inline]
          [<000000008422fa23>] __inet_stream_connect+0x5d0/0xf70 net/ipv4/af_inet.c:696
          [<0000000015b6f64d>] inet_stream_connect+0x53/0xa0 net/ipv4/af_inet.c:735
          [<0000000010122488>] __sys_connect_file+0x15c/0x1a0 net/socket.c:1865
          [<00000000b4b70023>] __sys_connect+0x165/0x1a0 net/socket.c:1882
          [<00000000f4cb3815>] __do_sys_connect net/socket.c:1892 [inline]
          [<00000000f4cb3815>] __se_sys_connect net/socket.c:1889 [inline]
          [<00000000f4cb3815>] __x64_sys_connect+0x6e/0xb0 net/socket.c:1889
          [<00000000e7b1e839>] do_syscall_64+0x33/0x40 arch/x86/entry/common.c:46
          [<0000000055e91434>] entry_SYSCALL_64_after_hwframe+0x67/0xd1
      
      Clean up the allocated memory in case of dccp_feat_push_confirm() failure
      and bail out with an error reset code.
      
      Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
      
      Fixes: e77b8363 ("dccp: Process incoming Change feature-negotiation options")
      Signed-off-by: default avatarIvan Solodovnikov <solodovnikov.ia@phystech.edu>
      Link: https://patch.msgid.link/20241126143902.190853-1-solodovnikov.ia@phystech.edu
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c99507ff
    • Jiri Wiesner's avatar
      net/ipv6: release expired exception dst cached in socket · b90d0613
      Jiri Wiesner authored
      [ Upstream commit 3301ab7d ]
      
      Dst objects get leaked in ip6_negative_advice() when this function is
      executed for an expired IPv6 route located in the exception table. There
      are several conditions that must be fulfilled for the leak to occur:
      * an ICMPv6 packet indicating a change of the MTU for the path is received,
        resulting in an exception dst being created
      * a TCP connection that uses the exception dst for routing packets must
        start timing out so that TCP begins retransmissions
      * after the exception dst expires, the FIB6 garbage collector must not run
        before TCP executes ip6_negative_advice() for the expired exception dst
      
      When TCP executes ip6_negative_advice() for an exception dst that has
      expired and if no other socket holds a reference to the exception dst, the
      refcount of the exception dst is 2, which corresponds to the increment
      made by dst_init() and the increment made by the TCP socket for which the
      connection is timing out. The refcount made by the socket is never
      released. The refcount of the dst is decremented in sk_dst_reset() but
      that decrement is counteracted by a dst_hold() intentionally placed just
      before the sk_dst_reset() in ip6_negative_advice(). After
      ip6_negative_advice() has finished, there is no other object tied to the
      dst. The socket lost its reference stored in sk_dst_cache and the dst is
      no longer in the exception table. The exception dst becomes a leaked
      object.
      
      As a result of this dst leak, an unbalanced refcount is reported for the
      loopback device of a net namespace being destroyed under kernels that do
      not contain e5f80fcf ("ipv6: give an IPv6 dev to blackhole_netdev"):
      unregister_netdevice: waiting for lo to become free. Usage count = 2
      
      Fix the dst leak by removing the dst_hold() in ip6_negative_advice(). The
      patch that introduced the dst_hold() in ip6_negative_advice() was
      92f1655a ("net: fix __dst_negative_advice() race"). But 92f1655a
      merely refactored the code with regards to the dst refcount so the issue
      was present even before 92f1655a. The bug was introduced in
      54c1a859 ("ipv6: Don't drop cache route entry unless timer actually
      expired.") where the expired cached route is deleted and the sk_dst_cache
      member of the socket is set to NULL by calling dst_negative_advice() but
      the refcount belonging to the socket is left unbalanced.
      
      The IPv4 version - ipv4_negative_advice() - is not affected by this bug.
      When the TCP connection times out ipv4_negative_advice() merely resets the
      sk_dst_cache of the socket while decrementing the refcount of the
      exception dst.
      
      Fixes: 92f1655a ("net: fix __dst_negative_advice() race")
      Fixes: 54c1a859 ("ipv6: Don't drop cache route entry unless timer actually expired.")
      Link: https://lore.kernel.org/netdev/20241113105611.GA6723@incl/T/#u
      
      
      Signed-off-by: default avatarJiri Wiesner <jwiesner@suse.de>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://patch.msgid.link/20241128085950.GA4505@incl
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b90d0613
    • Dmitry Antipov's avatar
      can: j1939: j1939_session_new(): fix skb reference counting · b3282c2b
      Dmitry Antipov authored
      
      [ Upstream commit a8c69500 ]
      
      Since j1939_session_skb_queue() does an extra skb_get() for each new
      skb, do the same for the initial one in j1939_session_new() to avoid
      refcount underflow.
      
      Reported-by: default avatar <syzbot+d4e8dc385d9258220c31@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=d4e8dc385d9258220c31
      
      
      Fixes: 9d71dd0c ("can: add support of SAE J1939 protocol")
      Signed-off-by: default avatarDmitry Antipov <dmantipov@yandex.ru>
      Tested-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
      Acked-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
      Link: https://patch.msgid.link/20241105094823.2403806-1-dmantipov@yandex.ru
      
      
      [mkl: clean up commit message]
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b3282c2b
    • Eric Dumazet's avatar
      net: hsr: avoid potential out-of-bound access in fill_frame_info() · aa632691
      Eric Dumazet authored
      
      [ Upstream commit b9653d19 ]
      
      syzbot is able to feed a packet with 14 bytes, pretending
      it is a vlan one.
      
      Since fill_frame_info() is relying on skb->mac_len already,
      extend the check to cover this case.
      
      BUG: KMSAN: uninit-value in fill_frame_info net/hsr/hsr_forward.c:709 [inline]
       BUG: KMSAN: uninit-value in hsr_forward_skb+0x9ee/0x3b10 net/hsr/hsr_forward.c:724
        fill_frame_info net/hsr/hsr_forward.c:709 [inline]
        hsr_forward_skb+0x9ee/0x3b10 net/hsr/hsr_forward.c:724
        hsr_dev_xmit+0x2f0/0x350 net/hsr/hsr_device.c:235
        __netdev_start_xmit include/linux/netdevice.h:5002 [inline]
        netdev_start_xmit include/linux/netdevice.h:5011 [inline]
        xmit_one net/core/dev.c:3590 [inline]
        dev_hard_start_xmit+0x247/0xa20 net/core/dev.c:3606
        __dev_queue_xmit+0x366a/0x57d0 net/core/dev.c:4434
        dev_queue_xmit include/linux/netdevice.h:3168 [inline]
        packet_xmit+0x9c/0x6c0 net/packet/af_packet.c:276
        packet_snd net/packet/af_packet.c:3146 [inline]
        packet_sendmsg+0x91ae/0xa6f0 net/packet/af_packet.c:3178
        sock_sendmsg_nosec net/socket.c:711 [inline]
        __sock_sendmsg+0x30f/0x380 net/socket.c:726
        __sys_sendto+0x594/0x750 net/socket.c:2197
        __do_sys_sendto net/socket.c:2204 [inline]
        __se_sys_sendto net/socket.c:2200 [inline]
        __x64_sys_sendto+0x125/0x1d0 net/socket.c:2200
        x64_sys_call+0x346a/0x3c30 arch/x86/include/generated/asm/syscalls_64.h:45
        do_syscall_x64 arch/x86/entry/common.c:52 [inline]
        do_syscall_64+0xcd/0x1e0 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f
      
      Uninit was created at:
        slab_post_alloc_hook mm/slub.c:4091 [inline]
        slab_alloc_node mm/slub.c:4134 [inline]
        kmem_cache_alloc_node_noprof+0x6bf/0xb80 mm/slub.c:4186
        kmalloc_reserve+0x13d/0x4a0 net/core/skbuff.c:587
        __alloc_skb+0x363/0x7b0 net/core/skbuff.c:678
        alloc_skb include/linux/skbuff.h:1323 [inline]
        alloc_skb_with_frags+0xc8/0xd00 net/core/skbuff.c:6612
        sock_alloc_send_pskb+0xa81/0xbf0 net/core/sock.c:2881
        packet_alloc_skb net/packet/af_packet.c:2995 [inline]
        packet_snd net/packet/af_packet.c:3089 [inline]
        packet_sendmsg+0x74c6/0xa6f0 net/packet/af_packet.c:3178
        sock_sendmsg_nosec net/socket.c:711 [inline]
        __sock_sendmsg+0x30f/0x380 net/socket.c:726
        __sys_sendto+0x594/0x750 net/socket.c:2197
        __do_sys_sendto net/socket.c:2204 [inline]
        __se_sys_sendto net/socket.c:2200 [inline]
        __x64_sys_sendto+0x125/0x1d0 net/socket.c:2200
        x64_sys_call+0x346a/0x3c30 arch/x86/include/generated/asm/syscalls_64.h:45
        do_syscall_x64 arch/x86/entry/common.c:52 [inline]
        do_syscall_64+0xcd/0x1e0 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f
      
      Fixes: 48b491a5 ("net: hsr: fix mac_len checks")
      Reported-by: default avatar <syzbot+671e2853f9851d039551@syzkaller.appspotmail.com>
      Closes: https://lore.kernel.org/netdev/6745dc7f.050a0220.21d33d.0018.GAE@google.com/T/#u
      
      
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Cc: WingMan Kwok <w-kwok2@ti.com>
      Cc: Murali Karicheri <m-karicheri2@ti.com>
      Cc: MD Danish Anwar <danishanwar@ti.com>
      Cc: Jiri Pirko <jiri@nvidia.com>
      Cc: George McCollister <george.mccollister@gmail.com>
      Link: https://patch.msgid.link/20241126144344.4177332-1-edumazet@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      aa632691
    • Martin Ottens's avatar
      net/sched: tbf: correct backlog statistic for GSO packets · f9653b00
      Martin Ottens authored
      
      [ Upstream commit 1596a135 ]
      
      When the length of a GSO packet in the tbf qdisc is larger than the burst
      size configured the packet will be segmented by the tbf_segment function.
      Whenever this function is used to enqueue SKBs, the backlog statistic of
      the tbf is not increased correctly. This can lead to underflows of the
      'backlog' byte-statistic value when these packets are dequeued from tbf.
      
      Reproduce the bug:
      Ensure that the sender machine has GSO enabled. Configured the tbf on
      the outgoing interface of the machine as follows (burstsize = 1 MTU):
      $ tc qdisc add dev <oif> root handle 1: tbf rate 50Mbit burst 1514 latency 50ms
      
      Send bulk TCP traffic out via this interface, e.g., by running an iPerf3
      client on this machine. Check the qdisc statistics:
      $ tc -s qdisc show dev <oif>
      
      The 'backlog' byte-statistic has incorrect values while traffic is
      transferred, e.g., high values due to u32 underflows. When the transfer
      is stopped, the value is != 0, which should never happen.
      
      This patch fixes this bug by updating the statistics correctly, even if
      single SKBs of a GSO SKB cannot be enqueued.
      
      Fixes: e43ac79a ("sch_tbf: segment too big GSO packets")
      Signed-off-by: default avatarMartin Ottens <martin.ottens@fau.de>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://patch.msgid.link/20241125174608.1484356-1-martin.ottens@fau.de
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f9653b00
    • Ajay Kaher's avatar
      ptp: Add error handling for adjfine callback in ptp_clock_adjtime · 7f5eda0e
      Ajay Kaher authored
      
      [ Upstream commit 98337d7c ]
      
      ptp_clock_adjtime sets ptp->dialed_frequency even when adjfine
      callback returns an error. This causes subsequent reads to return
      an incorrect value.
      
      Fix this by adding error check before ptp->dialed_frequency is set.
      
      Fixes: 39a8cbd9 ("ptp: remember the adjusted frequency")
      Signed-off-by: default avatarAjay Kaher <ajay.kaher@broadcom.com>
      Acked-by: default avatarRichard Cochran <richardcochran@gmail.com>
      Link: https://patch.msgid.link/20241125105954.1509971-1-ajay.kaher@broadcom.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7f5eda0e
    • Dmitry Antipov's avatar
      netfilter: x_tables: fix LED ID check in led_tg_check() · ad28612e
      Dmitry Antipov authored
      
      [ Upstream commit 04317f4e ]
      
      Syzbot has reported the following BUG detected by KASAN:
      
      BUG: KASAN: slab-out-of-bounds in strlen+0x58/0x70
      Read of size 1 at addr ffff8881022da0c8 by task repro/5879
      ...
      Call Trace:
       <TASK>
       dump_stack_lvl+0x241/0x360
       ? __pfx_dump_stack_lvl+0x10/0x10
       ? __pfx__printk+0x10/0x10
       ? _printk+0xd5/0x120
       ? __virt_addr_valid+0x183/0x530
       ? __virt_addr_valid+0x183/0x530
       print_report+0x169/0x550
       ? __virt_addr_valid+0x183/0x530
       ? __virt_addr_valid+0x183/0x530
       ? __virt_addr_valid+0x45f/0x530
       ? __phys_addr+0xba/0x170
       ? strlen+0x58/0x70
       kasan_report+0x143/0x180
       ? strlen+0x58/0x70
       strlen+0x58/0x70
       kstrdup+0x20/0x80
       led_tg_check+0x18b/0x3c0
       xt_check_target+0x3bb/0xa40
       ? __pfx_xt_check_target+0x10/0x10
       ? stack_depot_save_flags+0x6e4/0x830
       ? nft_target_init+0x174/0xc30
       nft_target_init+0x82d/0xc30
       ? __pfx_nft_target_init+0x10/0x10
       ? nf_tables_newrule+0x1609/0x2980
       ? nf_tables_newrule+0x1609/0x2980
       ? rcu_is_watching+0x15/0xb0
       ? nf_tables_newrule+0x1609/0x2980
       ? nf_tables_newrule+0x1609/0x2980
       ? __kmalloc_noprof+0x21a/0x400
       nf_tables_newrule+0x1860/0x2980
       ? __pfx_nf_tables_newrule+0x10/0x10
       ? __nla_parse+0x40/0x60
       nfnetlink_rcv+0x14e5/0x2ab0
       ? __pfx_validate_chain+0x10/0x10
       ? __pfx_nfnetlink_rcv+0x10/0x10
       ? __lock_acquire+0x1384/0x2050
       ? netlink_deliver_tap+0x2e/0x1b0
       ? __pfx_lock_release+0x10/0x10
       ? netlink_deliver_tap+0x2e/0x1b0
       netlink_unicast+0x7f8/0x990
       ? __pfx_netlink_unicast+0x10/0x10
       ? __virt_addr_valid+0x183/0x530
       ? __check_object_size+0x48e/0x900
       netlink_sendmsg+0x8e4/0xcb0
       ? __pfx_netlink_sendmsg+0x10/0x10
       ? aa_sock_msg_perm+0x91/0x160
       ? __pfx_netlink_sendmsg+0x10/0x10
       __sock_sendmsg+0x223/0x270
       ____sys_sendmsg+0x52a/0x7e0
       ? __pfx_____sys_sendmsg+0x10/0x10
       __sys_sendmsg+0x292/0x380
       ? __pfx___sys_sendmsg+0x10/0x10
       ? lockdep_hardirqs_on_prepare+0x43d/0x780
       ? __pfx_lockdep_hardirqs_on_prepare+0x10/0x10
       ? exc_page_fault+0x590/0x8c0
       ? do_syscall_64+0xb6/0x230
       do_syscall_64+0xf3/0x230
       entry_SYSCALL_64_after_hwframe+0x77/0x7f
      ...
       </TASK>
      
      Since an invalid (without '\0' byte at all) byte sequence may be passed
      from userspace, add an extra check to ensure that such a sequence is
      rejected as possible ID and so never passed to 'kstrdup()' and further.
      
      Reported-by: default avatar <syzbot+6c8215822f35fdb35667@syzkaller.appspotmail.com>
      Closes: https://syzkaller.appspot.com/bug?extid=6c8215822f35fdb35667
      
      
      Fixes: 268cb38e ("netfilter: x_tables: add LED trigger target")
      Signed-off-by: default avatarDmitry Antipov <dmantipov@yandex.ru>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ad28612e
    • Jinghao Jia's avatar
      ipvs: fix UB due to uninitialized stack access in ip_vs_protocol_init() · 0b2cbed8
      Jinghao Jia authored
      
      [ Upstream commit 146b6f11 ]
      
      Under certain kernel configurations when building with Clang/LLVM, the
      compiler does not generate a return or jump as the terminator
      instruction for ip_vs_protocol_init(), triggering the following objtool
      warning during build time:
      
        vmlinux.o: warning: objtool: ip_vs_protocol_init() falls through to next function __initstub__kmod_ip_vs_rr__935_123_ip_vs_rr_init6()
      
      At runtime, this either causes an oops when trying to load the ipvs
      module or a boot-time panic if ipvs is built-in. This same issue has
      been reported by the Intel kernel test robot previously.
      
      Digging deeper into both LLVM and the kernel code reveals this to be a
      undefined behavior problem. ip_vs_protocol_init() uses a on-stack buffer
      of 64 chars to store the registered protocol names and leaves it
      uninitialized after definition. The function calls strnlen() when
      concatenating protocol names into the buffer. With CONFIG_FORTIFY_SOURCE
      strnlen() performs an extra step to check whether the last byte of the
      input char buffer is a null character (commit 3009f891 ("fortify:
      Allow strlen() and strnlen() to pass compile-time known lengths")).
      This, together with possibly other configurations, cause the following
      IR to be generated:
      
        define hidden i32 @ip_vs_protocol_init() local_unnamed_addr #5 section ".init.text" align 16 !kcfi_type !29 {
          %1 = alloca [64 x i8], align 16
          ...
      
        14:                                               ; preds = %11
          %15 = getelementptr inbounds i8, ptr %1, i64 63
          %16 = load i8, ptr %15, align 1
          %17 = tail call i1 @llvm.is.constant.i8(i8 %16)
          %18 = icmp eq i8 %16, 0
          %19 = select i1 %17, i1 %18, i1 false
          br i1 %19, label %20, label %23
      
        20:                                               ; preds = %14
          %21 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #23
          ...
      
        23:                                               ; preds = %14, %11, %20
          %24 = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64) #24
          ...
        }
      
      The above code calculates the address of the last char in the buffer
      (value %15) and then loads from it (value %16). Because the buffer is
      never initialized, the LLVM GVN pass marks value %16 as undefined:
      
        %13 = getelementptr inbounds i8, ptr %1, i64 63
        br i1 undef, label %14, label %17
      
      This gives later passes (SCCP, in particular) more DCE opportunities by
      propagating the undef value further, and eventually removes everything
      after the load on the uninitialized stack location:
      
        define hidden i32 @ip_vs_protocol_init() local_unnamed_addr #0 section ".init.text" align 16 !kcfi_type !11 {
          %1 = alloca [64 x i8], align 16
          ...
      
        12:                                               ; preds = %11
          %13 = getelementptr inbounds i8, ptr %1, i64 63
          unreachable
        }
      
      In this way, the generated native code will just fall through to the
      next function, as LLVM does not generate any code for the unreachable IR
      instruction and leaves the function without a terminator.
      
      Zero the on-stack buffer to avoid this possible UB.
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Closes: https://lore.kernel.org/oe-kbuild-all/202402100205.PWXIz1ZK-lkp@intel.com/
      
      
      Co-developed-by: default avatarRuowen Qin <ruqin@redhat.com>
      Signed-off-by: default avatarRuowen Qin <ruqin@redhat.com>
      Signed-off-by: default avatarJinghao Jia <jinghao7@illinois.edu>
      Acked-by: default avatarJulian Anastasov <ja@ssi.bg>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0b2cbed8
    • Dario Binacchi's avatar
      can: sun4i_can: sun4i_can_err(): fix {rx,tx}_errors statistics · 273cab97
      Dario Binacchi authored
      
      [ Upstream commit 595a8198 ]
      
      The sun4i_can_err() function only incremented the receive error counter
      and never the transmit error counter, even if the STA_ERR_DIR flag
      reported that an error had occurred during transmission.
      
      Increment the receive/transmit error counter based on the value of the
      STA_ERR_DIR flag.
      
      Fixes: 0738eff1 ("can: Allwinner A10/A20 CAN Controller support - Kernel module")
      Signed-off-by: default avatarDario Binacchi <dario.binacchi@amarulasolutions.com>
      Link: https://patch.msgid.link/20241122221650.633981-11-dario.binacchi@amarulasolutions.com
      
      
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      273cab97
    • Dario Binacchi's avatar
      can: sun4i_can: sun4i_can_err(): call can_change_state() even if cf is NULL · 265f8341
      Dario Binacchi authored
      
      [ Upstream commit ee6bf367 ]
      
      Call the function can_change_state() if the allocation of the skb
      fails, as it handles the cf parameter when it is null.
      
      Additionally, this ensures that the statistics related to state error
      counters (i. e. warning, passive, and bus-off) are updated.
      
      Fixes: 0738eff1 ("can: Allwinner A10/A20 CAN Controller support - Kernel module")
      Signed-off-by: default avatarDario Binacchi <dario.binacchi@amarulasolutions.com>
      Link: https://patch.msgid.link/20241122221650.633981-3-dario.binacchi@amarulasolutions.com
      
      
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      265f8341
    • Yassine Oudjana's avatar
      watchdog: mediatek: Make sure system reset gets asserted in mtk_wdt_restart() · 601ec000
      Yassine Oudjana authored
      
      [ Upstream commit a1495a21 ]
      
      Clear the IRQ enable bit of WDT_MODE before asserting software reset
      in order to make TOPRGU issue a system reset signal instead of an IRQ.
      
      Fixes: a44a4553 ("watchdog: Add driver for Mediatek watchdog")
      Signed-off-by: default avatarYassine Oudjana <y.oudjana@protonmail.com>
      Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Link: https://lore.kernel.org/r/20241106104738.195968-2-y.oudjana@protonmail.com
      
      
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarWim Van Sebroeck <wim@linux-watchdog.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      601ec000
    • Oleksandr Ocheretnyi's avatar
      iTCO_wdt: mask NMI_NOW bit for update_no_reboot_bit() call · 05bed96e
      Oleksandr Ocheretnyi authored
      
      [ Upstream commit daa814d7 ]
      
      Commit da23b6fa ("watchdog: iTCO: Add support for Cannon Lake
      PCH iTCO") does not mask NMI_NOW bit during TCO1_CNT register's
      value comparison for update_no_reboot_bit() call causing following
      failure:
      
         ...
         iTCO_vendor_support: vendor-support=0
         iTCO_wdt iTCO_wdt: unable to reset NO_REBOOT flag, device
                                          disabled by hardware/BIOS
         ...
      
      and this can lead to unexpected NMIs later during regular
      crashkernel's workflow because of watchdog probe call failures.
      
      This change masks NMI_NOW bit for TCO1_CNT register values to
      avoid unexpected NMI_NOW bit inversions.
      
      Fixes: da23b6fa ("watchdog: iTCO: Add support for Cannon Lake PCH iTCO")
      Signed-off-by: default avatarOleksandr Ocheretnyi <oocheret@cisco.com>
      Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Reviewed-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
      Link: https://lore.kernel.org/r/20240913191403.2560805-1-oocheret@cisco.com
      
      
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarWim Van Sebroeck <wim@linux-watchdog.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      05bed96e
    • Lucas Stach's avatar
      drm/etnaviv: flush shader L1 cache after user commandstream · 4715e23b
      Lucas Stach authored
      
      commit 4f8dbade upstream.
      
      The shader L1 cache is a writeback cache for shader loads/stores
      and thus must be flushed before any BOs backing the shader buffers
      are potentially freed.
      
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarChristian Gmeiner <cgmeiner@igalia.com>
      Signed-off-by: default avatarLucas Stach <l.stach@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4715e23b
    • Josef Bacik's avatar
      btrfs: don't BUG_ON on ENOMEM from btrfs_lookup_extent_info() in walk_down_proc() · c1406d83
      Josef Bacik authored
      
      commit a580fb2c upstream.
      
      We handle errors here properly, ENOMEM isn't fatal, return the error.
      
      Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      Signed-off-by: default avatarKeerthana K <keerthana.kalyanasundaram@broadcom.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c1406d83
    • Yang Erkun's avatar
      nfsd: fix nfs4_openowner leak when concurrent nfsd4_open occur · 2d505a80
      Yang Erkun authored
      
      commit 98100e88 upstream.
      
      The action force umount(umount -f) will attempt to kill all rpc_task even
      umount operation may ultimately fail if some files remain open.
      Consequently, if an action attempts to open a file, it can potentially
      send two rpc_task to nfs server.
      
                         NFS CLIENT
      thread1                             thread2
      open("file")
      ...
      nfs4_do_open
       _nfs4_do_open
        _nfs4_open_and_get_state
         _nfs4_proc_open
          nfs4_run_open_task
           /* rpc_task1 */
           rpc_run_task
           rpc_wait_for_completion_task
      
                                          umount -f
                                          nfs_umount_begin
                                           rpc_killall_tasks
                                            rpc_signal_task
           rpc_task1 been wakeup
           and return -512
       _nfs4_do_open // while loop
          ...
          nfs4_run_open_task
           /* rpc_task2 */
           rpc_run_task
           rpc_wait_for_completion_task
      
      While processing an open request, nfsd will first attempt to find or
      allocate an nfs4_openowner. If it finds an nfs4_openowner that is not
      marked as NFS4_OO_CONFIRMED, this nfs4_openowner will released. Since
      two rpc_task can attempt to open the same file simultaneously from the
      client to server, and because two instances of nfsd can run
      concurrently, this situation can lead to lots of memory leak.
      Additionally, when we echo 0 to /proc/fs/nfsd/threads, warning will be
      triggered.
      
                          NFS SERVER
      nfsd1                  nfsd2       echo 0 > /proc/fs/nfsd/threads
      
      nfsd4_open
       nfsd4_process_open1
        find_or_alloc_open_stateowner
         // alloc oo1, stateid1
                             nfsd4_open
                              nfsd4_process_open1
                              find_or_alloc_open_stateowner
                              // find oo1, without NFS4_OO_CONFIRMED
                               release_openowner
                                unhash_openowner_locked
                                list_del_init(&oo->oo_perclient)
                                // cannot find this oo
                                // from client, LEAK!!!
                               alloc_stateowner // alloc oo2
      
       nfsd4_process_open2
        init_open_stateid
        // associate oo1
        // with stateid1, stateid1 LEAK!!!
        nfs4_get_vfs_file
        // alloc nfsd_file1 and nfsd_file_mark1
        // all LEAK!!!
      
                               nfsd4_process_open2
                               ...
      
                                          write_threads
                                           ...
                                           nfsd_destroy_serv
                                            nfsd_shutdown_net
                                             nfs4_state_shutdown_net
                                              nfs4_state_destroy_net
                                               destroy_client
                                                __destroy_client
                                                // won't find oo1!!!
                                           nfsd_shutdown_generic
                                            nfsd_file_cache_shutdown
                                             kmem_cache_destroy
                                             for nfsd_file_slab
                                             and nfsd_file_mark_slab
                                             // bark since nfsd_file1
                                             // and nfsd_file_mark1
                                             // still alive
      
      =======================================================================
      BUG nfsd_file (Not tainted): Objects remaining in nfsd_file on
      __kmem_cache_shutdown()
      -----------------------------------------------------------------------
      
      Slab 0xffd4000004438a80 objects=34 used=1 fp=0xff11000110e2ad28
      flags=0x17ffffc0000240(workingset|head|node=0|zone=2|lastcpupid=0x1fffff)
      CPU: 4 UID: 0 PID: 757 Comm: sh Not tainted 6.12.0-rc6+ #19
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
      1.16.1-2.fc37 04/01/2014
      Call Trace:
       <TASK>
       dump_stack_lvl+0x53/0x70
       slab_err+0xb0/0xf0
       __kmem_cache_shutdown+0x15c/0x310
       kmem_cache_destroy+0x66/0x160
       nfsd_file_cache_shutdown+0xac/0x210 [nfsd]
       nfsd_destroy_serv+0x251/0x2a0 [nfsd]
       nfsd_svc+0x125/0x1e0 [nfsd]
       write_threads+0x16a/0x2a0 [nfsd]
       nfsctl_transaction_write+0x74/0xa0 [nfsd]
       vfs_write+0x1ae/0x6d0
       ksys_write+0xc1/0x160
       do_syscall_64+0x5f/0x170
       entry_SYSCALL_64_after_hwframe+0x76/0x7e
      
      Disabling lock debugging due to kernel taint
      Object 0xff11000110e2ac38 @offset=3128
      Allocated in nfsd_file_do_acquire+0x20f/0xa30 [nfsd] age=1635 cpu=3
      pid=800
       nfsd_file_do_acquire+0x20f/0xa30 [nfsd]
       nfsd_file_acquire_opened+0x5f/0x90 [nfsd]
       nfs4_get_vfs_file+0x4c9/0x570 [nfsd]
       nfsd4_process_open2+0x713/0x1070 [nfsd]
       nfsd4_open+0x74b/0x8b0 [nfsd]
       nfsd4_proc_compound+0x70b/0xc20 [nfsd]
       nfsd_dispatch+0x1b4/0x3a0 [nfsd]
       svc_process_common+0x5b8/0xc50 [sunrpc]
       svc_process+0x2ab/0x3b0 [sunrpc]
       svc_handle_xprt+0x681/0xa20 [sunrpc]
       nfsd+0x183/0x220 [nfsd]
       kthread+0x199/0x1e0
       ret_from_fork+0x31/0x60
       ret_from_fork_asm+0x1a/0x30
      
      Add nfs4_openowner_unhashed to help found unhashed nfs4_openowner, and
      break nfsd4_open process to fix this problem.
      
      Cc: stable@vger.kernel.org # v5.4+
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarYang Erkun <yangerkun@huawei.com>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2d505a80
    • Yang Erkun's avatar
      nfsd: make sure exp active before svc_export_show · 7fd29d28
      Yang Erkun authored
      
      commit be8f982c upstream.
      
      The function `e_show` was called with protection from RCU. This only
      ensures that `exp` will not be freed. Therefore, the reference count for
      `exp` can drop to zero, which will trigger a refcount use-after-free
      warning when `exp_get` is called. To resolve this issue, use
      `cache_get_rcu` to ensure that `exp` remains active.
      
      ------------[ cut here ]------------
      refcount_t: addition on 0; use-after-free.
      WARNING: CPU: 3 PID: 819 at lib/refcount.c:25
      refcount_warn_saturate+0xb1/0x120
      CPU: 3 UID: 0 PID: 819 Comm: cat Not tainted 6.12.0-rc3+ #1
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
      1.16.1-2.fc37 04/01/2014
      RIP: 0010:refcount_warn_saturate+0xb1/0x120
      ...
      Call Trace:
       <TASK>
       e_show+0x20b/0x230 [nfsd]
       seq_read_iter+0x589/0x770
       seq_read+0x1e5/0x270
       vfs_read+0x125/0x530
       ksys_read+0xc1/0x160
       do_syscall_64+0x5f/0x170
       entry_SYSCALL_64_after_hwframe+0x76/0x7e
      
      Fixes: bf18f163 ("NFSD: Using exp_get for export getting")
      Cc: stable@vger.kernel.org # 4.20+
      Signed-off-by: default avatarYang Erkun <yangerkun@huawei.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7fd29d28
    • Yuan Can's avatar
      dm thin: Add missing destroy_work_on_stack() · 1f53e840
      Yuan Can authored
      
      commit e74fa244 upstream.
      
      This commit add missed destroy_work_on_stack() operations for pw->worker in
      pool_work_wait().
      
      Fixes: e7a3e871 ("dm thin: cleanup noflush_work to use a proper completion")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarYuan Can <yuancan@huawei.com>
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1f53e840
    • Kishon Vijay Abraham I's avatar
      PCI: keystone: Add link up check to ks_pcie_other_map_bus() · c6ac663c
      Kishon Vijay Abraham I authored
      commit 9e9ec8d8 upstream.
      
      K2G forwards the error triggered by a link-down state (e.g., no connected
      endpoint device) on the system bus for PCI configuration transactions;
      these errors are reported as an SError at system level, which is fatal and
      hangs the system.
      
      So, apply fix similar to how it was done in the DesignWare Core driver
      commit 15b23906 ("PCI: dwc: Add link up check in dw_child_pcie_ops.map_bus()").
      
      Fixes: 10a797c6 ("PCI: dwc: keystone: Use pci_ops for config space accessors")
      Link: https://lore.kernel.org/r/20240524105714.191642-3-s-vadapalli@ti.com
      
      
      Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
      Signed-off-by: default avatarSiddharth Vadapalli <s-vadapalli@ti.com>
      [kwilczynski: commit log, added tag for stable releases]
      Signed-off-by: default avatarKrzysztof Wilczyński <kwilczynski@kernel.org>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c6ac663c
    • Frank Li's avatar
      i3c: master: Fix miss free init_dyn_addr at i3c_master_put_i3c_addrs() · 093ecc6d
      Frank Li authored
      
      commit 30829905 upstream.
      
      if (dev->boardinfo && dev->boardinfo->init_dyn_addr)
                                            ^^^ here check "init_dyn_addr"
      	i3c_bus_set_addr_slot_status(&master->bus, dev->info.dyn_addr, ...)
      						             ^^^^
      							free "dyn_addr"
      Fix copy/paste error "dyn_addr" by replacing it with "init_dyn_addr".
      
      Cc: stable@kernel.org
      Fixes: 3a379bbc ("i3c: Add core I3C infrastructure")
      Reviewed-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Signed-off-by: default avatarFrank Li <Frank.Li@nxp.com>
      Link: https://lore.kernel.org/r/20241001162608.224039-1-Frank.Li@nxp.com
      
      
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      093ecc6d
    • Peter Griffin's avatar
      scsi: ufs: exynos: Fix hibern8 notify callbacks · aa10c746
      Peter Griffin authored
      commit ceef938b upstream.
      
      v1 of the patch which introduced the ufshcd_vops_hibern8_notify()
      callback used a bool instead of an enum. In v2 this was updated to an
      enum based on the review feedback in [1].
      
      ufs-exynos hibernate calls have always been broken upstream as it
      follows the v1 bool implementation.
      
      Link: https://patchwork.kernel.org/project/linux-scsi/patch/001f01d23994$719997c0$54ccc740$@samsung.com/
      
       [1]
      Fixes: 55f4b1f7 ("scsi: ufs: ufs-exynos: Add UFS host support for Exynos SoCs")
      Signed-off-by: default avatarPeter Griffin <peter.griffin@linaro.org>
      Link: https://lore.kernel.org/r/20241031150033.3440894-13-peter.griffin@linaro.org
      
      
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarTudor Ambarus <tudor.ambarus@linaro.org>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aa10c746
    • Alexandru Ardelean's avatar
      util_macros.h: fix/rework find_closest() macros · a1f2aff0
      Alexandru Ardelean authored
      commit bc73b418 upstream.
      
      A bug was found in the find_closest() (find_closest_descending() is also
      affected after some testing), where for certain values with small
      progressions, the rounding (done by averaging 2 values) causes an
      incorrect index to be returned.  The rounding issues occur for
      progressions of 1, 2 and 3.  It goes away when the progression/interval
      between two values is 4 or larger.
      
      It's particularly bad for progressions of 1.  For example if there's an
      array of 'a = { 1, 2, 3 }', using 'find_closest(2, a ...)' would return 0
      (the index of '1'), rather than returning 1 (the index of '2').  This
      means that for exact values (with a progression of 1), find_closest() will
      misbehave and return the index of the value smaller than the one we're
      searching for.
      
      For progressions of 2 and 3, the exact values are obtained correctly; but
      values aren't approximated correctly (as one would expect).  Starting with
      progressions of 4, all seems to be good (one gets what one would expect).
      
      While one could argue that 'find_closest()' should not be used for arrays
      with progressions of 1 (i.e. '{1, 2, 3, ...}', the macro should still
      behave correctly.
      
      The bug was found while testing the 'drivers/iio/adc/ad7606.c',
      specifically the oversampling feature.
      For reference, the oversampling values are listed as:
         static const unsigned int ad7606_oversampling_avail[7] = {
                1, 2, 4, 8, 16, 32, 64,
         };
      
      When doing:
        1. $ echo 1 > /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           $ cat /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           1  # this is fine
        2. $ echo 2 > /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           $ cat /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           1  # this is wrong; 2 should be returned here
        3. $ echo 3 > /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           $ cat /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           2  # this is fine
        4. $ echo 4 > /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           $ cat /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           4  # this is fine
      And from here-on, the values are as correct (one gets what one would
      expect.)
      
      While writing a kunit test for this bug, a peculiar issue was found for the
      array in the 'drivers/hwmon/ina2xx.c' & 'drivers/iio/adc/ina2xx-adc.c'
      drivers. While running the kunit test (for 'ina226_avg_tab' from these
      drivers):
        * idx = find_closest([-1 to 2], ina226_avg_tab, ARRAY_SIZE(ina226_avg_tab));
          This returns idx == 0, so value.
        * idx = find_closest(3, ina226_avg_tab, ARRAY_SIZE(ina226_avg_tab));
          This returns idx == 0, value 1; and now one could argue whether 3 is
          closer to 4 or to 1. This quirk only appears for value '3' in this
          array, but it seems to be a another rounding issue.
        * And from 4 onwards the 'find_closest'() works fine (one gets what one
          would expect).
      
      This change reworks the find_closest() macros to also check the difference
      between the left and right elements when 'x'. If the distance to the right
      is smaller (than the distance to the left), the index is incremented by 1.
      This also makes redundant the need for using the DIV_ROUND_CLOSEST() macro.
      
      In order to accommodate for any mix of negative + positive values, the
      internal variables '__fc_x', '__fc_mid_x', '__fc_left' & '__fc_right' are
      forced to 'long' type. This also addresses any potential bugs/issues with
      'x' being of an unsigned type. In those situations any comparison between
      signed & unsigned would be promoted to a comparison between 2 unsigned
      numbers; this is especially annoying when '__fc_left' & '__fc_right'
      underflow.
      
      The find_closest_descending() macro was also reworked and duplicated from
      the find_closest(), and it is being iterated in reverse. The main reason
      for this is to get the same indices as 'find_closest()' (but in reverse).
      The comparison for '__fc_right < __fc_left' favors going the array in
      ascending order.
      For example for array '{ 1024, 512, 256, 128, 64, 16, 4, 1 }' and x = 3, we
      get:
          __fc_mid_x = 2
          __fc_left = -1
          __fc_right = -2
          Then '__fc_right < __fc_left' evaluates to true and '__fc_i++' becomes 7
          which is not quite incorrect, but 3 is closer to 4 than to 1.
      
      This change has been validated with the kunit from the next patch.
      
      Link: https://lkml.kernel.org/r/20241105145406.554365-1-aardelean@baylibre.com
      
      
      Fixes: 95d11952 ("util_macros.h: add find_closest() macro")
      Signed-off-by: default avatarAlexandru Ardelean <aardelean@baylibre.com>
      Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a1f2aff0
    • Zicheng Qu's avatar
      ad7780: fix division by zero in ad7780_write_raw() · afc1e3c0
      Zicheng Qu authored
      
      commit c174b53e upstream.
      
      In the ad7780_write_raw() , val2 can be zero, which might lead to a
      division by zero error in DIV_ROUND_CLOSEST(). The ad7780_write_raw()
      is based on iio_info's write_raw. While val is explicitly declared that
      can be zero (in read mode), val2 is not specified to be non-zero.
      
      Fixes: 9085daa4 ("staging: iio: ad7780: add gain & filter gpio support")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarZicheng Qu <quzicheng@huawei.com>
      Link: https://patch.msgid.link/20241028142027.1032332-1-quzicheng@huawei.com
      
      
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      afc1e3c0
    • Filipe Manana's avatar
      btrfs: ref-verify: fix use-after-free after invalid ref action · 6fd018aa
      Filipe Manana authored
      
      [ Upstream commit 7c4e39f9 ]
      
      At btrfs_ref_tree_mod() after we successfully inserted the new ref entry
      (local variable 'ref') into the respective block entry's rbtree (local
      variable 'be'), if we find an unexpected action of BTRFS_DROP_DELAYED_REF,
      we error out and free the ref entry without removing it from the block
      entry's rbtree. Then in the error path of btrfs_ref_tree_mod() we call
      btrfs_free_ref_cache(), which iterates over all block entries and then
      calls free_block_entry() for each one, and there we will trigger a
      use-after-free when we are called against the block entry to which we
      added the freed ref entry to its rbtree, since the rbtree still points
      to the block entry, as we didn't remove it from the rbtree before freeing
      it in the error path at btrfs_ref_tree_mod(). Fix this by removing the
      new ref entry from the rbtree before freeing it.
      
      Syzbot report this with the following stack traces:
      
         BTRFS error (device loop0 state EA):   Ref action 2, root 5, ref_root 0, parent 8564736, owner 0, offset 0, num_refs 18446744073709551615
            __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
            update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
            btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
            btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
            btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
            btrfs_insert_empty_items+0x9c/0x1a0 fs/btrfs/ctree.c:4314
            btrfs_insert_empty_item fs/btrfs/ctree.h:669 [inline]
            btrfs_insert_orphan_item+0x1f1/0x320 fs/btrfs/orphan.c:23
            btrfs_orphan_add+0x6d/0x1a0 fs/btrfs/inode.c:3482
            btrfs_unlink+0x267/0x350 fs/btrfs/inode.c:4293
            vfs_unlink+0x365/0x650 fs/namei.c:4469
            do_unlinkat+0x4ae/0x830 fs/namei.c:4533
            __do_sys_unlinkat fs/namei.c:4576 [inline]
            __se_sys_unlinkat fs/namei.c:4569 [inline]
            __x64_sys_unlinkat+0xcc/0xf0 fs/namei.c:4569
            do_syscall_x64 arch/x86/entry/common.c:52 [inline]
            do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
            entry_SYSCALL_64_after_hwframe+0x77/0x7f
         BTRFS error (device loop0 state EA):   Ref action 1, root 5, ref_root 5, parent 0, owner 260, offset 0, num_refs 1
            __btrfs_mod_ref+0x76b/0xac0 fs/btrfs/extent-tree.c:2521
            update_ref_for_cow+0x96a/0x11f0
            btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
            btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
            btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
            btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
            __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
            btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
            __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
            __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
            btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
            prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
            relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
            btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
            btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
            __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
            btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
         BTRFS error (device loop0 state EA):   Ref action 2, root 5, ref_root 0, parent 8564736, owner 0, offset 0, num_refs 18446744073709551615
            __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
            update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
            btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
            btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
            btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
            btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
            __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
            btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
            __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
            __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
            btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
            prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
            relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
            btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
            btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
            __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
            btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
         ==================================================================
         BUG: KASAN: slab-use-after-free in rb_first+0x69/0x70 lib/rbtree.c:473
         Read of size 8 at addr ffff888042d1af38 by task syz.0.0/5329
      
         CPU: 0 UID: 0 PID: 5329 Comm: syz.0.0 Not tainted 6.12.0-rc7-syzkaller #0
         Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
         Call Trace:
          <TASK>
          __dump_stack lib/dump_stack.c:94 [inline]
          dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
          print_address_description mm/kasan/report.c:377 [inline]
          print_report+0x169/0x550 mm/kasan/report.c:488
          kasan_report+0x143/0x180 mm/kasan/report.c:601
          rb_first+0x69/0x70 lib/rbtree.c:473
          free_block_entry+0x78/0x230 fs/btrfs/ref-verify.c:248
          btrfs_free_ref_cache+0xa3/0x100 fs/btrfs/ref-verify.c:917
          btrfs_ref_tree_mod+0x139f/0x15e0 fs/btrfs/ref-verify.c:898
          btrfs_free_extent+0x33c/0x380 fs/btrfs/extent-tree.c:3544
          __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
          update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
          btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
          btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
          btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
          btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
          __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
          btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
          __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
          __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
          btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
          prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
          relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
          btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
          btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
          __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
          btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
          btrfs_ioctl_balance+0x493/0x7c0 fs/btrfs/ioctl.c:3673
          vfs_ioctl fs/ioctl.c:51 [inline]
          __do_sys_ioctl fs/ioctl.c:907 [inline]
          __se_sys_ioctl+0xf9/0x170 fs/ioctl.c:893
          do_syscall_x64 arch/x86/entry/common.c:52 [inline]
          do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
          entry_SYSCALL_64_after_hwframe+0x77/0x7f
         RIP: 0033:0x7f996df7e719
         RSP: 002b:00007f996ede7038 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
         RAX: ffffffffffffffda RBX: 00007f996e135f80 RCX: 00007f996df7e719
         RDX: 0000000020000180 RSI: 00000000c4009420 RDI: 0000000000000004
         RBP: 00007f996dff139e R08: 0000000000000000 R09: 0000000000000000
         R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
         R13: 0000000000000000 R14: 00007f996e135f80 R15: 00007fff79f32e68
          </TASK>
      
         Allocated by task 5329:
          kasan_save_stack mm/kasan/common.c:47 [inline]
          kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
          poison_kmalloc_redzone mm/kasan/common.c:377 [inline]
          __kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:394
          kasan_kmalloc include/linux/kasan.h:257 [inline]
          __kmalloc_cache_noprof+0x19c/0x2c0 mm/slub.c:4295
          kmalloc_noprof include/linux/slab.h:878 [inline]
          kzalloc_noprof include/linux/slab.h:1014 [inline]
          btrfs_ref_tree_mod+0x264/0x15e0 fs/btrfs/ref-verify.c:701
          btrfs_free_extent+0x33c/0x380 fs/btrfs/extent-tree.c:3544
          __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
          update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
          btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
          btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
          btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
          btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
          __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
          btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
          __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
          __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
          btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
          prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
          relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
          btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
          btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
          __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
          btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
          btrfs_ioctl_balance+0x493/0x7c0 fs/btrfs/ioctl.c:3673
          vfs_ioctl fs/ioctl.c:51 [inline]
          __do_sys_ioctl fs/ioctl.c:907 [inline]
          __se_sys_ioctl+0xf9/0x170 fs/ioctl.c:893
          do_syscall_x64 arch/x86/entry/common.c:52 [inline]
          do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
          entry_SYSCALL_64_after_hwframe+0x77/0x7f
      
         Freed by task 5329:
          kasan_save_stack mm/kasan/common.c:47 [inline]
          kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
          kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:579
          poison_slab_object mm/kasan/common.c:247 [inline]
          __kasan_slab_free+0x59/0x70 mm/kasan/common.c:264
          kasan_slab_free include/linux/kasan.h:230 [inline]
          slab_free_hook mm/slub.c:2342 [inline]
          slab_free mm/slub.c:4579 [inline]
          kfree+0x1a0/0x440 mm/slub.c:4727
          btrfs_ref_tree_mod+0x136c/0x15e0
          btrfs_free_extent+0x33c/0x380 fs/btrfs/extent-tree.c:3544
          __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
          update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
          btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
          btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
          btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
          btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
          __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
          btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
          __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
          __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
          btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
          prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
          relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
          btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
          btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
          __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
          btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
          btrfs_ioctl_balance+0x493/0x7c0 fs/btrfs/ioctl.c:3673
          vfs_ioctl fs/ioctl.c:51 [inline]
          __do_sys_ioctl fs/ioctl.c:907 [inline]
          __se_sys_ioctl+0xf9/0x170 fs/ioctl.c:893
          do_syscall_x64 arch/x86/entry/common.c:52 [inline]
          do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
          entry_SYSCALL_64_after_hwframe+0x77/0x7f
      
         The buggy address belongs to the object at ffff888042d1af00
          which belongs to the cache kmalloc-64 of size 64
         The buggy address is located 56 bytes inside of
          freed 64-byte region [ffff888042d1af00, ffff888042d1af40)
      
         The buggy address belongs to the physical page:
         page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x42d1a
         anon flags: 0x4fff00000000000(node=1|zone=1|lastcpupid=0x7ff)
         page_type: f5(slab)
         raw: 04fff00000000000 ffff88801ac418c0 0000000000000000 dead000000000001
         raw: 0000000000000000 0000000000200020 00000001f5000000 0000000000000000
         page dumped because: kasan: bad access detected
         page_owner tracks the page as allocated
         page last allocated via order 0, migratetype Unmovable, gfp_mask 0x52c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 5055, tgid 5055 (dhcpcd-run-hook), ts 40377240074, free_ts 40376848335
          set_page_owner include/linux/page_owner.h:32 [inline]
          post_alloc_hook+0x1f3/0x230 mm/page_alloc.c:1541
          prep_new_page mm/page_alloc.c:1549 [inline]
          get_page_from_freelist+0x3649/0x3790 mm/page_alloc.c:3459
          __alloc_pages_noprof+0x292/0x710 mm/page_alloc.c:4735
          alloc_pages_mpol_noprof+0x3e8/0x680 mm/mempolicy.c:2265
          alloc_slab_page+0x6a/0x140 mm/slub.c:2412
          allocate_slab+0x5a/0x2f0 mm/slub.c:2578
          new_slab mm/slub.c:2631 [inline]
          ___slab_alloc+0xcd1/0x14b0 mm/slub.c:3818
          __slab_alloc+0x58/0xa0 mm/slub.c:3908
          __slab_alloc_node mm/slub.c:3961 [inline]
          slab_alloc_node mm/slub.c:4122 [inline]
          __do_kmalloc_node mm/slub.c:4263 [inline]
          __kmalloc_noprof+0x25a/0x400 mm/slub.c:4276
          kmalloc_noprof include/linux/slab.h:882 [inline]
          kzalloc_noprof include/linux/slab.h:1014 [inline]
          tomoyo_encode2 security/tomoyo/realpath.c:45 [inline]
          tomoyo_encode+0x26f/0x540 security/tomoyo/realpath.c:80
          tomoyo_realpath_from_path+0x59e/0x5e0 security/tomoyo/realpath.c:283
          tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
          tomoyo_check_open_permission+0x255/0x500 security/tomoyo/file.c:771
          security_file_open+0x777/0x990 security/security.c:3109
          do_dentry_open+0x369/0x1460 fs/open.c:945
          vfs_open+0x3e/0x330 fs/open.c:1088
          do_open fs/namei.c:3774 [inline]
          path_openat+0x2c84/0x3590 fs/namei.c:3933
         page last free pid 5055 tgid 5055 stack trace:
          reset_page_owner include/linux/page_owner.h:25 [inline]
          free_pages_prepare mm/page_alloc.c:1112 [inline]
          free_unref_page+0xcfb/0xf20 mm/page_alloc.c:2642
          free_pipe_info+0x300/0x390 fs/pipe.c:860
          put_pipe_info fs/pipe.c:719 [inline]
          pipe_release+0x245/0x320 fs/pipe.c:742
          __fput+0x23f/0x880 fs/file_table.c:431
          __do_sys_close fs/open.c:1567 [inline]
          __se_sys_close fs/open.c:1552 [inline]
          __x64_sys_close+0x7f/0x110 fs/open.c:1552
          do_syscall_x64 arch/x86/entry/common.c:52 [inline]
          do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
          entry_SYSCALL_64_after_hwframe+0x77/0x7f
      
         Memory state around the buggy address:
          ffff888042d1ae00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
          ffff888042d1ae80: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
         >ffff888042d1af00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
                                                 ^
          ffff888042d1af80: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
          ffff888042d1b000: 00 00 00 00 00 fc fc 00 00 00 00 00 fc fc 00 00
      
      Reported-by: default avatar <syzbot+7325f164162e200000c1@syzkaller.appspotmail.com>
      Link: https://lore.kernel.org/linux-btrfs/673723eb.050a0220.1324f8.00a8.GAE@google.com/T/#u
      
      
      Fixes: fd708b81 ("Btrfs: add a extent ref verify tool")
      CC: stable@vger.kernel.org # 4.19+
      Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6fd018aa
    • Ojaswin Mujoo's avatar
      quota: flush quota_release_work upon quota writeback · 6f3821ac
      Ojaswin Mujoo authored
      
      [ Upstream commit ac6f4202 ]
      
      One of the paths quota writeback is called from is:
      
      freeze_super()
        sync_filesystem()
          ext4_sync_fs()
            dquot_writeback_dquots()
      
      Since we currently don't always flush the quota_release_work queue in
      this path, we can end up with the following race:
      
       1. dquot are added to releasing_dquots list during regular operations.
       2. FS Freeze starts, however, this does not flush the quota_release_work queue.
       3. Freeze completes.
       4. Kernel eventually tries to flush the workqueue while FS is frozen which
          hits a WARN_ON since transaction gets started during frozen state:
      
        ext4_journal_check_start+0x28/0x110 [ext4] (unreliable)
        __ext4_journal_start_sb+0x64/0x1c0 [ext4]
        ext4_release_dquot+0x90/0x1d0 [ext4]
        quota_release_workfn+0x43c/0x4d0
      
      Which is the following line:
      
        WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
      
      Which ultimately results in generic/390 failing due to dmesg
      noise. This was detected on powerpc machine 15 cores.
      
      To avoid this, make sure to flush the workqueue during
      dquot_writeback_dquots() so we dont have any pending workitems after
      freeze.
      
      Reported-by: default avatarDisha Goel <disgoel@linux.ibm.com>
      CC: stable@vger.kernel.org
      Fixes: dabc8b20 ("quota: fix dqput() to follow the guarantees dquot_srcu should provide")
      Reviewed-by: default avatarBaokun Li <libaokun1@huawei.com>
      Signed-off-by: default avatarOjaswin Mujoo <ojaswin@linux.ibm.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Link: https://patch.msgid.link/20241121123855.645335-2-ojaswin@linux.ibm.com
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6f3821ac
    • Gustavo A. R. Silva's avatar
      octeontx2-pf: Fix out-of-bounds read in otx2_get_fecparam() · 366e55e9
      Gustavo A. R. Silva authored
      
      commit 93efb0c6 upstream.
      
      Code at line 967 implies that rsp->fwdata.supported_fec may be up to 4:
      
       967: if (rsp->fwdata.supported_fec <= FEC_MAX_INDEX)
      
      If rsp->fwdata.supported_fec evaluates to 4, then there is an
      out-of-bounds read at line 971 because fec is an array with
      a maximum of 4 elements:
      
       954         const int fec[] = {
       955                 ETHTOOL_FEC_OFF,
       956                 ETHTOOL_FEC_BASER,
       957                 ETHTOOL_FEC_RS,
       958                 ETHTOOL_FEC_BASER | ETHTOOL_FEC_RS};
       959 #define FEC_MAX_INDEX 4
      
       971: fecparam->fec = fec[rsp->fwdata.supported_fec];
      
      Fix this by properly indexing fec[] with rsp->fwdata.supported_fec - 1.
      In this case the proper indexes 0 to 3 are used when
      rsp->fwdata.supported_fec evaluates to a range of 1 to 4, correspondingly.
      
      Fixes: d0cf9503 ("octeontx2-pf: ethtool fec mode support")
      Addresses-Coverity-ID: 1501722 ("Out-of-bounds read")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      366e55e9
    • Shengjiu Wang's avatar
      ASoC: fsl_micfil: fix the naming style for mask definition · 442dadf3
      Shengjiu Wang authored
      
      commit 101b096b upstream.
      
      Remove the _SHIFT for the mask definition.
      
      Fixes: 17f2142b ("ASoC: fsl_micfil: use GENMASK to define register bit fields")
      Signed-off-by: default avatarShengjiu Wang <shengjiu.wang@nxp.com>
      Acked-by: default avatarSascha Hauer <s.hauer@pengutronix.de>
      Link: https://lore.kernel.org/r/1651736047-28809-1-git-send-email-shengjiu.wang@nxp.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      442dadf3
    • Dan Carpenter's avatar
      sh: intc: Fix use-after-free bug in register_intc_controller() · 971b4893
      Dan Carpenter authored
      
      [ Upstream commit 63e72e55 ]
      
      In the error handling for this function, d is freed without ever
      removing it from intc_list which would lead to a use after free.
      To fix this, let's only add it to the list after everything has
      succeeded.
      
      Fixes: 2dcec7a9 ("sh: intc: set_irq_wake() support")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Reviewed-by: default avatarJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
      Signed-off-by: default avatarJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      971b4893
    • Liu Jian's avatar
      sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport · 86a1f9fa
      Liu Jian authored
      
      [ Upstream commit 4db9ad82 ]
      
      Since transport->sock has been set to NULL during reset transport,
      XPRT_SOCK_UPD_TIMEOUT also needs to be cleared. Otherwise, the
      xs_tcp_set_socket_timeouts() may be triggered in xs_tcp_send_request()
      to dereference the transport->sock that has been set to NULL.
      
      Fixes: 7196dbb0 ("SUNRPC: Allow changing of the TCP timeout parameters on the fly")
      Signed-off-by: default avatarLi Lingfeng <lilingfeng3@huawei.com>
      Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      86a1f9fa
    • Trond Myklebust's avatar
      SUNRPC: Replace internal use of SOCKWQ_ASYNC_NOSPACE · 8c06a00a
      Trond Myklebust authored
      
      [ Upstream commit 2790a624 ]
      
      The socket's SOCKWQ_ASYNC_NOSPACE can be cleared by various actors in
      the socket layer, so replace it with our own flag in the transport
      sock_state field.
      
      Reported-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Stable-dep-of: 4db9ad82 ("sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8c06a00a
    • Thiago Rafael Becker's avatar
      sunrpc: remove unnecessary test in rpc_task_set_client() · a4b153bd
      Thiago Rafael Becker authored
      
      [ Upstream commit 023859ce ]
      
      In rpc_task_set_client(), testing for a NULL clnt is not necessary, as
      clnt should always be a valid pointer to a rpc_client.
      
      Signed-off-by: default avatarThiago Rafael Becker <trbecker@gmail.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Stable-dep-of: 4db9ad82 ("sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a4b153bd
    • Trond Myklebust's avatar
      SUNRPC: Convert rpc_client refcount to use refcount_t · 3ccfa826
      Trond Myklebust authored
      
      [ Upstream commit 71d3d0eb ]
      
      There are now tools in the refcount library that allow us to convert the
      client shutdown code.
      
      Reported-by: default avatarXiyu Yang <xiyuyang19@fudan.edu.cn>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Stable-dep-of: 4db9ad82 ("sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3ccfa826
    • Calum Mackay's avatar
      SUNRPC: correct error code comment in xs_tcp_setup_socket() · e2730edf
      Calum Mackay authored
      
      [ Upstream commit 8c71139d ]
      
      This comment was introduced by commit 6ea44adc
      ("SUNRPC: ensure correct error is reported by xs_tcp_setup_socket()").
      
      I believe EIO was a typo at the time: it should have been EAGAIN.
      
      Subsequently, commit 0445f92c ("SUNRPC: Fix disconnection races")
      changed that to ENOTCONN.
      
      Rather than trying to keep the comment here in sync with the code in
      xprt_force_disconnect(), make the point in a non-specific way.
      
      Fixes: 6ea44adc ("SUNRPC: ensure correct error is reported by xs_tcp_setup_socket()")
      Signed-off-by: default avatarCalum Mackay <calum.mackay@oracle.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Stable-dep-of: 4db9ad82 ("sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e2730edf
    • Li Lingfeng's avatar
      nfs: ignore SB_RDONLY when mounting nfs · f69fb61c
      Li Lingfeng authored
      [ Upstream commit 52cb7f8f ]
      
      When exporting only one file system with fsid=0 on the server side, the
      client alternately uses the ro/rw mount options to perform the mount
      operation, and a new vfsmount is generated each time.
      
      It can be reproduced as follows:
      [root@localhost ~]# mount /dev/sda /mnt2
      [root@localhost ~]# echo "/mnt2 *(rw,no_root_squash,fsid=0)" >/etc/exports
      [root@localhost ~]# systemctl restart nfs-server
      [root@localhost ~]# mount -t nfs -o ro,vers=4 127.0.0.1:/ /mnt/sdaa
      [root@localhost ~]# mount -t nfs -o rw,vers=4 127.0.0.1:/ /mnt/sdaa
      [root@localhost ~]# mount -t nfs -o ro,vers=4 127.0.0.1:/ /mnt/sdaa
      [root@localhost ~]# mount -t nfs -o rw,vers=4 127.0.0.1:/ /mnt/sdaa
      [root@localhost ~]# mount | grep nfs4
      127.0.0.1:/ on /mnt/sdaa type nfs4 (ro,relatime,vers=4.2,rsize=1048576,...
      127.0.0.1:/ on /mnt/sdaa type nfs4 (rw,relatime,vers=4.2,rsize=1048576,...
      127.0.0.1:/ on /mnt/sdaa type nfs4 (ro,relatime,vers=4.2,rsize=1048576,...
      127.0.0.1:/ on /mnt/sdaa type nfs4 (rw,relatime,vers=4.2,rsize=1048576,...
      [root@localhost ~]#
      
      We expected that after mounting with the ro option, using the rw option to
      mount again would return EBUSY, but the actual situation was not the case.
      
      As shown above, when mounting for the first time, a superblock with the ro
      flag will be generated, and at the same time, in do_new_mount_fc -->
      do_add_mount, it detects that the superblock corresponding to the current
      target directory is inconsistent with the currently generated one
      (path->mnt->mnt_sb != newmnt->mnt.mnt_sb), and a new vfsmount will be
      generated.
      
      When mounting with the rw option for the second time, since no matching
      superblock can be found in the fs_supers list, a new superblock with the
      rw flag will be generated again. The superblock in use (ro) is different
      from the newly generated superblock (rw), and a new vfsmount will be
      generated again.
      
      When mounting with the ro option for the third time, the superblock (ro)
      is found in fs_supers, the superblock in use (rw) is different from the
      found superblock (ro), and a new vfsmount will be generated again.
      
      We can switch between ro/rw through remount, and only one superblock needs
      to be generated, thus avoiding the problem of repeated generation of
      vfsmount caused by switching superblocks.
      
      Furthermore, This can also resolve the issue described in the link.
      
      Fixes: 275a5d24 ("NFS: Error when mounting the same filesystem with different options")
      Link: https://lore.kernel.org/all/20240604112636.236517-3-lilingfeng@huaweicloud.com/
      
      
      Signed-off-by: default avatarLi Lingfeng <lilingfeng3@huawei.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f69fb61c
    • Masahiro Yamada's avatar
      modpost: remove incorrect code in do_eisa_entry() · bd4624d7
      Masahiro Yamada authored
      
      [ Upstream commit 0c3e0913 ]
      
      This function contains multiple bugs after the following commits:
      
       - ac551828 ("modpost: i2c aliases need no trailing wildcard")
       - 6543becf ("mod/file2alias: make modalias generation safe for cross compiling")
      
      Commit ac551828 inserted the following code to do_eisa_entry():
      
          else
                  strcat(alias, "*");
      
      This is incorrect because 'alias' is uninitialized. If it is not
      NULL-terminated, strcat() could cause a buffer overrun.
      
      Even if 'alias' happens to be zero-filled, it would output:
      
          MODULE_ALIAS("*");
      
      This would match anything. As a result, the module could be loaded by
      any unrelated uevent from an unrelated subsystem.
      
      Commit ac551828 introduced another bug.            
      
      Prior to that commit, the conditional check was:
      
          if (eisa->sig[0])
      
      This checked if the first character of eisa_device_id::sig was not '\0'.
      
      However, commit ac551828 changed it as follows:
      
          if (sig[0])
      
      sig[0] is NOT the first character of the eisa_device_id::sig. The
      type of 'sig' is 'char (*)[8]', meaning that the type of 'sig[0]' is
      'char [8]' instead of 'char'. 'sig[0]' and 'symval' refer to the same
      address, which never becomes NULL.
      
      The correct conversion would have been:
      
          if ((*sig)[0])
      
      However, this if-conditional was meaningless because the earlier change
      in commit ac551828 was incorrect.
      
      This commit removes the entire incorrect code, which should never have
      been executed.
      
      Fixes: ac551828 ("modpost: i2c aliases need no trailing wildcard")
      Fixes: 6543becf ("mod/file2alias: make modalias generation safe for cross compiling")
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bd4624d7
    • Maxime Chevallier's avatar
      rtc: ab-eoz9: don't fail temperature reads on undervoltage notification · b0660da6
      Maxime Chevallier authored
      
      [ Upstream commit e0779a0d ]
      
      The undervoltage flags reported by the RTC are useful to know if the
      time and date are reliable after a reboot. Although the threshold VLOW1
      indicates that the thermometer has been shutdown and time compensation
      is off, it doesn't mean that the temperature readout is currently
      impossible.
      
      As the system is running, the RTC voltage is now fully established and
      we can read the temperature.
      
      Fixes: 67075b63 ("rtc: add AB-RTCMC-32.768kHz-EOZ9 RTC support")
      Signed-off-by: default avatarMaxime Chevallier <maxime.chevallier@bootlin.com>
      Link: https://lore.kernel.org/r/20241122101031.68916-3-maxime.chevallier@bootlin.com
      
      
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b0660da6
    • Alex Zenla's avatar
      9p/xen: fix release of IRQ · 7f5a2ed5
      Alex Zenla authored
      
      [ Upstream commit e43c608f ]
      
      Kernel logs indicate an IRQ was double-freed.
      
      Pass correct device ID during IRQ release.
      
      Fixes: 71ebd719 ("xen/9pfs: connect to the backend")
      Signed-off-by: default avatarAlex Zenla <alex@edera.dev>
      Signed-off-by: default avatarAlexander Merritt <alexander@edera.dev>
      Signed-off-by: default avatarAriadne Conill <ariadne@ariadne.space>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Message-ID: <20241121225100.5736-1-alexander@edera.dev>
      [Dominique: remove confusing variable reset to 0]
      Signed-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7f5a2ed5
    • Alex Zenla's avatar
      9p/xen: fix init sequence · fa365f68
      Alex Zenla authored
      
      [ Upstream commit 7ef3ae82 ]
      
      Large amount of mount hangs observed during hotplugging of 9pfs devices. The
      9pfs Xen driver attempts to initialize itself more than once, causing the
      frontend and backend to disagree: the backend listens on a channel that the
      frontend does not send on, resulting in stalled processing.
      
      Only allow initialization of 9p frontend once.
      
      Fixes: c15fe55d ("9p/xen: fix connection sequence")
      Signed-off-by: default avatarAlex Zenla <alex@edera.dev>
      Signed-off-by: default avatarAlexander Merritt <alexander@edera.dev>
      Signed-off-by: default avatarAriadne Conill <ariadne@ariadne.space>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Message-ID: <20241119211633.38321-1-alexander@edera.dev>
      Signed-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fa365f68
    • Christoph Hellwig's avatar
      block: return unsigned int from bdev_io_min · 57ee79e9
      Christoph Hellwig authored
      
      [ Upstream commit 46fd48ab ]
      
      The underlying limit is defined as an unsigned int, so return that from
      bdev_io_min as well.
      
      Fixes: ac481c20 ("block: Topology ioctls")
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20241119072602.1059488-1-hch@lst.de
      
      
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      57ee79e9
    • Qingfang Deng's avatar
      jffs2: fix use of uninitialized variable · 25ec6cd7
      Qingfang Deng authored
      
      [ Upstream commit 3ba44ee9 ]
      
      When building the kernel with -Wmaybe-uninitialized, the compiler
      reports this warning:
      
      In function 'jffs2_mark_erased_block',
          inlined from 'jffs2_erase_pending_blocks' at fs/jffs2/erase.c:116:4:
      fs/jffs2/erase.c:474:9: warning: 'bad_offset' may be used uninitialized [-Wmaybe-uninitialized]
        474 |         jffs2_erase_failed(c, jeb, bad_offset);
            |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      fs/jffs2/erase.c: In function 'jffs2_erase_pending_blocks':
      fs/jffs2/erase.c:402:18: note: 'bad_offset' was declared here
        402 |         uint32_t bad_offset;
            |                  ^~~~~~~~~~
      
      When mtd->point() is used, jffs2_erase_pending_blocks can return -EIO
      without initializing bad_offset, which is later used at the filebad
      label in jffs2_mark_erased_block.
      Fix it by initializing this variable.
      
      Fixes: 8a0f5723 ("[JFFS2] Return values of jffs2_block_check_erase error paths")
      Signed-off-by: default avatarQingfang Deng <qingfang.deng@siflower.com.cn>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      25ec6cd7
Loading