Skip to content
  1. Dec 20, 2023
    • Stefan Wahren's avatar
      qca_debug: Fix ethtool -G iface tx behavior · 51ad9c19
      Stefan Wahren authored
      [ Upstream commit 96a7e861 ]
      
      After calling ethtool -g it was not possible to adjust the TX ring
      size again:
      
        # ethtool -g eth1
        Ring parameters for eth1:
        Pre-set maximums:
        RX:		4
        RX Mini:	n/a
        RX Jumbo:	n/a
        TX:		10
        Current hardware settings:
        RX:		4
        RX Mini:	n/a
        RX Jumbo:	n/a
        TX:		10
        # ethtool -G eth1 tx 8
        netlink error: Invalid argument
      
      The reason for this is that the readonly setting rx_pending get
      initialized and after that the range check in qcaspi_set_ringparam()
      fails regardless of the provided parameter. So fix this by accepting
      the exposed RX defaults. Instead of adding another magic number
      better use a new define here.
      
      Fixes: 291ab06e
      
       ("net: qualcomm: new Ethernet over SPI driver for QCA7000")
      Suggested-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarStefan Wahren <wahrenst@gmx.net>
      Link: https://lore.kernel.org/r/20231206141222.52029-3-wahrenst@gmx.net
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      51ad9c19
    • Stefan Wahren's avatar
      qca_debug: Prevent crash on TX ring changes · b7f58686
      Stefan Wahren authored
      [ Upstream commit f4e6064c ]
      
      The qca_spi driver stop and restart the SPI kernel thread
      (via ndo_stop & ndo_open) in case of TX ring changes. This is
      a big issue because it allows userspace to prevent restart of
      the SPI kernel thread (via signals). A subsequent change of
      TX ring wrongly assume a valid spi_thread pointer which result
      in a crash.
      
      So prevent this by stopping the network traffic handling and
      temporary park the SPI thread.
      
      Fixes: 291ab06e
      
       ("net: qualcomm: new Ethernet over SPI driver for QCA7000")
      Signed-off-by: default avatarStefan Wahren <wahrenst@gmx.net>
      Link: https://lore.kernel.org/r/20231206141222.52029-2-wahrenst@gmx.net
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b7f58686
    • Maciej Żenczykowski's avatar
      net: ipv6: support reporting otherwise unknown prefix flags in RTM_NEWPREFIX · 9354e0ac
      Maciej Żenczykowski authored
      [ Upstream commit bd4a8167 ]
      
      Lorenzo points out that we effectively clear all unknown
      flags from PIO when copying them to userspace in the netlink
      RTM_NEWPREFIX notification.
      
      We could fix this one at a time as new flags are defined,
      or in one fell swoop - I choose the latter.
      
      We could either define 6 new reserved flags (reserved1..6) and handle
      them individually (and rename them as new flags are defined), or we
      could simply copy the entire unmodified byte over - I choose the latter.
      
      This unfortunately requires some anonymous union/struct magic,
      so we add a static assert on the struct size for a little extra safety.
      
      Cc: David Ahern <dsahern@kernel.org>
      Cc: Lorenzo Colitti <lorenzo@google.com>
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarMaciej Żenczykowski <maze@google.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9354e0ac
    • David Howells's avatar
      afs: Fix refcount underflow from error handling race · 053220aa
      David Howells authored
      [ Upstream commit 52bf9f6c ]
      
      If an AFS cell that has an unreachable (eg. ENETUNREACH) server listed (VL
      server or fileserver), an asynchronous probe to one of its addresses may
      fail immediately because sendmsg() returns an error.  When this happens, a
      refcount underflow can happen if certain events hit a very small window.
      
      The way this occurs is:
      
       (1) There are two levels of "call" object, the afs_call and the
           rxrpc_call.  Each of them can be transitioned to a "completed" state
           in the event of success or failure.
      
       (2) Asynchronous afs_calls are self-referential whilst they are active to
           prevent them from evaporating when they're not being processed.  This
           reference is disposed of when the afs_call is completed.
      
           Note that an afs_call may only be completed once; once completed
           completing it again will do nothing.
      
       (3) When a call transmission is made, the app-side rxrpc code queues a Tx
           buffer for the rxrpc I/O thread to transmit.  The I/O thread invokes
           sendmsg() to transmit it - and in the case of failure, it transitions
           the rxrpc_call to the completed state.
      
       (4) When an rxrpc_call is completed, the app layer is notified.  In this
           case, the app is kafs and it schedules a work item to process events
           pertaining to an afs_call.
      
       (5) When the afs_call event processor is run, it goes down through the
           RPC-specific handler to afs_extract_data() to retrieve data from rxrpc
           - and, in this case, it picks up the error from the rxrpc_call and
           returns it.
      
           The error is then propagated to the afs_call and that is completed
           too.  At this point the self-reference is released.
      
       (6) If the rxrpc I/O thread manages to complete the rxrpc_call within the
           window between rxrpc_send_data() queuing the request packet and
           checking for call completion on the way out, then
           rxrpc_kernel_send_data() will return the error from sendmsg() to the
           app.
      
       (7) Then afs_make_call() will see an error and will jump to the error
           handling path which will attempt to clean up the afs_call.
      
       (8) The problem comes when the error handling path in afs_make_call()
           tries to unconditionally drop an async afs_call's self-reference.
           This self-reference, however, may already have been dropped by
           afs_extract_data() completing the afs_call
      
       (9) The refcount underflows when we return to afs_do_probe_vlserver() and
           that tries to drop its reference on the afs_call.
      
      Fix this by making afs_make_call() attempt to complete the afs_call rather
      than unconditionally putting it.  That way, if afs_extract_data() manages
      to complete the call first, afs_make_call() won't do anything.
      
      The bug can be forced by making do_udp_sendmsg() return -ENETUNREACH and
      sticking an msleep() in rxrpc_send_data() after the 'success:' label to
      widen the race window.
      
      The error message looks something like:
      
          refcount_t: underflow; use-after-free.
          WARNING: CPU: 3 PID: 720 at lib/refcount.c:28 refcount_warn_saturate+0xba/0x110
          ...
          RIP: 0010:refcount_warn_saturate+0xba/0x110
          ...
          afs_put_call+0x1dc/0x1f0 [kafs]
          afs_fs_get_capabilities+0x8b/0xe0 [kafs]
          afs_fs_probe_fileserver+0x188/0x1e0 [kafs]
          afs_lookup_server+0x3bf/0x3f0 [kafs]
          afs_alloc_server_list+0x130/0x2e0 [kafs]
          afs_create_volume+0x162/0x400 [kafs]
          afs_get_tree+0x266/0x410 [kafs]
          vfs_get_tree+0x25/0xc0
          fc_mount+0xe/0x40
          afs_d_automount+0x1b3/0x390 [kafs]
          __traverse_mounts+0x8f/0x210
          step_into+0x340/0x760
          path_openat+0x13a/0x1260
          do_filp_open+0xaf/0x160
          do_sys_openat2+0xaf/0x170
      
      or something like:
      
          refcount_t: underflow; use-after-free.
          ...
          RIP: 0010:refcount_warn_saturate+0x99/0xda
          ...
          afs_put_call+0x4a/0x175
          afs_send_vl_probes+0x108/0x172
          afs_select_vlserver+0xd6/0x311
          afs_do_cell_detect_alias+0x5e/0x1e9
          afs_cell_detect_alias+0x44/0x92
          afs_validate_fc+0x9d/0x134
          afs_get_tree+0x20/0x2e6
          vfs_get_tree+0x1d/0xc9
          fc_mount+0xe/0x33
          afs_d_automount+0x48/0x9d
          __traverse_mounts+0xe0/0x166
          step_into+0x140/0x274
          open_last_lookups+0x1c1/0x1df
          path_openat+0x138/0x1c3
          do_filp_open+0x55/0xb4
          do_sys_openat2+0x6c/0xb6
      
      Fixes: 34fa4761
      
       ("afs: Fix race in async call refcounting")
      Reported-by: default avatarBill MacAllister <bill@ca-zephyr.org>
      Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1052304
      
      
      Suggested-by: default avatarJeffrey E Altman <jaltman@auristor.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Reviewed-by: default avatarJeffrey Altman <jaltman@auristor.com>
      cc: Marc Dionne <marc.dionne@auristor.com>
      cc: linux-afs@lists.infradead.org
      Link: https://lore.kernel.org/r/2633992.1702073229@warthog.procyon.org.uk/
      
       # v1
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      053220aa
  2. Dec 14, 2023