Skip to content
  1. Sep 23, 2023
    • xu xin's avatar
      net/ipv4: return the real errno instead of -EINVAL · e5d94c98
      xu xin authored
      [ Upstream commit c67180ef
      
       ]
      
      For now, No matter what error pointer ip_neigh_for_gw() returns,
      ip_finish_output2() always return -EINVAL, which may mislead the upper
      users.
      
      For exemple, an application uses sendto to send an UDP packet, but when the
      neighbor table overflows, sendto() will get a value of -EINVAL, and it will
      cause users to waste a lot of time checking parameters for errors.
      
      Return the real errno instead of -EINVAL.
      
      Signed-off-by: default avatarxu xin <xu.xin16@zte.com.cn>
      Reviewed-by: default avatarYang Yang <yang.yang29@zte.com.cn>
      Cc: Si Hao <si.hao@zte.com.cn>
      Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Reviewed-by: default avatarVadim Fedorenko <vadim.fedorenko@linux.dev>
      Link: https://lore.kernel.org/r/20230807015408.248237-1-xu.xin16@zte.com.cn
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e5d94c98
    • Kuniyuki Iwashima's avatar
      net: Use sockaddr_storage for getsockopt(SO_PEERNAME). · d5372a1f
      Kuniyuki Iwashima authored
      [ Upstream commit 8936bf53 ]
      
      Commit df8fc4e9 ("kbuild: Enable -fstrict-flex-arrays=3") started
      applying strict rules to standard string functions.
      
      It does not work well with conventional socket code around each protocol-
      specific sockaddr_XXX struct, which is cast from sockaddr_storage and has
      a bigger size than fortified functions expect.  See these commits:
      
       commit 06d4c8a8 ("af_unix: Fix fortify_panic() in unix_bind_bsd().")
       commit ecb4534b ("af_unix: Terminate sun_path when bind()ing pathname socket.")
       commit a0ade840
      
       ("af_packet: Fix warning of fortified memcpy() in packet_getname().")
      
      We must cast the protocol-specific address back to sockaddr_storage
      to call such functions.
      
      However, in the case of getsockaddr(SO_PEERNAME), the rationale is a bit
      unclear as the buffer is defined by char[128] which is the same size as
      sockaddr_storage.
      
      Let's use sockaddr_storage explicitly.
      
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d5372a1f
    • John Watts's avatar
      can: sun4i_can: Add support for the Allwinner D1 · ab0ae0af
      John Watts authored
      [ Upstream commit 8abb9525
      
       ]
      
      The controllers present in the D1 are extremely similar to the R40
      and require the same reset quirks, but An extra quirk is needed to support
      receiving packets.
      
      Signed-off-by: default avatarJohn Watts <contact@jookia.org>
      Link: https://lore.kernel.org/all/20230721221552.1973203-6-contact@jookia.org
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ab0ae0af
    • John Watts's avatar
      can: sun4i_can: Add acceptance register quirk · 4eb79abf
      John Watts authored
      [ Upstream commit 8cda0c6d
      
       ]
      
      The Allwinner D1's CAN controllers have the ACPC and ACPM registers
      moved down. Compensate for this by adding an offset quirk for the
      acceptance registers.
      
      Signed-off-by: default avatarJohn Watts <contact@jookia.org>
      Link: https://lore.kernel.org/all/20230721221552.1973203-5-contact@jookia.org
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4eb79abf
    • Dmitry Antipov's avatar
      wifi: wil6210: fix fortify warnings · f04b40cb
      Dmitry Antipov authored
      [ Upstream commit 1ad8237e
      
       ]
      
      When compiling with gcc 13.1 and CONFIG_FORTIFY_SOURCE=y,
      I've noticed the following:
      
      In function ‘fortify_memcpy_chk’,
          inlined from ‘wil_rx_crypto_check_edma’ at drivers/net/wireless/ath/wil6210/txrx_edma.c:566:2:
      ./include/linux/fortify-string.h:529:25: warning: call to ‘__read_overflow2_field’
      declared with attribute warning: detected read beyond size of field (2nd parameter);
      maybe use struct_group()? [-Wattribute-warning]
        529 |                         __read_overflow2_field(q_size_field, size);
            |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      where the compiler complains on:
      
      const u8 *pn;
      ...
      pn = (u8 *)&st->ext.pn_15_0;
      ...
      memcpy(cc->pn, pn, IEEE80211_GCMP_PN_LEN);
      
      and:
      
      In function ‘fortify_memcpy_chk’,
          inlined from ‘wil_rx_crypto_check’ at drivers/net/wireless/ath/wil6210/txrx.c:684:2:
      ./include/linux/fortify-string.h:529:25: warning: call to ‘__read_overflow2_field’
      declared with attribute warning: detected read beyond size of field (2nd parameter);
      maybe use struct_group()? [-Wattribute-warning]
        529 |                         __read_overflow2_field(q_size_field, size);
            |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      where the compiler complains on:
      
      const u8 *pn = (u8 *)&d->mac.pn_15_0;
      ...
      memcpy(cc->pn, pn, IEEE80211_GCMP_PN_LEN);
      
      In both cases, the fortification logic interprets 'memcpy()' as 6-byte
      overread of 2-byte field 'pn_15_0' of 'struct wil_rx_status_extension'
      and 'pn_15_0' of 'struct vring_rx_mac', respectively. To silence
      these warnings, last two fields of the aforementioned structures
      are grouped using 'struct_group_attr(pn, __packed' quirk.
      
      Signed-off-by: default avatarDmitry Antipov <dmantipov@yandex.ru>
      Signed-off-by: default avatarKalle Valo <quic_kvalo@quicinc.com>
      Link: https://lore.kernel.org/r/20230621093711.80118-1-dmantipov@yandex.ru
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f04b40cb
    • Matt Whitlock's avatar
      mt76: mt7921: don't assume adequate headroom for SDIO headers · 5c8bbb79
      Matt Whitlock authored
      [ Upstream commit 98c4d0ab
      
       ]
      
      mt7921_usb_sdio_tx_prepare_skb() calls mt7921_usb_sdio_write_txwi() and
      mt7921_skb_add_usb_sdio_hdr(), both of which blindly assume that
      adequate headroom will be available in the passed skb. This assumption
      typically is satisfied when the skb was allocated in the net core for
      transmission via the mt7921 netdev (although even that is only an
      optimization and is not strictly guaranteed), but the assumption is
      sometimes not satisfied when the skb originated in the receive path of
      another netdev and was passed through to the mt7921, such as by the
      bridge layer. Blindly prepending bytes to an skb is always wrong.
      
      This commit introduces a call to skb_cow_head() before the call to
      mt7921_usb_sdio_write_txwi() in mt7921_usb_sdio_tx_prepare_skb() to
      ensure that at least MT_SDIO_TXD_SIZE + MT_SDIO_HDR_SIZE bytes can be
      pushed onto the skb.
      
      Without this fix, I can trivially cause kernel panics by bridging an
      MT7921AU-based USB 802.11ax interface with an Ethernet interface on an
      Intel Atom-based x86 system using its onboard RTL8169 PCI Ethernet
      adapter and also on an ARM-based Raspberry Pi 1 using its onboard
      SMSC9512 USB Ethernet adapter. Note that the panics do not occur in
      every system configuration, as they occur only if the receiving netdev
      leaves less headroom in its received skbs than the mt7921 needs for its
      SDIO headers.
      
      Here is an example stack trace of this panic on Raspberry Pi OS Lite
      2023-02-21 running kernel 6.1.24+ [1]:
      
       skb_panic from skb_push+0x44/0x48
       skb_push from mt7921_usb_sdio_tx_prepare_skb+0xd4/0x190 [mt7921_common]
       mt7921_usb_sdio_tx_prepare_skb [mt7921_common] from mt76u_tx_queue_skb+0x94/0x1d0 [mt76_usb]
       mt76u_tx_queue_skb [mt76_usb] from __mt76_tx_queue_skb+0x4c/0xc8 [mt76]
       __mt76_tx_queue_skb [mt76] from mt76_txq_schedule.part.0+0x13c/0x398 [mt76]
       mt76_txq_schedule.part.0 [mt76] from mt76_txq_schedule_all+0x24/0x30 [mt76]
       mt76_txq_schedule_all [mt76] from mt7921_tx_worker+0x58/0xf4 [mt7921_common]
       mt7921_tx_worker [mt7921_common] from __mt76_worker_fn+0x9c/0xec [mt76]
       __mt76_worker_fn [mt76] from kthread+0xbc/0xe0
       kthread from ret_from_fork+0x14/0x34
      
      After this fix, bridging the mt7921 interface works fine on both of my
      previously problematic systems.
      
      [1] https://github.com/raspberrypi/firmware/tree/5c276f55a4b21345cd4d6200a504ee991851ff7a
      
      Link: https://github.com/openwrt/openwrt/issues/11796
      Signed-off-by: default avatarMatt Whitlock <kernel@mattwhitlock.name>
      Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5c8bbb79
    • Dmitry Antipov's avatar
      wifi: mwifiex: fix fortify warning · 4f621fe1
      Dmitry Antipov authored
      [ Upstream commit dcce94b8
      
       ]
      
      When compiling with gcc 13.1 and CONFIG_FORTIFY_SOURCE=y,
      I've noticed the following:
      
      In function ‘fortify_memcpy_chk’,
          inlined from ‘mwifiex_construct_tdls_action_frame’ at drivers/net/wireless/marvell/mwifiex/tdls.c:765:3,
          inlined from ‘mwifiex_send_tdls_action_frame’ at drivers/net/wireless/marvell/mwifiex/tdls.c:856:6:
      ./include/linux/fortify-string.h:529:25: warning: call to ‘__read_overflow2_field’
      declared with attribute warning: detected read beyond size of field (2nd parameter);
      maybe use struct_group()? [-Wattribute-warning]
        529 |                         __read_overflow2_field(q_size_field, size);
            |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      The compiler actually complains on:
      
      memmove(pos + ETH_ALEN, &mgmt->u.action.category,
      	sizeof(mgmt->u.action.u.tdls_discover_resp));
      
      and it happens because the fortification logic interprets this
      as an attempt to overread 1-byte 'u.action.category' member of
      'struct ieee80211_mgmt'. To silence this warning, it's enough
      to pass an address of 'u.action' itself instead of an address
      of its first member.
      
      This also fixes an improper usage of 'sizeof()'. Since 'skb' is
      extended with 'sizeof(mgmt->u.action.u.tdls_discover_resp) + 1'
      bytes (where 1 is actually 'sizeof(mgmt->u.action.category)'),
      I assume that the same number of bytes should be copied.
      
      Suggested-by: default avatarBrian Norris <briannorris@chromium.org>
      Signed-off-by: default avatarDmitry Antipov <dmantipov@yandex.ru>
      Reviewed-by: default avatarBrian Norris <briannorris@chromium.org>
      Signed-off-by: default avatarKalle Valo <kvalo@kernel.org>
      Link: https://lore.kernel.org/r/20230629085115.180499-2-dmantipov@yandex.ru
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4f621fe1
    • Dongliang Mu's avatar
      wifi: ath9k: fix printk specifier · 2640a8e5
      Dongliang Mu authored
      [ Upstream commit 061115fb
      
       ]
      
      Smatch reports:
      
      ath_pci_probe() warn: argument 4 to %lx specifier is cast from pointer
      ath_ahb_probe() warn: argument 4 to %lx specifier is cast from pointer
      
      Fix it by modifying %lx to %p in the printk format string.
      
      Note that with this change, the pointer address will be printed as a
      hashed value by default. This is appropriate because the kernel
      should not leak kernel pointers to user space in an informational
      message. If someone wants to see the real address for debugging
      purposes, this can be achieved with the no_hash_pointers kernel option.
      
      Signed-off-by: default avatarDongliang Mu <dzm91@hust.edu.cn>
      Acked-by: default avatarToke Høiland-Jørgensen <toke@toke.dk>
      Signed-off-by: default avatarKalle Valo <quic_kvalo@quicinc.com>
      Link: https://lore.kernel.org/r/20230723040403.296723-1-dzm91@hust.edu.cn
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2640a8e5
    • Dmitry Antipov's avatar
      wifi: ath9k: fix fortify warnings · 1800a27a
      Dmitry Antipov authored
      [ Upstream commit 810e41ce
      
       ]
      
      When compiling with gcc 13.1 and CONFIG_FORTIFY_SOURCE=y,
      I've noticed the following:
      
      In function ‘fortify_memcpy_chk’,
          inlined from ‘ath_tx_complete_aggr’ at drivers/net/wireless/ath/ath9k/xmit.c:556:4,
          inlined from ‘ath_tx_process_buffer’ at drivers/net/wireless/ath/ath9k/xmit.c:773:3:
      ./include/linux/fortify-string.h:529:25: warning: call to ‘__read_overflow2_field’
      declared with attribute warning: detected read beyond size of field (2nd parameter);
      maybe use struct_group()? [-Wattribute-warning]
        529 |                         __read_overflow2_field(q_size_field, size);
            |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      In function ‘fortify_memcpy_chk’,
          inlined from ‘ath_tx_count_frames’ at drivers/net/wireless/ath/ath9k/xmit.c:473:3,
          inlined from ‘ath_tx_complete_aggr’ at drivers/net/wireless/ath/ath9k/xmit.c:572:2,
          inlined from ‘ath_tx_process_buffer’ at drivers/net/wireless/ath/ath9k/xmit.c:773:3:
      ./include/linux/fortify-string.h:529:25: warning: call to ‘__read_overflow2_field’
      declared with attribute warning: detected read beyond size of field (2nd parameter);
      maybe use struct_group()? [-Wattribute-warning]
        529 |                         __read_overflow2_field(q_size_field, size);
            |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      In both cases, the compiler complains on:
      
      memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3);
      
      which is the legal way to copy both 'ba_low' and following 'ba_high'
      members of 'struct ath_tx_status' at once (that is, issue one 8-byte
      'memcpy()' for two 4-byte fields). Since the fortification logic seems
      interprets this trick as an attempt to overread 4-byte 'ba_low', silence
      relevant warnings by using the convenient 'struct_group()' quirk.
      
      Suggested-by: default avatarJohannes Berg <johannes@sipsolutions.net>
      Signed-off-by: default avatarDmitry Antipov <dmantipov@yandex.ru>
      Acked-by: default avatarToke Høiland-Jørgensen <toke@toke.dk>
      Signed-off-by: default avatarKalle Valo <quic_kvalo@quicinc.com>
      Link: https://lore.kernel.org/r/20230620080855.396851-2-dmantipov@yandex.ru
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1800a27a
    • Wojciech Drewek's avatar
      ice: Don't tx before switchdev is fully configured · 5760a72b
      Wojciech Drewek authored
      [ Upstream commit 7aa529a6
      
       ]
      
      There is possibility that ice_eswitch_port_start_xmit might be
      called while some resources are still not allocated which might
      cause NULL pointer dereference. Fix this by checking if switchdev
      configuration was finished.
      
      Reviewed-by: default avatarPaul Menzel <pmenzel@molgen.mpg.de>
      Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
      Signed-off-by: default avatarWojciech Drewek <wojciech.drewek@intel.com>
      Tested-by: default avatarSujai Buvaneswaran <sujai.buvaneswaran@intel.com>
      Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5760a72b
    • Azeem Shaikh's avatar
      crypto: lrw,xts - Replace strlcpy with strscpy · ad58d7eb
      Azeem Shaikh authored
      [ Upstream commit babb80b3
      
       ]
      
      strlcpy() reads the entire source buffer first.
      This read may exceed the destination size limit.
      This is both inefficient and can lead to linear read
      overflows if a source string is not NUL-terminated [1].
      In an effort to remove strlcpy() completely [2], replace
      strlcpy() here with strscpy().
      
      Direct replacement is safe here since return value of -errno
      is used to check for truncation instead of sizeof(dest).
      
      [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
      [2] https://github.com/KSPP/linux/issues/89
      
      Signed-off-by: default avatarAzeem Shaikh <azeemshaikh38@gmail.com>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ad58d7eb
    • Jiri Pirko's avatar
      devlink: remove reload failed checks in params get/set callbacks · ac70101e
      Jiri Pirko authored
      [ Upstream commit 633d76ad ]
      
      The checks in question were introduced by:
      commit 6b4db2e5 ("devlink: Fix use-after-free after a failed reload").
      That fixed an issue of reload with mlxsw driver.
      
      Back then, that was a valid fix, because there was a limitation
      in place that prevented drivers from registering/unregistering params
      when devlink instance was registered.
      
      It was possible to do the fix differently by changing drivers to
      register/unregister params in appropriate places making sure the ops
      operate only on memory which is allocated and initialized. But that,
      as a dependency, would require to remove the limitation mentioned above.
      
      Eventually, this limitation was lifted by:
      commit 1d18bb1a ("devlink: allow registering parameters after the instance")
      
      Also, the alternative fix (which also fixed another issue) was done by:
      commit 74cbc3c0
      
       ("mlxsw: spectrum_acl_tcam: Move devlink param to TCAM code").
      
      Therefore, the checks are no longer relevant. Each driver should make
      sure to have the params registered only when the memory the ops
      are working with is allocated and initialized.
      
      So remove the checks.
      
      Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
      Reviewed-by: default avatarIdo Schimmel <idosch@nvidia.com>
      Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ac70101e
    • @wuzhangjin's avatar
      selftests/nolibc: fix up kernel parameters support · a0300edc
      @wuzhangjin authored
      [ Upstream commit c388c992
      
       ]
      
      kernel parameters allow pass two types of strings, one type is like
      'noapic', another type is like 'panic=5', the first type is passed as
      arguments of the init program, the second type is passed as environment
      variables of the init program.
      
      when users pass kernel parameters like this:
      
          noapic NOLIBC_TEST=syscall
      
      our nolibc-test program will use the test setting from argv[1] and
      ignore the one from NOLIBC_TEST environment variable, and at last, it
      will print the following line and ignore the whole test setting.
      
          Ignoring unknown test name 'noapic'
      
      reversing the parsing order does solve the above issue:
      
          test = getenv("NOLIBC_TEST");
          if (test)
              test = argv[1];
      
      but it still doesn't work with such kernel parameters (without
      NOLIBC_TEST environment variable):
      
          noapic FOO=bar
      
      To support all of the potential kernel parameters, let's verify the test
      setting from both of argv[1] and NOLIBC_TEST environment variable.
      
      Reviewed-by: default avatarThomas Weißschuh <linux@weissschuh.net>
      Signed-off-by: default avatarZhangjin Wu <falcon@tinylab.org>
      Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a0300edc
    • Mario Limonciello's avatar
      ACPI: x86: s2idle: Catch multiple ACPI_TYPE_PACKAGE objects · 1ea7e478
      Mario Limonciello authored
      [ Upstream commit 883cf0d4
      
       ]
      
      If a badly constructed firmware includes multiple `ACPI_TYPE_PACKAGE`
      objects while evaluating the AMD LPS0 _DSM, there will be a memory
      leak.  Explicitly guard against this.
      
      Suggested-by: default avatarBjorn Helgaas <helgaas@kernel.org>
      Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1ea7e478
    • Tomislav Novak's avatar
      hw_breakpoint: fix single-stepping when using bpf_overflow_handler · dc1d81ee
      Tomislav Novak authored
      [ Upstream commit d11a6987
      
       ]
      
      Arm platforms use is_default_overflow_handler() to determine if the
      hw_breakpoint code should single-step over the breakpoint trigger or
      let the custom handler deal with it.
      
      Since bpf_overflow_handler() currently isn't recognized as a default
      handler, attaching a BPF program to a PERF_TYPE_BREAKPOINT event causes
      it to keep firing (the instruction triggering the data abort exception
      is never skipped). For example:
      
        # bpftrace -e 'watchpoint:0x10000:4:w { print("hit") }' -c ./test
        Attaching 1 probe...
        hit
        hit
        [...]
        ^C
      
      (./test performs a single 4-byte store to 0x10000)
      
      This patch replaces the check with uses_default_overflow_handler(),
      which accounts for the bpf_overflow_handler() case by also testing
      if one of the perf_event_output functions gets invoked indirectly,
      via orig_default_handler.
      
      Signed-off-by: default avatarTomislav Novak <tnovak@meta.com>
      Tested-by: Samuel Gosselin <sgosselin@google.com> # arm64
      Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/linux-arm-kernel/20220923203644.2731604-1-tnovak@fb.com/
      Link: https://lore.kernel.org/r/20230605191923.1219974-1-tnovak@meta.com
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      dc1d81ee
    • Xu Yang's avatar
      perf/imx_ddr: speed up overflow frequency of cycle · d42d342d
      Xu Yang authored
      [ Upstream commit e89ecd83
      
       ]
      
      For i.MX8MP, we cannot ensure that cycle counter overflow occurs at least
      4 times as often as other events. Due to byte counters will count for any
      event configured, it will overflow more often. And if byte counters
      overflow that related counters would stop since they share the
      COUNTER_CNTL. We can speed up cycle counter overflow frequency by setting
      counter parameter (CP) field of cycle counter. In this way, we can avoid
      stop counting byte counters when interrupt didn't come and the byte
      counters can be fetched or updated from each cycle counter overflow
      interrupt.
      
      Because we initialize CP filed to shorten counter0 overflow time, the cycle
      counter will start couting from a fixed/base value each time. We need to
      remove the base from the result too. Therefore, we could get precise result
      from cycle counter.
      
      Signed-off-by: default avatarXu Yang <xu.yang_2@nxp.com>
      Reviewed-by: default avatarFrank Li <Frank.Li@nxp.com>
      Link: https://lore.kernel.org/r/20230811015438.1999307b
      
      -1-xu.yang_2@nxp.com
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d42d342d
    • Yicong Yang's avatar
      perf/smmuv3: Enable HiSilicon Erratum 162001900 quirk for HIP08/09 · 9d9b5cbc
      Yicong Yang authored
      [ Upstream commit 0242737d
      
       ]
      
      Some HiSilicon SMMU PMCG suffers the erratum 162001900 that the PMU
      disable control sometimes fail to disable the counters. This will lead
      to error or inaccurate data since before we enable the counters the
      counter's still counting for the event used in last perf session.
      
      This patch tries to fix this by hardening the global disable process.
      Before disable the PMU, writing an invalid event type (0xffff) to
      focibly stop the counters. Correspondingly restore each events on
      pmu::pmu_enable().
      
      Signed-off-by: default avatarYicong Yang <yangyicong@hisilicon.com>
      Link: https://lore.kernel.org/r/20230814124012.58013-1-yangyicong@huawei.com
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9d9b5cbc
    • Jiri Slaby (SUSE)'s avatar
      ACPI: video: Add backlight=native DMI quirk for Lenovo Ideapad Z470 · 4cb0612c
      Jiri Slaby (SUSE) authored
      [ Upstream commit 96b709be
      
       ]
      
      The Lenovo Ideapad Z470 predates Windows 8, so it defaults to using
      acpi_video for backlight control. But this is not functional on this
      model.
      
      Add a DMI quirk to use the native backlight interface which works.
      
      Link: https://bugzilla.suse.com/show_bug.cgi?id=1208724
      Signed-off-by: default avatarJiri Slaby (SUSE) <jirislaby@kernel.org>
      Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4cb0612c
    • Paul E. McKenney's avatar
      scftorture: Forgive memory-allocation failure if KASAN · 9f10b4eb
      Paul E. McKenney authored
      [ Upstream commit 013608cd
      
       ]
      
      Kernels built with CONFIG_KASAN=y quarantine newly freed memory in order
      to better detect use-after-free errors.  However, this can exhaust memory
      more quickly in allocator-heavy tests, which can result in spurious
      scftorture failure.  This commit therefore forgives memory-allocation
      failure in kernels built with CONFIG_KASAN=y, but continues counting
      the errors for use in detailed test-result analyses.
      
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9f10b4eb
    • Zqiang's avatar
      rcuscale: Move rcu_scale_writer() schedule_timeout_uninterruptible() to _idle() · 83ed0cdb
      Zqiang authored
      [ Upstream commit e60c122a
      
       ]
      
      The rcuscale.holdoff module parameter can be used to delay the start
      of rcu_scale_writer() kthread.  However, the hung-task timeout will
      trigger when the timeout specified by rcuscale.holdoff is greater than
      hung_task_timeout_secs:
      
      runqemu kvm nographic slirp qemuparams="-smp 4 -m 2048M"
      bootparams="rcuscale.shutdown=0 rcuscale.holdoff=300"
      
      [  247.071753] INFO: task rcu_scale_write:59 blocked for more than 122 seconds.
      [  247.072529]       Not tainted 6.4.0-rc1-00134-gb9ed6de8d4ff #7
      [  247.073400] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      [  247.074331] task:rcu_scale_write state:D stack:30144 pid:59    ppid:2      flags:0x00004000
      [  247.075346] Call Trace:
      [  247.075660]  <TASK>
      [  247.075965]  __schedule+0x635/0x1280
      [  247.076448]  ? __pfx___schedule+0x10/0x10
      [  247.076967]  ? schedule_timeout+0x2dc/0x4d0
      [  247.077471]  ? __pfx_lock_release+0x10/0x10
      [  247.078018]  ? enqueue_timer+0xe2/0x220
      [  247.078522]  schedule+0x84/0x120
      [  247.078957]  schedule_timeout+0x2e1/0x4d0
      [  247.079447]  ? __pfx_schedule_timeout+0x10/0x10
      [  247.080032]  ? __pfx_rcu_scale_writer+0x10/0x10
      [  247.080591]  ? __pfx_process_timeout+0x10/0x10
      [  247.081163]  ? __pfx_sched_set_fifo_low+0x10/0x10
      [  247.081760]  ? __pfx_rcu_scale_writer+0x10/0x10
      [  247.082287]  rcu_scale_writer+0x6b1/0x7f0
      [  247.082773]  ? mark_held_locks+0x29/0xa0
      [  247.083252]  ? __pfx_rcu_scale_writer+0x10/0x10
      [  247.083865]  ? __pfx_rcu_scale_writer+0x10/0x10
      [  247.084412]  kthread+0x179/0x1c0
      [  247.084759]  ? __pfx_kthread+0x10/0x10
      [  247.085098]  ret_from_fork+0x2c/0x50
      [  247.085433]  </TASK>
      
      This commit therefore replaces schedule_timeout_uninterruptible() with
      schedule_timeout_idle().
      
      Signed-off-by: default avatarZqiang <qiang.zhang1211@gmail.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      83ed0cdb
    • Wander Lairson Costa's avatar
      kernel/fork: beware of __put_task_struct() calling context · 3b1107ab
      Wander Lairson Costa authored
      [ Upstream commit d243b344
      
       ]
      
      Under PREEMPT_RT, __put_task_struct() indirectly acquires sleeping
      locks. Therefore, it can't be called from an non-preemptible context.
      
      One practical example is splat inside inactive_task_timer(), which is
      called in a interrupt context:
      
        CPU: 1 PID: 2848 Comm: life Kdump: loaded Tainted: G W ---------
         Hardware name: HP ProLiant DL388p Gen8, BIOS P70 07/15/2012
         Call Trace:
         dump_stack_lvl+0x57/0x7d
         mark_lock_irq.cold+0x33/0xba
         mark_lock+0x1e7/0x400
         mark_usage+0x11d/0x140
         __lock_acquire+0x30d/0x930
         lock_acquire.part.0+0x9c/0x210
         rt_spin_lock+0x27/0xe0
         refill_obj_stock+0x3d/0x3a0
         kmem_cache_free+0x357/0x560
         inactive_task_timer+0x1ad/0x340
         __run_hrtimer+0x8a/0x1a0
         __hrtimer_run_queues+0x91/0x130
         hrtimer_interrupt+0x10f/0x220
         __sysvec_apic_timer_interrupt+0x7b/0xd0
         sysvec_apic_timer_interrupt+0x4f/0xd0
         asm_sysvec_apic_timer_interrupt+0x12/0x20
         RIP: 0033:0x7fff196bf6f5
      
      Instead of calling __put_task_struct() directly, we defer it using
      call_rcu(). A more natural approach would use a workqueue, but since
      in PREEMPT_RT, we can't allocate dynamic memory from atomic context,
      the code would become more complex because we would need to put the
      work_struct instance in the task_struct and initialize it when we
      allocate a new task_struct.
      
      The issue is reproducible with stress-ng:
      
        while true; do
            stress-ng --sched deadline --sched-period 1000000000 \
      	      --sched-runtime 800000000 --sched-deadline \
      	      1000000000 --mmapfork 23 -t 20
        done
      
      Reported-by: default avatarHu Chunyu <chuhu@redhat.com>
      Suggested-by: default avatarOleg Nesterov <oleg@redhat.com>
      Suggested-by: default avatarValentin Schneider <vschneid@redhat.com>
      Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarWander Lairson Costa <wander@redhat.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20230614122323.37957-2-wander@redhat.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3b1107ab
    • Abhishek Mainkar's avatar
      ACPICA: Add AML_NO_OPERAND_RESOLVE flag to Timer · e1f68693
      Abhishek Mainkar authored
      [ Upstream commit 3a21ffdb
      
       ]
      
      ACPICA commit 90310989a0790032f5a0140741ff09b545af4bc5
      
      According to the ACPI specification 19.6.134, no argument is required to be passed for ASL Timer instruction. For taking care of no argument, AML_NO_OPERAND_RESOLVE flag is added to ASL Timer instruction opcode.
      
      When ASL timer instruction interpreted by ACPI interpreter, getting error. After adding AML_NO_OPERAND_RESOLVE flag to ASL Timer instruction opcode, issue is not observed.
      
      =============================================================
      UBSAN: array-index-out-of-bounds in acpica/dswexec.c:401:12 index -1 is out of range for type 'union acpi_operand_object *[9]'
      CPU: 37 PID: 1678 Comm: cat Not tainted
      6.0.0-dev-th500-6.0.y-1+bcf8c46459e407-generic-64k
      HW name: NVIDIA BIOS v1.1.1-d7acbfc-dirty 12/19/2022 Call trace:
       dump_backtrace+0xe0/0x130
       show_stack+0x20/0x60
       dump_stack_lvl+0x68/0x84
       dump_stack+0x18/0x34
       ubsan_epilogue+0x10/0x50
       __ubsan_handle_out_of_bounds+0x80/0x90
       acpi_ds_exec_end_op+0x1bc/0x6d8
       acpi_ps_parse_loop+0x57c/0x618
       acpi_ps_parse_aml+0x1e0/0x4b4
       acpi_ps_execute_method+0x24c/0x2b8
       acpi_ns_evaluate+0x3a8/0x4bc
       acpi_evaluate_object+0x15c/0x37c
       acpi_evaluate_integer+0x54/0x15c
       show_power+0x8c/0x12c [acpi_power_meter]
      
      Link: https://github.com/acpica/acpica/commit/90310989
      Signed-off-by: default avatarAbhishek Mainkar <abmainkar@nvidia.com>
      Signed-off-by: default avatarBob Moore <robert.moore@intel.com>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e1f68693
    • Will Shiu's avatar
      locks: fix KASAN: use-after-free in trace_event_raw_event_filelock_lock · 34bff6d8
      Will Shiu authored
      [ Upstream commit 74f6f591
      
       ]
      
      As following backtrace, the struct file_lock request , in posix_lock_inode
      is free before ftrace function using.
      Replace the ftrace function ahead free flow could fix the use-after-free
      issue.
      
      [name:report&]===============================================
      BUG:KASAN: use-after-free in trace_event_raw_event_filelock_lock+0x80/0x12c
      [name:report&]Read at addr f6ffff8025622620 by task NativeThread/16753
      [name:report_hw_tags&]Pointer tag: [f6], memory tag: [fe]
      [name:report&]
      BT:
      Hardware name: MT6897 (DT)
      Call trace:
       dump_backtrace+0xf8/0x148
       show_stack+0x18/0x24
       dump_stack_lvl+0x60/0x7c
       print_report+0x2c8/0xa08
       kasan_report+0xb0/0x120
       __do_kernel_fault+0xc8/0x248
       do_bad_area+0x30/0xdc
       do_tag_check_fault+0x1c/0x30
       do_mem_abort+0x58/0xbc
       el1_abort+0x3c/0x5c
       el1h_64_sync_handler+0x54/0x90
       el1h_64_sync+0x68/0x6c
       trace_event_raw_event_filelock_lock+0x80/0x12c
       posix_lock_inode+0xd0c/0xd60
       do_lock_file_wait+0xb8/0x190
       fcntl_setlk+0x2d8/0x440
      ...
      [name:report&]
      [name:report&]Allocated by task 16752:
      ...
       slab_post_alloc_hook+0x74/0x340
       kmem_cache_alloc+0x1b0/0x2f0
       posix_lock_inode+0xb0/0xd60
      ...
       [name:report&]
       [name:report&]Freed by task 16752:
      ...
        kmem_cache_free+0x274/0x5b0
        locks_dispose_list+0x3c/0x148
        posix_lock_inode+0xc40/0xd60
        do_lock_file_wait+0xb8/0x190
        fcntl_setlk+0x2d8/0x440
        do_fcntl+0x150/0xc18
      ...
      
      Signed-off-by: default avatarWill Shiu <Will.Shiu@mediatek.com>
      Signed-off-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      34bff6d8
    • Qu Wenruo's avatar
      btrfs: output extra debug info if we failed to find an inline backref · 28062cd6
      Qu Wenruo authored
      [ Upstream commit 7f72f505
      
       ]
      
      [BUG]
      Syzbot reported several warning triggered inside
      lookup_inline_extent_backref().
      
      [CAUSE]
      As usual, the reproducer doesn't reliably trigger locally here, but at
      least we know the WARN_ON() is triggered when an inline backref can not
      be found, and it can only be triggered when @insert is true. (I.e.
      inserting a new inline backref, which means the backref should already
      exist)
      
      [ENHANCEMENT]
      After the WARN_ON(), dump all the parameters and the extent tree
      leaf to help debug.
      
      Link: https://syzkaller.appspot.com/bug?extid=d6f9ff86c1d804ba2bc6
      Signed-off-by: default avatarQu Wenruo <wqu@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>
      28062cd6
    • Fedor Pchelkin's avatar
      autofs: fix memory leak of waitqueues in autofs_catatonic_mode · 726deae6
      Fedor Pchelkin authored
      [ Upstream commit ccbe77f7
      
       ]
      
      Syzkaller reports a memory leak:
      
      BUG: memory leak
      unreferenced object 0xffff88810b279e00 (size 96):
        comm "syz-executor399", pid 3631, jiffies 4294964921 (age 23.870s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 08 9e 27 0b 81 88 ff ff  ..........'.....
          08 9e 27 0b 81 88 ff ff 00 00 00 00 00 00 00 00  ..'.............
        backtrace:
          [<ffffffff814cfc90>] kmalloc_trace+0x20/0x90 mm/slab_common.c:1046
          [<ffffffff81bb75ca>] kmalloc include/linux/slab.h:576 [inline]
          [<ffffffff81bb75ca>] autofs_wait+0x3fa/0x9a0 fs/autofs/waitq.c:378
          [<ffffffff81bb88a7>] autofs_do_expire_multi+0xa7/0x3e0 fs/autofs/expire.c:593
          [<ffffffff81bb8c33>] autofs_expire_multi+0x53/0x80 fs/autofs/expire.c:619
          [<ffffffff81bb6972>] autofs_root_ioctl_unlocked+0x322/0x3b0 fs/autofs/root.c:897
          [<ffffffff81bb6a95>] autofs_root_ioctl+0x25/0x30 fs/autofs/root.c:910
          [<ffffffff81602a9c>] vfs_ioctl fs/ioctl.c:51 [inline]
          [<ffffffff81602a9c>] __do_sys_ioctl fs/ioctl.c:870 [inline]
          [<ffffffff81602a9c>] __se_sys_ioctl fs/ioctl.c:856 [inline]
          [<ffffffff81602a9c>] __x64_sys_ioctl+0xfc/0x140 fs/ioctl.c:856
          [<ffffffff84608225>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
          [<ffffffff84608225>] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
          [<ffffffff84800087>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      autofs_wait_queue structs should be freed if their wait_ctr becomes zero.
      Otherwise they will be lost.
      
      In this case an AUTOFS_IOC_EXPIRE_MULTI ioctl is done, then a new
      waitqueue struct is allocated in autofs_wait(), its initial wait_ctr
      equals 2. After that wait_event_killable() is interrupted (it returns
      -ERESTARTSYS), so that 'wq->name.name == NULL' condition may be not
      satisfied. Actually, this condition can be satisfied when
      autofs_wait_release() or autofs_catatonic_mode() is called and, what is
      also important, wait_ctr is decremented in those places. Upon the exit of
      autofs_wait(), wait_ctr is decremented to 1. Then the unmounting process
      begins: kill_sb calls autofs_catatonic_mode(), which should have freed the
      waitqueues, but it only decrements its usage counter to zero which is not
      a correct behaviour.
      
      edit:imk
      This description is of course not correct. The umount performed as a result
      of an expire is a umount of a mount that has been automounted, it's not the
      autofs mount itself. They happen independently, usually after everything
      mounted within the autofs file system has been expired away. If everything
      hasn't been expired away the automount daemon can still exit leaving mounts
      in place. But expires done in both cases will result in a notification that
      calls autofs_wait_release() with a result status. The problem case is the
      summary execution of of the automount daemon. In this case any waiting
      processes won't be woken up until either they are terminated or the mount
      is umounted.
      end edit: imk
      
      So in catatonic mode we should free waitqueues which counter becomes zero.
      
      edit: imk
      Initially I was concerned that the calling of autofs_wait_release() and
      autofs_catatonic_mode() was not mutually exclusive but that can't be the
      case (obviously) because the queue entry (or entries) is removed from the
      list when either of these two functions are called. Consequently the wait
      entry will be freed by only one of these functions or by the woken process
      in autofs_wait() depending on the order of the calls.
      end edit: imk
      
      Reported-by: default avatar <syzbot+5e53f70e69ff0c0a1c0c@syzkaller.appspotmail.com>
      Suggested-by: default avatarTakeshi Misawa <jeliantsurux@gmail.com>
      Signed-off-by: default avatarFedor Pchelkin <pchelkin@ispras.ru>
      Signed-off-by: default avatarAlexey Khoroshilov <khoroshilov@ispras.ru>
      Signed-off-by: default avatarIan Kent <raven@themaw.net>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Andrei Vagin <avagin@gmail.com>
      Cc: autofs@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Message-Id: <169112719161.7590.6700123246297365841.stgit@donald.themaw.net>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      726deae6
  2. Sep 19, 2023