1. Jun 28, 2023
    • Jakub Kicinski's avatar
      Merge branch 'af_unix-followup-fixes-for-so_passpidfd' · ae230642
      Jakub Kicinski authored
      Kuniyuki Iwashima says:
      
      ====================
      af_unix: Followup fixes for SO_PASSPIDFD.
      
      This series fixes 2 issues introduced by commit 5e2ff670 ("scm: add
      SO_PASSPIDFD and SCM_PIDFD").
      
      The 1st patch fixes a warning in scm_pidfd_recv() reported by syzkaller.
      The 2nd patch fixes a regression that bluetooth can't be built as module.
      ====================
      
      Link: https://lore.kernel.org/r/20230627174314.67688-1-kuniyu@amazon.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      ae230642
    • Alexander Mikhalitsyn's avatar
      net: scm: introduce and use scm_recv_unix helper · a9c49cc2
      Alexander Mikhalitsyn authored
      Recently, our friends from bluetooth subsystem reported [1] that after
      commit 5e2ff670 ("scm: add SO_PASSPIDFD and SCM_PIDFD") scm_recv()
      helper become unusable in kernel modules (because it uses unexported
      pidfd_prepare() API).
      
      We were aware of this issue and workarounded it in a hard way
      by commit 97154bcf ("af_unix: Kconfig: make CONFIG_UNIX bool").
      
      But recently a new functionality was added in the scope of commit
      817efd3cad74 ("Bluetooth: hci_sock: Forward credentials to monitor")
      and after that bluetooth can't be compiled as a kernel module.
      
      After some discussion in [1] we decided to split scm_recv() into
      two helpers, one won't support SCM_PIDFD (used for unix sockets),
      and another one will be completely the same as it was before commit
      5e2ff670 ("scm: add SO_PASSPIDFD and SCM_PIDFD").
      
      Link: https://lore.kernel.org/lkml/CAJqdLrpFcga4n7wxBhsFqPQiN8PKFVr6U10fKcJ9W7AcZn+o6Q@mail.gmail.com/ [1]
      Fixes: 5e2ff670
      
       ("scm: add SO_PASSPIDFD and SCM_PIDFD")
      Signed-off-by: default avatarAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
      Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Link: https://lore.kernel.org/r/20230627174314.67688-3-kuniyu@amazon.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      a9c49cc2
    • Kuniyuki Iwashima's avatar
      af_unix: Skip SCM_PIDFD if scm->pid is NULL. · 603fc57a
      Kuniyuki Iwashima authored
      syzkaller hit a WARN_ON_ONCE(!scm->pid) in scm_pidfd_recv().
      
      In unix_stream_read_generic(), if there is no skb in the queue, we could
      bail out the do-while loop without calling scm_set_cred():
      
        1. No skb in the queue
        2. sk is non-blocking
             or
           shutdown(sk, RCV_SHUTDOWN) is called concurrently
             or
           peer calls close()
      
      If the socket is configured with SO_PASSPIDFD, scm_pidfd_recv() would
      populate cmsg with garbage emitting the warning.
      
      Let's skip SCM_PIDFD if scm->pid is NULL in scm_pidfd_recv().
      
      Note another way would be skip calling scm_recv() in such cases, but this
      caused a regression resulting in commit 9d797ee2 ("Revert "af_unix:
      Call scm_recv() only after scm_set_cred()."").
      
      WARNING: CPU: 1 PID: 3245 at include/net/scm.h:138 scm_pidfd_recv include/net/scm.h:138 [inline]
      WARNING: CPU: 1 PID: 3245 at include/net/scm.h:138 scm_recv.constprop.0+0x754/0x850 include/net/scm.h:177
      Modules linked in:
      CPU: 1 PID: 3245 Comm: syz-executor.1 Not tainted 6.4.0-rc5-01219-gfa0e21fa #2
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
      RIP: 0010:scm_pidfd_recv include/net/scm.h:138 [inline]
      RIP: 0010:scm_recv.constprop.0+0x754/0x850 include/net/scm.h:177
      Code: 67 fd e9 55 fd ff ff e8 4a 70 67 fd e9 7f fd ff ff e8 40 70 67 fd e9 3e fb ff ff e8 36 70 67 fd e9 02 fd ff ff e8 8c 3a 20 fd <0f> 0b e9 fe fb ff ff e8 50 70 67 fd e9 2e f9 ff ff e8 46 70 67 fd
      RSP: 0018:ffffc90009af7660 EFLAGS: 00010216
      RAX: 00000000000000a1 RBX: ffff888041e58a80 RCX: ffffc90003852000
      RDX: 0000000000040000 RSI: ffffffff842675b4 RDI: 0000000000000007
      RBP: ffffc90009af7810 R08: 0000000000000007 R09: 0000000000000013
      R10: 00000000000000f8 R11: 0000000000000001 R12: ffffc90009af7db0
      R13: 0000000000000000 R14: ffff888041e58a88 R15: 1ffff9200135eecc
      FS:  00007f6b7113f640(0000) GS:ffff88806cf00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007f6b7111de38 CR3: 0000000012a6e002 CR4: 0000000000770ee0
      PKRU: 55555554
      Call Trace:
       <TASK>
       unix_stream_read_generic+0x5fe/0x1f50 net/unix/af_unix.c:2830
       unix_stream_recvmsg+0x194/0x1c0 net/unix/af_unix.c:2880
       sock_recvmsg_nosec net/socket.c:1019 [inline]
       sock_recvmsg+0x188/0x1d0 net/socket.c:1040
       ____sys_recvmsg+0x210/0x610 net/socket.c:2712
       ___sys_recvmsg+0xff/0x190 net/socket.c:2754
       do_recvmmsg+0x25d/0x6c0 net/socket.c:2848
       __sys_recvmmsg net/socket.c:2927 [inline]
       __do_sys_recvmmsg net/socket.c:2950 [inline]
       __se_sys_recvmmsg net/socket.c:2943 [inline]
       __x64_sys_recvmmsg+0x224/0x290 net/socket.c:2943
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3f/0x90 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x72/0xdc
      RIP: 0033:0x7f6b71da2e5d
      Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 73 9f 1b 00 f7 d8 64 89 01 48
      RSP: 002b:00007f6b7113ecc8 EFLAGS: 00000246 ORIG_RAX: 000000000000012b
      RAX: ffffffffffffffda RBX: 00000000004bc050 RCX: 00007f6b71da2e5d
      RDX: 0000000000000007 RSI: 0000000020006600 RDI: 000000000000000b
      RBP: 00000000004bc050 R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000120 R11: 0000000000000246 R12: 0000000000000000
      R13: 000000000000006e R14: 00007f6b71e03530 R15: 0000000000000000
       </TASK>
      
      Fixes: 5e2ff670
      
       ("scm: add SO_PASSPIDFD and SCM_PIDFD")
      Reported-by: default avatarsyzkaller <syzkaller@googlegroups.com>
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Link: https://lore.kernel.org/r/20230627174314.67688-2-kuniyu@amazon.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      603fc57a
    • Moritz Fischer's avatar
      net: lan743x: Simplify comparison · 30ac666a
      Moritz Fischer authored
      
      
      Simplify comparison, no functional changes.
      
      Cc: Bryan Whitehead <bryan.whitehead@microchip.com>
      Cc: UNGLinuxDriver@microchip.com
      Suggested-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarMoritz Fischer <moritzf@google.com>
      Link: https://lore.kernel.org/r/20230627035432.1296760-1-moritzf@google.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      30ac666a
    • Jakub Kicinski's avatar
      Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net · 3674fbf0
      Jakub Kicinski authored
      
      
      Merge in late fixes to prepare for the 6.5 net-next PR.
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      3674fbf0
    • Kuniyuki Iwashima's avatar
      netlink: Add __sock_i_ino() for __netlink_diag_dump(). · 25a9c8a4
      Kuniyuki Iwashima authored
      syzbot reported a warning in __local_bh_enable_ip(). [0]
      
      Commit 8d61f926 ("netlink: fix potential deadlock in
      netlink_set_err()") converted read_lock(&nl_table_lock) to
      read_lock_irqsave() in __netlink_diag_dump() to prevent a deadlock.
      
      However, __netlink_diag_dump() calls sock_i_ino() that uses
      read_lock_bh() and read_unlock_bh().  If CONFIG_TRACE_IRQFLAGS=y,
      read_unlock_bh() finally enables IRQ even though it should stay
      disabled until the following read_unlock_irqrestore().
      
      Using read_lock() in sock_i_ino() would trigger a lockdep splat
      in another place that was fixed in commit f064af1e ("net: fix
      a lockdep splat"), so let's add __sock_i_ino() that would be safe
      to use under BH disabled.
      
      [0]:
      WARNING: CPU: 0 PID: 5012 at kernel/softirq.c:376 __local_bh_enable_ip+0xbe/0x130 kernel/softirq.c:376
      Modules linked in:
      CPU: 0 PID: 5012 Comm: syz-executor487 Not tainted 6.4.0-rc7-syzkaller-00202-g6f68fc39 #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/27/2023
      RIP: 0010:__local_bh_enable_ip+0xbe/0x130 kernel/softirq.c:376
      Code: 45 bf 01 00 00 00 e8 91 5b 0a 00 e8 3c 15 3d 00 fb 65 8b 05 ec e9 b5 7e 85 c0 74 58 5b 5d c3 65 8b 05 b2 b6 b4 7e 85 c0 75 a2 <0f> 0b eb 9e e8 89 15 3d 00 eb 9f 48 89 ef e8 6f 49 18 00 eb a8 0f
      RSP: 0018:ffffc90003a1f3d0 EFLAGS: 00010046
      RAX: 0000000000000000 RBX: 0000000000000201 RCX: 1ffffffff1cf5996
      RDX: 0000000000000000 RSI: 0000000000000201 RDI: ffffffff8805c6f3
      RBP: ffffffff8805c6f3 R08: 0000000000000001 R09: ffff8880152b03a3
      R10: ffffed1002a56074 R11: 0000000000000005 R12: 00000000000073e4
      R13: dffffc0000000000 R14: 0000000000000002 R15: 0000000000000000
      FS:  0000555556726300(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 000000000045ad50 CR3: 000000007c646000 CR4: 00000000003506f0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       <TASK>
       sock_i_ino+0x83/0xa0 net/core/sock.c:2559
       __netlink_diag_dump+0x45c/0x790 net/netlink/diag.c:171
       netlink_diag_dump+0xd6/0x230 net/netlink/diag.c:207
       netlink_dump+0x570/0xc50 net/netlink/af_netlink.c:2269
       __netlink_dump_start+0x64b/0x910 net/netlink/af_netlink.c:2374
       netlink_dump_start include/linux/netlink.h:329 [inline]
       netlink_diag_handler_dump+0x1ae/0x250 net/netlink/diag.c:238
       __sock_diag_cmd net/core/sock_diag.c:238 [inline]
       sock_diag_rcv_msg+0x31e/0x440 net/core/sock_diag.c:269
       netlink_rcv_skb+0x165/0x440 net/netlink/af_netlink.c:2547
       sock_diag_rcv+0x2a/0x40 net/core/sock_diag.c:280
       netlink_unicast_kernel net/netlink/af_netlink.c:1339 [inline]
       netlink_unicast+0x547/0x7f0 net/netlink/af_netlink.c:1365
       netlink_sendmsg+0x925/0xe30 net/netlink/af_netlink.c:1914
       sock_sendmsg_nosec net/socket.c:724 [inline]
       sock_sendmsg+0xde/0x190 net/socket.c:747
       ____sys_sendmsg+0x71c/0x900 net/socket.c:2503
       ___sys_sendmsg+0x110/0x1b0 net/socket.c:2557
       __sys_sendmsg+0xf7/0x1c0 net/socket.c:2586
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      RIP: 0033:0x7f5303aaabb9
      Code: 28 c3 e8 2a 14 00 00 66 2e 0f 1f 84 00 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
      RSP: 002b:00007ffc7506e548 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
      RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f5303aaabb9
      RDX: 0000000000000000 RSI: 0000000020000180 RDI: 0000000000000003
      RBP: 00007f5303a6ed60 R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 00007f5303a6edf0
      R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
       </TASK>
      
      Fixes: 8d61f926
      
       ("netlink: fix potential deadlock in netlink_set_err()")
      Reported-by: default avatar <syzbot+5da61cf6a9bc1902d422@syzkaller.appspotmail.com>
      Link: https://syzkaller.appspot.com/bug?extid=5da61cf6a9bc1902d422
      
      
      Suggested-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20230626164313.52528-1-kuniyu@amazon.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      25a9c8a4
    • Vladimir Oltean's avatar
      net: dsa: avoid suspicious RCU usage for synced VLAN-aware MAC addresses · d06f925f
      Vladimir Oltean authored
      When using the felix driver (the only one which supports UC filtering
      and MC filtering) as a DSA master for a random other DSA switch, one can
      see the following stack trace when the downstream switch ports join a
      VLAN-aware bridge:
      
      =============================
      WARNING: suspicious RCU usage
      -----------------------------
      net/8021q/vlan_core.c:238 suspicious rcu_dereference_protected() usage!
      
      stack backtrace:
      Workqueue: dsa_ordered dsa_slave_switchdev_event_work
      Call trace:
       lockdep_rcu_suspicious+0x170/0x210
       vlan_for_each+0x8c/0x188
       dsa_slave_sync_uc+0x128/0x178
       __hw_addr_sync_dev+0x138/0x158
       dsa_slave_set_rx_mode+0x58/0x70
       __dev_set_rx_mode+0x88/0xa8
       dev_uc_add+0x74/0xa0
       dsa_port_bridge_host_fdb_add+0xec/0x180
       dsa_slave_switchdev_event_work+0x7c/0x1c8
       process_one_work+0x290/0x568
      
      What it's saying is that vlan_for_each() expects rtnl_lock() context and
      it's not getting it, when it's called from the DSA master's ndo_set_rx_mode().
      
      The caller of that - dsa_slave_set_rx_mode() - is the slave DSA
      interface's dsa_port_bridge_host_fdb_add() which comes from the deferred
      dsa_slave_switchdev_event_work().
      
      We went to great lengths to avoid the rtnl_lock() context in that call
      path in commit 0faf890f ("net: dsa: drop rtnl_lock from
      dsa_slave_switchdev_event_work"), and calling rtnl_lock() is simply not
      an option due to the possibility of deadlocking when calling
      dsa_flush_workqueue() from the call paths that do hold rtnl_lock() -
      basically all of them.
      
      So, when the DSA master calls vlan_for_each() from its ndo_set_rx_mode(),
      the state of the 8021q driver on this device is really not protected
      from concurrent access by anything.
      
      Looking at net/8021q/, I don't think that vlan_info->vid_list was
      particularly designed with RCU traversal in mind, so introducing an RCU
      read-side form of vlan_for_each() - vlan_for_each_rcu() - won't be so
      easy, and it also wouldn't be exactly what we need anyway.
      
      In general I believe that the solution isn't in net/8021q/ anyway;
      vlan_for_each() is not cut out for this task. DSA doesn't need rtnl_lock()
      to be held per se - since it's not a netdev state change that we're
      blocking, but rather, just concurrent additions/removals to a VLAN list.
      We don't even need sleepable context - the callback of vlan_for_each()
      just schedules deferred work.
      
      The proposed escape is to remove the dependency on vlan_for_each() and
      to open-code a non-sleepable, rtnl-free alternative to that, based on
      copies of the VLAN list modified from .ndo_vlan_rx_add_vid() and
      .ndo_vlan_rx_kill_vid().
      
      Fixes: 64fdc5f3
      
       ("net: dsa: sync unicast and multicast addresses for VLAN filters too")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Link: https://lore.kernel.org/r/20230626154402.3154454-1-vladimir.oltean@nxp.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      d06f925f
    • Kuniyuki Iwashima's avatar
      Revert "af_unix: Call scm_recv() only after scm_set_cred()." · 9d797ee2
      Kuniyuki Iwashima authored
      This reverts commit 3f5f118b.
      
      Konrad reported that desktop environment below cannot be reached after
      commit 3f5f118b
      
       ("af_unix: Call scm_recv() only after scm_set_cred().")
      
        - postmarketOS (Alpine Linux w/ musl 1.2.4)
        - busybox 1.36.1
        - GNOME 44.1
        - networkmanager 1.42.6
        - openrc 0.47
      
      Regarding to the warning of SO_PASSPIDFD, I'll post another patch to
      suppress it by skipping SCM_PIDFD if scm->pid == NULL in scm_pidfd_recv().
      
      Reported-by: default avatarKonrad Dybcio <konradybcio@kernel.org>
      Link: https://lore.kernel.org/netdev/8c7f9abd-4f84-7296-2788-1e130d6304a0@kernel.org/
      
      
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Tested-by: default avatarIdo Schimmel <idosch@nvidia.com>
      Tested-by: default avatarGal Pressman <gal@nvidia.com>
      Link: https://lore.kernel.org/r/20230626205837.82086-1-kuniyu@amazon.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      9d797ee2
    • Jakub Kicinski's avatar
      phylink: ReST-ify the phylink_pcs_neg_mode() kdoc · 1a3f6fc4
      Jakub Kicinski authored
      
      
      Stephen reports warnings when rendering phylink kdocs as HTML:
      
        include/linux/phylink.h:110: ERROR: Unexpected indentation.
        include/linux/phylink.h:111: WARNING: Block quote ends without a blank line; unexpected unindent.
        include/linux/phylink.h:614: WARNING: Inline literal start-string without end-string.
        include/linux/phylink.h:644: WARNING: Inline literal start-string without end-string.
      
      Make phylink_pcs_neg_mode() use a proper list format to fix the first
      two warnings.
      
      The last two warnings, AFAICT, come from the use of shorthand like
      phylink_mode_*(). Perhaps those should be special-cased at the Sphinx
      level.
      
      Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Link: https://lore.kernel.org/all/20230626162908.2f149f98@canb.auug.org.au/
      Link: https://lore.kernel.org/r/20230626214640.3142252-1-kuba@kernel.org
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      1a3f6fc4
    • David Howells's avatar
      libceph: Partially revert changes to support MSG_SPLICE_PAGES · 5da4d7b8
      David Howells authored
      Fix the mishandling of MSG_DONTWAIT and also reinstates the per-page
      checking of the source pages (which might have come from a DIO write by
      userspace) by partially reverting the changes to support MSG_SPLICE_PAGES
      and doing things a little differently.  In messenger_v1:
      
       (1) The ceph_tcp_sendpage() is resurrected and the callers reverted to use
           that.
      
       (2) The callers now pass MSG_MORE unconditionally.  Previously, they were
           passing in MSG_MORE|MSG_SENDPAGE_NOTLAST and then degrading that to
           just MSG_MORE on the last call to ->sendpage().
      
       (3) Make ceph_tcp_sendpage() a wrapper around sendmsg() rather than
           sendpage(), setting MSG_SPLICE_PAGES if sendpage_ok() returns true on
           the page.
      
      In messenger_v2:
      
       (4) Bring back do_try_sendpage() and make the callers use that.
      
       (5) Make do_try_sendpage() use sendmsg() for both cases and set
           MSG_SPLICE_PAGES if sendpage_ok() is set.
      
      Fixes: 40a8c17a ("ceph: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage")
      Fixes: fa094cca
      
       ("ceph: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage()")
      Reported-by: default avatarIlya Dryomov <idryomov@gmail.com>
      Link: https://lore.kernel.org/r/CAOi1vP9vjLfk3W+AJFeexC93jqPaPUn2dD_4NrzxwoZTbYfOnw@mail.gmail.com/
      Link: https://lore.kernel.org/r/CAOi1vP_Bn918j24S94MuGyn+Gxk212btw7yWeDrRcW1U8pc_BA@mail.gmail.com/
      
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Xiubo Li <xiubli@redhat.com>
      cc: Jeff Layton <jlayton@kernel.org>
      cc: Jens Axboe <axboe@kernel.dk>
      cc: Matthew Wilcox <willy@infradead.org>
      Link: https://lore.kernel.org/r/3101881.1687801973@warthog.procyon.org.uk/ # v1
      Link: https://lore.kernel.org/r/3111635.1687813501@warthog.procyon.org.uk/
      
       # v2
      Reviewed-by: default avatarIlya Dryomov <idryomov@gmail.com>
      Link: https://lore.kernel.org/r/3199652.1687873788@warthog.procyon.org.uk
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      5da4d7b8
    • Vladimir Oltean's avatar
      net: phy: mscc: fix packet loss due to RGMII delays · 528a08bc
      Vladimir Oltean authored
      Two deadly typos break RX and TX traffic on the VSC8502 PHY using RGMII
      if phy-mode = "rgmii-id" or "rgmii-txid", and no "tx-internal-delay-ps"
      override exists. The negative error code from phy_get_internal_delay()
      does not get overridden with the delay deduced from the phy-mode, and
      later gets committed to hardware. Also, the rx_delay gets overridden by
      what should have been the tx_delay.
      
      Fixes: dbb050d2
      
       ("phy: mscc: Add support for RGMII delay configuration")
      Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: default avatarHarini Katakam <harini.katakam@amd.com>
      Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
      Link: https://lore.kernel.org/r/20230627134235.3453358-1-vladimir.oltean@nxp.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      528a08bc
    • Jakub Kicinski's avatar
      Merge branch 'use-vmalloc_array-and-vcalloc' · d9b1a5a6
      Jakub Kicinski authored
      Julia Lawall says:
      
      ====================
      use vmalloc_array and vcalloc
      
      The functions vmalloc_array and vcalloc were introduced in
      
      commit a8749a35 ("mm: vmalloc: introduce array allocation functions")
      
      but are not used much yet.  This series introduces uses of
      these functions, to protect against multiplication overflows.
      
      The changes were done using the following Coccinelle semantic
      patch.
      
      @initialize:ocaml@
      @@
      
      let rename alloc =
        match alloc with
          "vmalloc" -> "vmalloc_array"
        | "vzalloc" -> "vcalloc"
        | _ -> failwith "unknown"
      
      @@
          size_t e1,e2;
          constant C1, C2;
          expression E1, E2, COUNT, x1, x2, x3;
          typedef u8;
          typedef __u8;
          type t = {u8,__u8,char,unsigned char};
          identifier alloc = {vmalloc,vzalloc};
          fresh identifier realloc = script:ocaml(alloc) { rename alloc };
      @@
      
      (
            alloc(x1*x2*x3)
      |
            alloc(C1 * C2)
      |
            alloc((sizeof(t)) * (COUNT), ...)
      |
      -     alloc((e1) * (e2))
      +     realloc(e1, e2)
      |
      -     alloc((e1) * (COUNT))
      +     realloc(COUNT, e1)
      |
      -     alloc((E1) * (E2))
      +     realloc(E1, E2)
      )
      
      v2: This series uses vmalloc_array and vcalloc instead of
      array_size.  It also leaves a multiplication of a constant by a
      sizeof as is.  Two patches are thus dropped from the series.
      ====================
      
      Link: https://lore.kernel.org/r/20230627144339.144478-1-Julia.Lawall@inria.fr
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      d9b1a5a6
    • Julia Lawall's avatar
      net: mana: use vmalloc_array and vcalloc · e9c74f8b
      Julia Lawall authored
      
      
      Use vmalloc_array and vcalloc to protect against
      multiplication overflows.
      
      The changes were done using the following Coccinelle
      semantic patch:
      
      // <smpl>
      @initialize:ocaml@
      @@
      
      let rename alloc =
        match alloc with
          "vmalloc" -> "vmalloc_array"
        | "vzalloc" -> "vcalloc"
        | _ -> failwith "unknown"
      
      @@
          size_t e1,e2;
          constant C1, C2;
          expression E1, E2, COUNT, x1, x2, x3;
          typedef u8;
          typedef __u8;
          type t = {u8,__u8,char,unsigned char};
          identifier alloc = {vmalloc,vzalloc};
          fresh identifier realloc = script:ocaml(alloc) { rename alloc };
      @@
      
      (
            alloc(x1*x2*x3)
      |
            alloc(C1 * C2)
      |
            alloc((sizeof(t)) * (COUNT), ...)
      |
      -     alloc((e1) * (e2))
      +     realloc(e1, e2)
      |
      -     alloc((e1) * (COUNT))
      +     realloc(COUNT, e1)
      |
      -     alloc((E1) * (E2))
      +     realloc(E1, E2)
      )
      // </smpl>
      
      Signed-off-by: default avatarJulia Lawall <Julia.Lawall@inria.fr>
      Link: https://lore.kernel.org/r/20230627144339.144478-23-Julia.Lawall@inria.fr
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      e9c74f8b
    • Julia Lawall's avatar
      net: enetc: use vmalloc_array and vcalloc · fa87c546
      Julia Lawall authored
      
      
      Use vmalloc_array and vcalloc to protect against
      multiplication overflows.
      
      The changes were done using the following Coccinelle
      semantic patch:
      
      // <smpl>
      @initialize:ocaml@
      @@
      
      let rename alloc =
        match alloc with
          "vmalloc" -> "vmalloc_array"
        | "vzalloc" -> "vcalloc"
        | _ -> failwith "unknown"
      
      @@
          size_t e1,e2;
          constant C1, C2;
          expression E1, E2, COUNT, x1, x2, x3;
          typedef u8;
          typedef __u8;
          type t = {u8,__u8,char,unsigned char};
          identifier alloc = {vmalloc,vzalloc};
          fresh identifier realloc = script:ocaml(alloc) { rename alloc };
      @@
      
      (
            alloc(x1*x2*x3)
      |
            alloc(C1 * C2)
      |
            alloc((sizeof(t)) * (COUNT), ...)
      |
      -     alloc((e1) * (e2))
      +     realloc(e1, e2)
      |
      -     alloc((e1) * (COUNT))
      +     realloc(COUNT, e1)
      |
      -     alloc((E1) * (E2))
      +     realloc(E1, E2)
      )
      // </smpl>
      
      Signed-off-by: default avatarJulia Lawall <Julia.Lawall@inria.fr>
      Link: https://lore.kernel.org/r/20230627144339.144478-19-Julia.Lawall@inria.fr
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      fa87c546
    • Julia Lawall's avatar
      ionic: use vmalloc_array and vcalloc · f712c829
      Julia Lawall authored
      
      
      Use vmalloc_array and vcalloc to protect against
      multiplication overflows.
      
      The changes were done using the following Coccinelle
      semantic patch:
      
      // <smpl>
      @initialize:ocaml@
      @@
      
      let rename alloc =
        match alloc with
          "vmalloc" -> "vmalloc_array"
        | "vzalloc" -> "vcalloc"
        | _ -> failwith "unknown"
      
      @@
          size_t e1,e2;
          constant C1, C2;
          expression E1, E2, COUNT, x1, x2, x3;
          typedef u8;
          typedef __u8;
          type t = {u8,__u8,char,unsigned char};
          identifier alloc = {vmalloc,vzalloc};
          fresh identifier realloc = script:ocaml(alloc) { rename alloc };
      @@
      
      (
            alloc(x1*x2*x3)
      |
            alloc(C1 * C2)
      |
            alloc((sizeof(t)) * (COUNT), ...)
      |
      -     alloc((e1) * (e2))
      +     realloc(e1, e2)
      |
      -     alloc((e1) * (COUNT))
      +     realloc(COUNT, e1)
      |
      -     alloc((E1) * (E2))
      +     realloc(E1, E2)
      )
      // </smpl>
      
      Signed-off-by: default avatarJulia Lawall <Julia.Lawall@inria.fr>
      Link: https://lore.kernel.org/r/20230627144339.144478-12-Julia.Lawall@inria.fr
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      f712c829
    • Julia Lawall's avatar
      pds_core: use vmalloc_array and vcalloc · 906a76cc
      Julia Lawall authored
      
      
      Use vmalloc_array and vcalloc to protect against
      multiplication overflows.
      
      The changes were done using the following Coccinelle
      semantic patch:
      
      // <smpl>
      @initialize:ocaml@
      @@
      
      let rename alloc =
        match alloc with
          "vmalloc" -> "vmalloc_array"
        | "vzalloc" -> "vcalloc"
        | _ -> failwith "unknown"
      
      @@
          size_t e1,e2;
          constant C1, C2;
          expression E1, E2, COUNT, x1, x2, x3;
          typedef u8;
          typedef __u8;
          type t = {u8,__u8,char,unsigned char};
          identifier alloc = {vmalloc,vzalloc};
          fresh identifier realloc = script:ocaml(alloc) { rename alloc };
      @@
      
      (
            alloc(x1*x2*x3)
      |
            alloc(C1 * C2)
      |
            alloc((sizeof(t)) * (COUNT), ...)
      |
      -     alloc((e1) * (e2))
      +     realloc(e1, e2)
      |
      -     alloc((e1) * (COUNT))
      +     realloc(COUNT, e1)
      |
      -     alloc((E1) * (E2))
      +     realloc(E1, E2)
      )
      // </smpl>
      
      Signed-off-by: default avatarJulia Lawall <Julia.Lawall@inria.fr>
      Link: https://lore.kernel.org/r/20230627144339.144478-10-Julia.Lawall@inria.fr
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      906a76cc
    • Julia Lawall's avatar
      gve: use vmalloc_array and vcalloc · a13de901
      Julia Lawall authored
      
      
      Use vmalloc_array and vcalloc to protect against
      multiplication overflows.
      
      The changes were done using the following Coccinelle
      semantic patch:
      
      // <smpl>
      @initialize:ocaml@
      @@
      
      let rename alloc =
        match alloc with
          "vmalloc" -> "vmalloc_array"
        | "vzalloc" -> "vcalloc"
        | _ -> failwith "unknown"
      
      @@
          size_t e1,e2;
          constant C1, C2;
          expression E1, E2, COUNT, x1, x2, x3;
          typedef u8;
          typedef __u8;
          type t = {u8,__u8,char,unsigned char};
          identifier alloc = {vmalloc,vzalloc};
          fresh identifier realloc = script:ocaml(alloc) { rename alloc };
      @@
      
      (
            alloc(x1*x2*x3)
      |
            alloc(C1 * C2)
      |
            alloc((sizeof(t)) * (COUNT), ...)
      |
      -     alloc((e1) * (e2))
      +     realloc(e1, e2)
      |
      -     alloc((e1) * (COUNT))
      +     realloc(COUNT, e1)
      |
      -     alloc((E1) * (E2))
      +     realloc(E1, E2)
      )
      // </smpl>
      
      Signed-off-by: default avatarJulia Lawall <Julia.Lawall@inria.fr>
      Link: https://lore.kernel.org/r/20230627144339.144478-5-Julia.Lawall@inria.fr
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      a13de901
    • Julia Lawall's avatar
      octeon_ep: use vmalloc_array and vcalloc · 32d462a5
      Julia Lawall authored
      
      
      Use vmalloc_array and vcalloc to protect against
      multiplication overflows.
      
      The changes were done using the following Coccinelle
      semantic patch:
      
      // <smpl>
      @initialize:ocaml@
      @@
      
      let rename alloc =
        match alloc with
          "vmalloc" -> "vmalloc_array"
        | "vzalloc" -> "vcalloc"
        | _ -> failwith "unknown"
      
      @@
          size_t e1,e2;
          constant C1, C2;
          expression E1, E2, COUNT, x1, x2, x3;
          typedef u8;
          typedef __u8;
          type t = {u8,__u8,char,unsigned char};
          identifier alloc = {vmalloc,vzalloc};
          fresh identifier realloc = script:ocaml(alloc) { rename alloc };
      @@
      
      (
            alloc(x1*x2*x3)
      |
            alloc(C1 * C2)
      |
            alloc((sizeof(t)) * (COUNT), ...)
      |
      -     alloc((e1) * (e2))
      +     realloc(e1, e2)
      |
      -     alloc((e1) * (COUNT))
      +     realloc(COUNT, e1)
      |
      -     alloc((E1) * (E2))
      +     realloc(E1, E2)
      )
      // </smpl>
      
      Signed-off-by: default avatarJulia Lawall <Julia.Lawall@inria.fr>
      Link: https://lore.kernel.org/r/20230627144339.144478-3-Julia.Lawall@inria.fr
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      32d462a5
  2. Jun 27, 2023
  3. Jun 26, 2023
    • Pablo Neira Ayuso's avatar
      netfilter: nf_tables: fix underflow in chain reference counter · b389139f
      Pablo Neira Ayuso authored
      Set element addition error path decrements reference counter on chains
      twice: once on element release and again via nft_data_release().
      
      Then, d6b47866 ("netfilter: nf_tables: fix underflow in object
      reference counter") incorrectly fixed this by removing the stateful
      object reference count decrement.
      
      Restore the stateful object decrement as in b91d9036 ("netfilter:
      nf_tables: fix leaking object reference count") and let
      nft_data_release() decrement the chain reference counter, so this is
      done only once.
      
      Fixes: d6b47866 ("netfilter: nf_tables: fix underflow in object reference counter")
      Fixes: 628bd3e4
      
       ("netfilter: nf_tables: drop map element references from preparation phase")
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      b389139f
    • Pablo Neira Ayuso's avatar
      netfilter: nf_tables: unbind non-anonymous set if rule construction fails · 3e704897
      Pablo Neira Ayuso authored
      Otherwise a dangling reference to a rule object that is gone remains
      in the set binding list.
      
      Fixes: 26b5a571
      
       ("netfilter: nf_tables: add NFT_TRANS_PREPARE_ERROR to deal with bound set/chain")
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      3e704897
    • Ilia.Gavrilov's avatar
      netfilter: nf_conntrack_sip: fix the ct_sip_parse_numerical_param() return value. · f188d300
      Ilia.Gavrilov authored
      ct_sip_parse_numerical_param() returns only 0 or 1 now.
      But process_register_request() and process_register_response() imply
      checking for a negative value if parsing of a numerical header parameter
      failed.
      The invocation in nf_nat_sip() looks correct:
       	if (ct_sip_parse_numerical_param(...) > 0 &&
       	    ...) { ... }
      
      Make the return value of the function ct_sip_parse_numerical_param()
      a tristate to fix all the cases
      a) return 1 if value is found; *val is set
      b) return 0 if value is not found; *val is unchanged
      c) return -1 on error; *val is undefined
      
      Found by InfoTeCS on behalf of Linux Verification Center
      (linuxtesting.org) with SVACE.
      
      Fixes: 0f32a40f
      
       ("[NETFILTER]: nf_conntrack_sip: create signalling expectations")
      Signed-off-by: default avatarIlia.Gavrilov <Ilia.Gavrilov@infotecs.ru>
      Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
      Reviewed-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      f188d300
    • Randy Dunlap's avatar
      linux/netfilter.h: fix kernel-doc warnings · f18e7122
      Randy Dunlap authored
      kernel-doc does not support DECLARE_PER_CPU(), so don't mark it with
      kernel-doc notation.
      
      One comment block is not kernel-doc notation, so just use
      "/*" to begin the comment.
      
      Quietens these warnings:
      
      netfilter.h:493: warning: Function parameter or member 'bool' not described in 'DECLARE_PER_CPU'
      netfilter.h:493: warning: Function parameter or member 'nf_skb_duplicated' not described in 'DECLARE_PER_CPU'
      netfilter.h:493: warning: expecting prototype for nf_skb_duplicated(). Prototype was for DECLARE_PER_CPU() instead
      netfilter.h:496: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
       * Contains bitmask of ctnetlink event subscribers, if any.
      
      Fixes: e7c8899f ("netfilter: move tee_active to core")
      Fixes: fdf64911
      
       ("netfilter: ctnetlink: make event listener tracking global")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      f18e7122
    • Florian Westphal's avatar
      netfilter: conntrack: dccp: copy entire header to stack buffer, not just basic one · ff0a3a7d
      Florian Westphal authored
      Eric Dumazet says:
        nf_conntrack_dccp_packet() has an unique:
      
        dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
      
        And nothing more is 'pulled' from the packet, depending on the content.
        dh->dccph_doff, and/or dh->dccph_x ...)
        So dccp_ack_seq() is happily reading stuff past the _dh buffer.
      
      BUG: KASAN: stack-out-of-bounds in nf_conntrack_dccp_packet+0x1134/0x11c0
      Read of size 4 at addr ffff000128f66e0c by task syz-executor.2/29371
      [..]
      
      Fix this by increasing the stack buffer to also include room for
      the extra sequence numbers and all the known dccp packet type headers,
      then pull again after the initial validation of the basic header.
      
      While at it, mark packets invalid that lack 48bit sequence bit but
      where RFC says the type MUST use them.
      
      Compile tested only.
      
      v2: first skb_header_pointer() now needs to adjust the size to
          only pull the generic header. (Eric)
      
      Heads-up: I intend to remove dccp conntrack support later this year.
      
      Fixes: 2bc78049
      
       ("[NETFILTER]: nf_conntrack: add DCCP protocol support")
      Reported-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      ff0a3a7d
    • Jeremy Sowden's avatar
      lib/ts_bm: reset initial match offset for every block of text · 6f67fbf8
      Jeremy Sowden authored
      The `shift` variable which indicates the offset in the string at which
      to start matching the pattern is initialized to `bm->patlen - 1`, but it
      is not reset when a new block is retrieved.  This means the implemen-
      tation may start looking at later and later positions in each successive
      block and miss occurrences of the pattern at the beginning.  E.g.,
      consider a HTTP packet held in a non-linear skb, where the HTTP request
      line occurs in the second block:
      
        [... 52 bytes of packet headers ...]
        GET /bmtest HTTP/1.1\r\nHost: www.example.com\r\n\r\n
      
      and the pattern is "GET /bmtest".
      
      Once the first block comprising the packet headers has been examined,
      `shift` will be pointing to somewhere near the end of the block, and so
      when the second block is examined the request line at the beginning will
      be missed.
      
      Reinitialize the variable for each new block.
      
      Fixes: 8082e4ed ("[LIB]: Boyer-Moore extension for textsearch infrastructure strike #2")
      Link: https://bugzilla.netfilter.org/show_bug.cgi?id=1390
      
      
      Signed-off-by: default avatarJeremy Sowden <jeremy@azazel.net>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      6f67fbf8
    • Lin Ma's avatar
      net: nfc: Fix use-after-free caused by nfc_llcp_find_local · 6709d4b7
      Lin Ma authored
      This commit fixes several use-after-free that caused by function
      nfc_llcp_find_local(). For example, one UAF can happen when below buggy
      time window occurs.
      
      // nfc_genl_llc_get_params   | // nfc_unregister_device
                                   |
      dev = nfc_get_device(idx);   | device_lock(...)
      if (!dev)                    | dev->shutting_down = true;
          return -ENODEV;          | device_unlock(...);
                                   |
      device_lock(...);            |   // nfc_llcp_unregister_device
                                   |   nfc_llcp_find_local()
      nfc_llcp_find_local(...);    |
                                   |   local_cleanup()
      if (!local) {                |
          rc = -ENODEV;            |     // nfc_llcp_local_put
          goto exit;               |     kref_put(.., local_release)
      }                            |
                                   |       // local_release
                                   |       list_del(&local->list)
        // nfc_genl_send_params    |       kfree()
        local->dev->idx !!!UAF!!!  |
                                   |
      
      and the crash trace for the one of the discussed UAF like:
      
      BUG: KASAN: slab-use-after-free in nfc_genl_llc_get_params+0x72f/0x780  net/nfc/netlink.c:1045
      Read of size 8 at addr ffff888105b0e410 by task 20114
      
      Call Trace:
       <TASK>
       __dump_stack  lib/dump_stack.c:88 [inline]
       dump_stack_lvl+0x72/0xa0  lib/dump_stack.c:106
       print_address_description  mm/kasan/report.c:319 [inline]
       print_report+0xcc/0x620  mm/kasan/report.c:430
       kasan_report+0xb2/0xe0  mm/kasan/report.c:536
       nfc_genl_send_params  net/nfc/netlink.c:999 [inline]
       nfc_genl_llc_get_params+0x72f/0x780  net/nfc/netlink.c:1045
       genl_family_rcv_msg_doit.isra.0+0x1ee/0x2e0  net/netlink/genetlink.c:968
       genl_family_rcv_msg  net/netlink/genetlink.c:1048 [inline]
       genl_rcv_msg+0x503/0x7d0  net/netlink/genetlink.c:1065
       netlink_rcv_skb+0x161/0x430  net/netlink/af_netlink.c:2548
       genl_rcv+0x28/0x40  net/netlink/genetlink.c:1076
       netlink_unicast_kernel  net/netlink/af_netlink.c:1339 [inline]
       netlink_unicast+0x644/0x900  net/netlink/af_netlink.c:1365
       netlink_sendmsg+0x934/0xe70  net/netlink/af_netlink.c:1913
       sock_sendmsg_nosec  net/socket.c:724 [inline]
       sock_sendmsg+0x1b6/0x200  net/socket.c:747
       ____sys_sendmsg+0x6e9/0x890  net/socket.c:2501
       ___sys_sendmsg+0x110/0x1b0  net/socket.c:2555
       __sys_sendmsg+0xf7/0x1d0  net/socket.c:2584
       do_syscall_x64  arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3f/0x90  arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x72/0xdc
      RIP: 0033:0x7f34640a2389
      RSP: 002b:00007f3463415168 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
      RAX: ffffffffffffffda RBX: 00007f34641c1f80 RCX: 00007f34640a2389
      RDX: 0000000000000000 RSI: 0000000020000240 RDI: 0000000000000006
      RBP: 00007f34640ed493 R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
      R13: 00007ffe38449ecf R14: 00007f3463415300 R15: 0000000000022000
       </TASK>
      
      Allocated by task 20116:
       kasan_save_stack+0x22/0x50  mm/kasan/common.c:45
       kasan_set_track+0x25/0x30  mm/kasan/common.c:52
       ____kasan_kmalloc  mm/kasan/common.c:374 [inline]
       __kasan_kmalloc+0x7f/0x90  mm/kasan/common.c:383
       kmalloc  include/linux/slab.h:580 [inline]
       kzalloc  include/linux/slab.h:720 [inline]
       nfc_llcp_register_device+0x49/0xa40  net/nfc/llcp_core.c:1567
       nfc_register_device+0x61/0x260  net/nfc/core.c:1124
       nci_register_device+0x776/0xb20  net/nfc/nci/core.c:1257
       virtual_ncidev_open+0x147/0x230  drivers/nfc/virtual_ncidev.c:148
       misc_open+0x379/0x4a0  drivers/char/misc.c:165
       chrdev_open+0x26c/0x780  fs/char_dev.c:414
       do_dentry_open+0x6c4/0x12a0  fs/open.c:920
       do_open  fs/namei.c:3560 [inline]
       path_openat+0x24fe/0x37e0  fs/namei.c:3715
       do_filp_open+0x1ba/0x410  fs/namei.c:3742
       do_sys_openat2+0x171/0x4c0  fs/open.c:1356
       do_sys_open  fs/open.c:1372 [inline]
       __do_sys_openat  fs/open.c:1388 [inline]
       __se_sys_openat  fs/open.c:1383 [inline]
       __x64_sys_openat+0x143/0x200  fs/open.c:1383
       do_syscall_x64  arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3f/0x90  arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x72/0xdc
      
      Freed by task 20115:
       kasan_save_stack+0x22/0x50  mm/kasan/common.c:45
       kasan_set_track+0x25/0x30  mm/kasan/common.c:52
       kasan_save_free_info+0x2e/0x50  mm/kasan/generic.c:521
       ____kasan_slab_free  mm/kasan/common.c:236 [inline]
       ____kasan_slab_free  mm/kasan/common.c:200 [inline]
       __kasan_slab_free+0x10a/0x190  mm/kasan/common.c:244
       kasan_slab_free  include/linux/kasan.h:162 [inline]
       slab_free_hook  mm/slub.c:1781 [inline]
       slab_free_freelist_hook  mm/slub.c:1807 [inline]
       slab_free  mm/slub.c:3787 [inline]
       __kmem_cache_free+0x7a/0x190  mm/slub.c:3800
       local_release  net/nfc/llcp_core.c:174 [inline]
       kref_put  include/linux/kref.h:65 [inline]
       nfc_llcp_local_put  net/nfc/llcp_core.c:182 [inline]
       nfc_llcp_local_put  net/nfc/llcp_core.c:177 [inline]
       nfc_llcp_unregister_device+0x206/0x290  net/nfc/llcp_core.c:1620
       nfc_unregister_device+0x160/0x1d0  net/nfc/core.c:1179
       virtual_ncidev_close+0x52/0xa0  drivers/nfc/virtual_ncidev.c:163
       __fput+0x252/0xa20  fs/file_table.c:321
       task_work_run+0x174/0x270  kernel/task_work.c:179
       resume_user_mode_work  include/linux/resume_user_mode.h:49 [inline]
       exit_to_user_mode_loop  kernel/entry/common.c:171 [inline]
       exit_to_user_mode_prepare+0x108/0x110  kernel/entry/common.c:204
       __syscall_exit_to_user_mode_work  kernel/entry/common.c:286 [inline]
       syscall_exit_to_user_mode+0x21/0x50  kernel/entry/common.c:297
       do_syscall_64+0x4c/0x90  arch/x86/entry/common.c:86
       entry_SYSCALL_64_after_hwframe+0x72/0xdc
      
      Last potentially related work creation:
       kasan_save_stack+0x22/0x50  mm/kasan/common.c:45
       __kasan_record_aux_stack+0x95/0xb0  mm/kasan/generic.c:491
       kvfree_call_rcu+0x29/0xa80  kernel/rcu/tree.c:3328
       drop_sysctl_table+0x3be/0x4e0  fs/proc/proc_sysctl.c:1735
       unregister_sysctl_table.part.0+0x9c/0x190  fs/proc/proc_sysctl.c:1773
       unregister_sysctl_table+0x24/0x30  fs/proc/proc_sysctl.c:1753
       neigh_sysctl_unregister+0x5f/0x80  net/core/neighbour.c:3895
       addrconf_notify+0x140/0x17b0  net/ipv6/addrconf.c:3684
       notifier_call_chain+0xbe/0x210  kernel/notifier.c:87
       call_netdevice_notifiers_info+0xb5/0x150  net/core/dev.c:1937
       call_netdevice_notifiers_extack  net/core/dev.c:1975 [inline]
       call_netdevice_notifiers  net/core/dev.c:1989 [inline]
       dev_change_name+0x3c3/0x870  net/core/dev.c:1211
       dev_ifsioc+0x800/0xf70  net/core/dev_ioctl.c:376
       dev_ioctl+0x3d9/0xf80  net/core/dev_ioctl.c:542
       sock_do_ioctl+0x160/0x260  net/socket.c:1213
       sock_ioctl+0x3f9/0x670  net/socket.c:1316
       vfs_ioctl  fs/ioctl.c:51 [inline]
       __do_sys_ioctl  fs/ioctl.c:870 [inline]
       __se_sys_ioctl  fs/ioctl.c:856 [inline]
       __x64_sys_ioctl+0x19e/0x210  fs/ioctl.c:856
       do_syscall_x64  arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x3f/0x90  arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x72/0xdc
      
      The buggy address belongs to the object at ffff888105b0e400
       which belongs to the cache kmalloc-1k of size 1024
      The buggy address is located 16 bytes inside of
       freed 1024-byte region [ffff888105b0e400, ffff888105b0e800)
      
      The buggy address belongs to the physical page:
      head:ffffea000416c200 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
      flags: 0x200000000010200(slab|head|node=0|zone=2)
      raw: 0200000000010200 ffff8881000430c0 ffffea00044c7010 ffffea0004510e10
      raw: 0000000000000000 00000000000a000a 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
       ffff888105b0e300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
       ffff888105b0e380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      >ffff888105b0e400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                               ^
       ffff888105b0e480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
       ffff888105b0e500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      
      In summary, this patch solves those use-after-free by
      
      1. Re-implement the nfc_llcp_find_local(). The current version does not
      grab the reference when getting the local from the linked list.  For
      example, the llcp_sock_bind() gets the reference like below:
      
      // llcp_sock_bind()
      
          local = nfc_llcp_find_local(dev); // A
          ..... \
                 | raceable
          ..... /
          llcp_sock->local = nfc_llcp_local_get(local); // B
      
      There is an apparent race window that one can  drop the reference
      and free the local object fetched in (A) before (B) gets the reference.
      
      2. Some callers of the nfc_llcp_find_local() do not grab the reference
      at all. For example, the nfc_genl_llc_{{get/set}_params/sdreq} functions.
      We add the nfc_llcp_local_put() for them. Moreover, we add the necessary
      error handling function to put the reference.
      
      3. Add the nfc_llcp_remove_local() helper. The local object is removed
      from the linked list in local_release() when all reference is gone. This
      patch removes it when nfc_llcp_unregister_device() is called.
      
      Therefore, every caller of nfc_llcp_find_local() will get a reference
      even when the nfc_llcp_unregister_device() is called. This promises no
      use-after-free for the local object is ever possible.
      
      Fixes: 52feb444 ("NFC: Extend netlink interface for LTO, RW, and MIUX parameters support")
      Fixes: c7aa1225
      
       ("NFC: Take a reference on the LLCP local pointer when creating a socket")
      Signed-off-by: default avatarLin Ma <linma@zju.edu.cn>
      Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      6709d4b7
    • David S. Miller's avatar
      Merge branch 'sfc-next' · 771ca3de
      David S. Miller authored
      
      
      Edward Cree says:
      
      ====================
      sfc: fix unaligned access in loopback selftests
      
      Arnd reported that the sfc drivers each define a packed loopback_payload
       structure with an ethernet header followed by an IP header, whereas the
       kernel definition of iphdr specifies that this is 4-byte aligned,
       causing a W=1 warning.
      Fix this in each case by adding two bytes of leading padding to the
       struct, taking care that these are not sent on the wire.
      Tested on EF10; build-tested on Siena and Falcon.
      
      Changed in v2:
      * added __aligned(4) to payload struct definitions (Arnd)
      * fixed dodgy whitespace (checkpatch)
      ====================
      
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      771ca3de
    • Edward Cree's avatar
      sfc: falcon: use padding to fix alignment in loopback test · 1186c6b3
      Edward Cree authored
      
      
      Add two bytes of padding to the start of struct ef4_loopback_payload,
       which are not sent on the wire.  This ensures the 'ip' member is
       4-byte aligned, preventing the following W=1 warning:
      net/ethernet/sfc/falcon/selftest.c:43:15: error: field ip within 'struct ef4_loopback_payload' is less aligned than 'struct iphdr' and is usually due to 'struct ef4_loopback_payload' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
              struct iphdr ip;
      
      Reported-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarEdward Cree <ecree.xilinx@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      1186c6b3
    • Edward Cree's avatar
      sfc: siena: use padding to fix alignment in loopback test · 30c24dd8
      Edward Cree authored
      
      
      Add two bytes of padding to the start of struct efx_loopback_payload,
       which are not sent on the wire.  This ensures the 'ip' member is
       4-byte aligned, preventing the following W=1 warning:
      net/ethernet/sfc/siena/selftest.c:46:15: error: field ip within 'struct efx_loopback_payload' is less aligned than 'struct iphdr' and is usually due to 'struct efx_loopback_payload' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
              struct iphdr ip;
      
      Reported-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarEdward Cree <ecree.xilinx@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      30c24dd8
    • Edward Cree's avatar
      sfc: use padding to fix alignment in loopback test · cf60ed46
      Edward Cree authored
      
      
      Add two bytes of padding to the start of struct efx_loopback_payload,
       which are not sent on the wire.  This ensures the 'ip' member is
       4-byte aligned, preventing the following W=1 warning:
      net/ethernet/sfc/selftest.c:46:15: error: field ip within 'struct efx_loopback_payload' is less aligned than 'struct iphdr' and is usually due to 'struct efx_loopback_payload' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
              struct iphdr ip;
      
      Reported-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarEdward Cree <ecree.xilinx@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      cf60ed46
    • Edward Cree's avatar
      sfc: fix crash when reading stats while NIC is resetting · d1b35543
      Edward Cree authored
      efx_net_stats() (.ndo_get_stats64) can be called during an ethtool
       selftest, during which time nic_data->mc_stats is NULL as the NIC has
       been fini'd.  In this case do not attempt to fetch the latest stats
       from the hardware, else we will crash on a NULL dereference:
          BUG: kernel NULL pointer dereference, address: 0000000000000038
          RIP efx_nic_update_stats
          abridged calltrace:
          efx_ef10_update_stats_pf
          efx_net_stats
          dev_get_stats
          dev_seq_printf_stats
      Skipping the read is safe, we will simply give out stale stats.
      To ensure that the free in efx_ef10_fini_nic() does not race against
       efx_ef10_update_stats_pf(), which could cause a TOCTTOU bug, take the
       efx->stats_lock in fini_nic (it is already held across update_stats).
      
      Fixes: d3142c19
      
       ("sfc: refactor EF10 stats handling")
      Reviewed-by: default avatarPieter Jansen van Vuuren <pieter.jansen-van-vuuren@amd.com>
      Signed-off-by: default avatarEdward Cree <ecree.xilinx@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      d1b35543
    • Florian Westphal's avatar
      netfilter: nf_tables: limit allowed range via nla_policy · a412dbf4
      Florian Westphal authored
      
      
      These NLA_U32 types get stored in u8 fields, reject invalid values
      instead of silently casting to u8.
      
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      a412dbf4
    • Phil Sutter's avatar
      netfilter: nf_tables: Introduce NFT_MSG_GETSETELEM_RESET · 079cd633
      Phil Sutter authored
      
      
      Analogous to NFT_MSG_GETOBJ_RESET, but for set elements with a timeout
      or attached stateful expressions like counters or quotas - reset them
      all at once. Respect a per element timeout value if present to reset the
      'expires' value to.
      
      Signed-off-by: default avatarPhil Sutter <phil@nwl.cc>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      079cd633
    • Florian Westphal's avatar
      netfilter: snat: evict closing tcp entries on reply tuple collision · 45897255
      Florian Westphal authored
      
      
      When all tried source tuples are in use, the connection request (skb)
      and the new conntrack will be dropped in nf_confirm() due to the
      non-recoverable clash.
      
      Make it so that the last 32 attempts are allowed to evict a colliding
      entry if this connection is already closing and the new sequence number
      has advanced past the old one.
      
      Such "all tuples taken" secenario can happen with tcp-rpc workloads where
      same dst:dport gets queried repeatedly.
      
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      45897255
    • Florian Westphal's avatar
      netfilter: nf_tables: permit update of set size · 96b2ef9b
      Florian Westphal authored
      
      
      Now that set->nelems is always updated permit update of the sets max size.
      
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      96b2ef9b
    • Florian Westphal's avatar
      netfilter: ipset: remove rcu_read_lock_bh pair from ip_set_test · 78aa23d0
      Florian Westphal authored
      
      
      Callers already hold rcu_read_lock.
      
      Prior to RCU conversion this used to be a read_lock_bh(), but now the
      bh-disable isn't needed anymore.
      
      Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
      Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      78aa23d0