1. 05 Feb, 2020 40 commits
    • Arnaud Pouliquen's avatar
      ASoC: sti: fix possible sleep-in-atomic · 3403f865
      Arnaud Pouliquen authored
      [ Upstream commit ce780a47
      
       ]
      
      Change mutex and spinlock management to avoid sleep
      in atomic issue.
      Signed-off-by: default avatarArnaud Pouliquen <arnaud.pouliquen@st.com>
      Link: https://lore.kernel.org/r/20200113100400.30472-1-arnaud.pouliquen@st.com
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3403f865
    • Manfred Rudigier's avatar
      igb: Fix SGMII SFP module discovery for 100FX/LX. · 5c273c3a
      Manfred Rudigier authored
      [ Upstream commit 5365ec1a
      
       ]
      
      Changing the link mode should also be done for 100BaseFX SGMII modules,
      otherwise they just don't work when the default link mode in CTRL_EXT
      coming from the EEPROM is SERDES.
      
      Additionally 100Base-LX SGMII SFP modules are also supported now, which
      was not the case before.
      
      Tested with an i210 using Flexoptix S.1303.2M.G 100FX and
      S.1303.10.G 100LX SGMII SFP modules.
      Signed-off-by: default avatarManfred Rudigier <manfred.rudigier@omicronenergy.com>
      Tested-by: default avatarAaron Brown <aaron.f.brown@intel.com>
      Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5c273c3a
    • Cambda Zhu's avatar
      ixgbe: Fix calculation of queue with VFs and flow director on interface flap · 0350ed7b
      Cambda Zhu authored
      [ Upstream commit 4fad78ad
      
       ]
      
      This patch fixes the calculation of queue when we restore flow director
      filters after resetting adapter. In ixgbe_fdir_filter_restore(), filter's
      vf may be zero which makes the queue outside of the rx_ring array.
      
      The calculation is changed to the same as ixgbe_add_ethtool_fdir_entry().
      Signed-off-by: default avatarCambda Zhu <cambda@linux.alibaba.com>
      Tested-by: default avatarAndrew Bowers <andrewx.bowers@intel.com>
      Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0350ed7b
    • Radoslaw Tyl's avatar
      ixgbevf: Remove limit of 10 entries for unicast filter list · ca60e5ca
      Radoslaw Tyl authored
      [ Upstream commit aa604651 ]
      
      Currently, though the FDB entry is added to VF, it does not appear in
      RAR filters. VF driver only allows to add 10 entries. Attempting to add
      another causes an error. This patch removes limitation and allows use of
      all free RAR entries for the FDB if needed.
      
      Fixes: 46ec20ff
      
       ("ixgbevf: Add macvlan support in the set rx mode op")
      Signed-off-by: default avatarRadoslaw Tyl <radoslawx.tyl@intel.com>
      Acked-by: default avatarPaul Menzel <pmenzel@molgen.mpg.de>
      Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ca60e5ca
    • Lubomir Rintel's avatar
      clk: mmp2: Fix the order of timer mux parents · aecd1fe0
      Lubomir Rintel authored
      [ Upstream commit 8bea5ac0 ]
      
      Determined empirically, no documentation is available.
      
      The OLPC XO-1.75 laptop used parent 1, that one being VCTCXO/4 (65MHz), but
      thought it's a VCTCXO/2 (130MHz). The mmp2 timer driver, not knowing
      what is going on, ended up just dividing the rate as of
      commit f36797ee ("ARM: mmp/mmp2: dt: enable the clock")'
      
      Link: https://lore.kernel.org/r/20191218190454.420358-3-lkundrak@v3.sk
      
      Signed-off-by: default avatarLubomir Rintel <lkundrak@v3.sk>
      Acked-by: default avatarStephen Boyd <sboyd@kernel.org>
      Signed-off-by: default avatarOlof Johansson <olof@lixom.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      aecd1fe0
    • Markus Theil's avatar
      mac80211: mesh: restrict airtime metric to peered established plinks · 89f54ffd
      Markus Theil authored
      [ Upstream commit 02a61449
      
       ]
      
      The following warning is triggered every time an unestablished mesh peer
      gets dumped. Checks if a peer link is established before retrieving the
      airtime link metric.
      
      [ 9563.022567] WARNING: CPU: 0 PID: 6287 at net/mac80211/mesh_hwmp.c:345
                     airtime_link_metric_get+0xa2/0xb0 [mac80211]
      [ 9563.022697] Hardware name: PC Engines apu2/apu2, BIOS v4.10.0.3
      [ 9563.022756] RIP: 0010:airtime_link_metric_get+0xa2/0xb0 [mac80211]
      [ 9563.022838] Call Trace:
      [ 9563.022897]  sta_set_sinfo+0x936/0xa10 [mac80211]
      [ 9563.022964]  ieee80211_dump_station+0x6d/0x90 [mac80211]
      [ 9563.023062]  nl80211_dump_station+0x154/0x2a0 [cfg80211]
      [ 9563.023120]  netlink_dump+0x17b/0x370
      [ 9563.023130]  netlink_recvmsg+0x2a4/0x480
      [ 9563.023140]  ____sys_recvmsg+0xa6/0x160
      [ 9563.023154]  ___sys_recvmsg+0x93/0xe0
      [ 9563.023169]  __sys_recvmsg+0x7e/0xd0
      [ 9563.023210]  do_syscall_64+0x4e/0x140
      [ 9563.023217]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      Signed-off-by: default avatarMarkus Theil <markus.theil@tu-ilmenau.de>
      Link: https://lore.kernel.org/r/20191203180644.70653-1-markus.theil@tu-ilmenau.de
      
      
      [rewrite commit message]
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      89f54ffd
    • Dave Gerlach's avatar
      soc: ti: wkup_m3_ipc: Fix race condition with rproc_boot · 852c2bb9
      Dave Gerlach authored
      [ Upstream commit 03729cfa
      
       ]
      
      Any user of wkup_m3_ipc calls wkup_m3_ipc_get to get a handle and this
      checks the value of the static variable m3_ipc_state to see if the
      wkup_m3 is ready. Currently this is populated during probe before
      rproc_boot has been called, meaning there is a window of time that
      wkup_m3_ipc_get can return a valid handle but the wkup_m3 itself is not
      ready, leading to invalid IPC calls to the wkup_m3 and system
      instability.
      
      To avoid this, move the population of the m3_ipc_state variable until
      after rproc_boot has succeeded to guarantee a valid and usable handle
      is always returned.
      Reported-by: default avatarSuman Anna <s-anna@ti.com>
      Signed-off-by: default avatarDave Gerlach <d-gerlach@ti.com>
      Acked-by: default avatarSantosh Shilimkar <ssantosh@kernel.org>
      Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      852c2bb9
    • Kishon Vijay Abraham I's avatar
      ARM: dts: beagle-x15-common: Model 5V0 regulator · f795e1f7
      Kishon Vijay Abraham I authored
      [ Upstream commit e17e7c49
      
       ]
      
      On am57xx-beagle-x15, 5V0 is connected to P16, P17, P18 and P19
      connectors. On am57xx-evm, 5V0 regulator is used to get 3V6 regulator
      which is connected to the COMQ port. Model 5V0 regulator here in order
      for it to be used in am57xx-evm to model 3V6 regulator.
      Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
      Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f795e1f7
    • Marek Szyprowski's avatar
      ARM: dts: sun8i: a83t: Correct USB3503 GPIOs polarity · 719e8e93
      Marek Szyprowski authored
      [ Upstream commit 1c226017
      
       ]
      
      Current USB3503 driver ignores GPIO polarity and always operates as if the
      GPIO lines were flagged as ACTIVE_HIGH. Fix the polarity for the existing
      USB3503 chip applications to match the chip specification and common
      convention for naming the pins. The only pin, which has to be ACTIVE_LOW
      is the reset pin. The remaining are ACTIVE_HIGH. This change allows later
      to fix the USB3503 driver to properly use generic GPIO bindings and read
      polarity from DT.
      Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      719e8e93
    • Lee Jones's avatar
      media: si470x-i2c: Move free() past last use of 'radio' · c7d81222
      Lee Jones authored
      A pointer to 'struct si470x_device' is currently used after free:
      
        drivers/media/radio/si470x/radio-si470x-i2c.c:462:25-30: ERROR: reference
          preceded by free on line 460
      
      Shift the call to free() down past its final use.
      
      NB: Not sending to Mainline, since the problem does not exist there, it was
      caused by the backport of 2df200ab
      
       ("media: si470x-i2c: add missed
      operations in remove") to the stable trees.
      
      Cc: <stable@vger.kernel.org> # v3.18+
      Reported-by: default avatarkbuild test robot <lkp@intel.com>
      Reported-by: default avatarJulia Lawall <julia.lawall@lip6.fr>
      Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c7d81222
    • Michal Koutný's avatar
      cgroup: Prevent double killing of css when enabling threaded cgroup · 060af799
      Michal Koutný authored
      commit 3bc0bb36
      
       upstream.
      
      The test_cgcore_no_internal_process_constraint_on_threads selftest when
      running with subsystem controlling noise triggers two warnings:
      
      > [  597.443115] WARNING: CPU: 1 PID: 28167 at kernel/cgroup/cgroup.c:3131 cgroup_apply_control_enable+0xe0/0x3f0
      > [  597.443413] WARNING: CPU: 1 PID: 28167 at kernel/cgroup/cgroup.c:3177 cgroup_apply_control_disable+0xa6/0x160
      
      Both stem from a call to cgroup_type_write. The first warning was also
      triggered by syzkaller.
      
      When we're switching cgroup to threaded mode shortly after a subsystem
      was disabled on it, we can see the respective subsystem css dying there.
      
      The warning in cgroup_apply_control_enable is harmless in this case
      since we're not adding new subsys anyway.
      The warning in cgroup_apply_control_disable indicates an attempt to kill
      css of recently disabled subsystem repeatedly.
      
      The commit prevents these situations by making cgroup_type_write wait
      for all dying csses to go away before re-applying subtree controls.
      When at it, the locations of WARN_ON_ONCE calls are moved so that
      warning is triggered only when we are about to misuse the dying css.
      
      Reported-by: syzbot+5493b2a54d31d6aea629@syzkaller.appspotmail.com
      Reported-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      Signed-off-by: default avatarMichal Koutný <mkoutny@suse.com>
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      060af799
    • Dan Carpenter's avatar
      Bluetooth: Fix race condition in hci_release_sock() · 58e957b9
      Dan Carpenter authored
      commit 11eb85ec
      
       upstream.
      
      Syzbot managed to trigger a use after free "KASAN: use-after-free Write
      in hci_sock_bind".  I have reviewed the code manually and one possibly
      cause I have found is that we are not holding lock_sock(sk) when we do
      the hci_dev_put(hdev) in hci_sock_release().  My theory is that the bind
      and the release are racing against each other which results in this use
      after free.
      
      Reported-by: syzbot+eba992608adf3d796bcc@syzkaller.appspotmail.com
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      58e957b9
    • Zhenzhong Duan's avatar
      ttyprintk: fix a potential deadlock in interrupt context issue · ab84fd0d
      Zhenzhong Duan authored
      commit 9a655c77 upstream.
      
      tpk_write()/tpk_close() could be interrupted when holding a mutex, then
      in timer handler tpk_write() may be called again trying to acquire same
      mutex, lead to deadlock.
      
      Google syzbot reported this issue with CONFIG_DEBUG_ATOMIC_SLEEP
      enabled:
      
      BUG: sleeping function called from invalid context at
      kernel/locking/mutex.c:938
      in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 0, name: swapper/1
      1 lock held by swapper/1/0:
      ...
      Call Trace:
        <IRQ>
        dump_stack+0x197/0x210
        ___might_sleep.cold+0x1fb/0x23e
        __might_sleep+0x95/0x190
        __mutex_lock+0xc5/0x13c0
        mutex_lock_nested+0x16/0x20
        tpk_write+0x5d/0x340
        resync_tnc+0x1b6/0x320
        call_timer_fn+0x1ac/0x780
        run_timer_softirq+0x6c3/0x1790
        __do_softirq+0x262/0x98c
        irq_exit+0x19b/0x1e0
        smp_apic_timer_interrupt+0x1a3/0x610
        apic_timer_interrupt+0xf/0x20
        </IRQ>
      
      See link https://syzkaller.appspot.com/bug?extid=2eeef62ee31f9460ad65
      
       for
      more details.
      
      Fix it by using spinlock in process context instead of mutex and having
      interrupt disabled in critical section.
      
      Reported-by: syzbot+2eeef62ee31f9460ad65@syzkaller.appspotmail.com
      Signed-off-by: default avatarZhenzhong Duan <zhenzhong.duan@gmail.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Link: https://lore.kernel.org/r/20200113034842.435-1-zhenzhong.duan@gmail.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ab84fd0d
    • Hans Verkuil's avatar
      media: dvb-usb/dvb-usb-urb.c: initialize actlen to 0 · fb5e3b56
      Hans Verkuil authored
      commit 569bc8d6 upstream.
      
      This fixes a syzbot failure since actlen could be uninitialized,
      but it was still used.
      
      Syzbot link:
      
      https://syzkaller.appspot.com/bug?extid=6bf9606ee955b646c0e1
      
      
      
      Reported-and-tested-by: syzbot+6bf9606ee955b646c0e1@syzkaller.appspotmail.com
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Acked-by: default avatarSean Young <sean@mess.org>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fb5e3b56
    • Hans Verkuil's avatar
      media: gspca: zero usb_buf · 03a8533d
      Hans Verkuil authored
      commit de89d086 upstream.
      
      Allocate gspca_dev->usb_buf with kzalloc instead of kmalloc to
      ensure it is property zeroed. This fixes various syzbot errors
      about uninitialized data.
      
      Syzbot links:
      
      https://syzkaller.appspot.com/bug?extid=32310fc2aea76898d074
      https://syzkaller.appspot.com/bug?extid=99706d6390be1ac542a2
      https://syzkaller.appspot.com/bug?extid=64437af5c781a7f0e08e
      
      
      
      Reported-and-tested-by: syzbot+32310fc2aea76898d074@syzkaller.appspotmail.com
      Reported-and-tested-by: syzbot+99706d6390be1ac542a2@syzkaller.appspotmail.com
      Reported-and-tested-by: syzbot+64437af5c781a7f0e08e@syzkaller.appspotmail.com
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      03a8533d
    • Sean Young's avatar
      media: af9005: uninitialized variable printked · b7fae41e
      Sean Young authored
      commit 51d0c99b
      
       upstream.
      
      If usb_bulk_msg() fails, actual_length can be uninitialized.
      
      Reported-by: syzbot+9d42b7773d2fecd983ab@syzkaller.appspotmail.com
      Signed-off-by: default avatarSean Young <sean@mess.org>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b7fae41e
    • Sean Young's avatar
      media: digitv: don't continue if remote control state can't be read · 2e0ebd89
      Sean Young authored
      commit eecc70d2
      
       upstream.
      
      This results in an uninitialized variable read.
      
      Reported-by: syzbot+6bf9606ee955b646c0e1@syzkaller.appspotmail.com
      Signed-off-by: default avatarSean Young <sean@mess.org>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2e0ebd89
    • Jan Kara's avatar
      reiserfs: Fix memory leak of journal device string · 4397069f
      Jan Kara authored
      commit 5474ca7d upstream.
      
      When a filesystem is mounted with jdev mount option, we store the
      journal device name in an allocated string in superblock. However we
      fail to ever free that string. Fix it.
      
      Reported-by: syzbot+1c6756baf4b16b94d2a6@syzkaller.appspotmail.com
      Fixes: c3aa0776
      
       ("reiserfs: Properly display mount options in /proc/mounts")
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4397069f
    • Dan Carpenter's avatar
      mm/mempolicy.c: fix out of bounds write in mpol_parse_str() · 569ae81e
      Dan Carpenter authored
      commit c7a91bc7 upstream.
      
      What we are trying to do is change the '=' character to a NUL terminator
      and then at the end of the function we restore it back to an '='.  The
      problem is there are two error paths where we jump to the end of the
      function before we have replaced the '=' with NUL.
      
      We end up putting the '=' in the wrong place (possibly one element
      before the start of the buffer).
      
      Link: http://lkml.kernel.org/r/20200115055426.vdjwvry44nfug7yy@kili.mountain
      Reported-by: syzbot+e64a13c5369a194d67df@syzkaller.appspotmail.com
      Fixes: 095f1fc4
      
       ("mempolicy: rework shmem mpol parsing and display")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Dmitry Vyukov <dvyukov@google.com>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      569ae81e
    • Theodore Ts'o's avatar
      ext4: validate the debug_want_extra_isize mount option at parse time · 08e4a312
      Theodore Ts'o authored
      commit 9803387c upstream.
      
      Instead of setting s_want_extra_size and then making sure that it is a
      valid value afterwards, validate the field before we set it.  This
      avoids races and other problems when remounting the file system.
      
      Link: https://lore.kernel.org/r/20191215063020.GA11512@mit.edu
      
      
      Cc: stable@kernel.org
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Reported-and-tested-by: syzbot+4a39a025912b265cacef@syzkaller.appspotmail.com
      Signed-off-by: default avatarZubin Mithra <zsm@chromium.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      08e4a312
    • Dirk Behme's avatar
      arm64: kbuild: remove compressed images on 'make ARCH=arm64 (dist)clean' · 64700ad9
      Dirk Behme authored
      commit d7bbd6c1 upstream.
      
      Since v4.3-rc1 commit 0723c05f ("arm64: enable more compressed
      Image formats"), it is possible to build Image.{bz2,lz4,lzma,lzo}
      AArch64 images. However, the commit missed adding support for removing
      those images on 'make ARCH=arm64 (dist)clean'.
      
      Fix this by adding them to the target list.
      Make sure to match the order of the recipes in the makefile.
      
      Cc: stable@vger.kernel.org # v4.3+
      Fixes: 0723c05f
      
       ("arm64: enable more compressed Image formats")
      Signed-off-by: default avatarDirk Behme <dirk.behme@de.bosch.com>
      Signed-off-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
      Reviewed-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      64700ad9
    • Vitaly Chikunov's avatar
      tools lib: Fix builds when glibc contains strlcpy() · 44d87037
      Vitaly Chikunov authored
      commit 6c4798d3 upstream.
      
      Disable a couple of compilation warnings (which are treated as errors)
      on strlcpy() definition and declaration, allowing users to compile perf
      and kernel (objtool) when:
      
      1. glibc have strlcpy() (such as in ALT Linux since 2004) objtool and
         perf build fails with this (in gcc):
      
        In file included from exec-cmd.c:3:
        tools/include/linux/string.h:20:15: error: redundant redeclaration of ‘strlcpy’ [-Werror=redundant-decls]
           20 | extern size_t strlcpy(char *dest, const char *src, size_t size);
      
      2. clang ignores `-Wredundant-decls', but produces another warning when
         building perf:
      
          CC       util/string.o
        ../lib/string.c:99:8: error: attribute declaration must precede definition [-Werror,-Wignored-attributes]
        size_t __weak strlcpy(char *dest, const char *src, size_t size)
        ../../tools/include/linux/compiler.h:66:34: note: expanded from macro '__weak'
        # define __weak                 __attribute__((weak))
        /usr/include/bits/string_fortified.h:151:8: note: previous definition is here
        __NTH (strlcpy (char *__restrict __dest, const char *__restrict __src,
      
      Committer notes:
      
      The
      
       #pragma GCC diagnostic
      
      directive was introduced in gcc 4.6, so check for that as well.
      
      Fixes: ce990917 ("perf tools: Move strlcpy() from perf to tools/lib/string.c")
      Fixes: 0215d59b ("tools lib: Reinstate strlcpy() header guard with __UCLIBC__")
      Resolves: https://bugzilla.kernel.org/show_bug.cgi?id=118481
      
      Signed-off-by: default avatarVitaly Chikunov <vt@altlinux.org>
      Reviewed-by: default avatarDmitry Levin <ldv@altlinux.org>
      Cc: Dmitry Levin <ldv@altlinux.org>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: kbuild test robot <lkp@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Cc: Vineet Gupta <vineet.gupta1@synopsys.com>
      Link: http://lore.kernel.org/lkml/20191224172029.19690-1-vt@altlinux.org
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      44d87037
    • Chanwoo Choi's avatar
      PM / devfreq: Add new name attribute for sysfs · 1fa12145
      Chanwoo Choi authored
      commit 2fee1a7c upstream.
      
      The commit 4585fbcb ("PM / devfreq: Modify the device name as devfreq(X) for
      sysfs") changed the node name to devfreq(x). After this commit, it is not
      possible to get the device name through /sys/class/devfreq/devfreq(X)/*.
      
      Add new name attribute in order to get device name.
      
      Cc: stable@vger.kernel.org
      Fixes: 4585fbcb
      
       ("PM / devfreq: Modify the device name as devfreq(X) for sysfs")
      Signed-off-by: default avatarChanwoo Choi <cw00.choi@samsung.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1fa12145
    • Andres Freund's avatar
      perf c2c: Fix return type for histogram sorting comparision functions · 806dbe2d
      Andres Freund authored
      commit c1c8013e upstream.
      
      Commit 722ddfde ("perf tools: Fix time sorting") changed - correctly
      so - hist_entry__sort to return int64. Unfortunately several of the
      builtin-c2c.c comparison routines only happened to work due the cast
      caused by the wrong return type.
      
      This causes meaningless ordering of both the cacheline list, and the
      cacheline details page. E.g a simple:
      
        perf c2c record -a sleep 3
        perf c2c report
      
      will result in cacheline table like
        =================================================
                   Shared Data Cache Line Table
        =================================================
        #
        #        ------- Cacheline ----------    Total     Tot  - LLC Load Hitm -  - Store Reference -  - Load Dram -     LLC  Total  - Core Load Hit -  - LLC Load Hit -
        # Index         Address  Node  PA cnt  records    Hitm  Total  Lcl    Rmt  Total  L1Hit  L1Miss     Lcl   Rmt  Ld Miss  Loads    FB    L1   L2     Llc      Rmt
        # .....  ..............  ....  ......  .......  ......  .....  .....  ...  ....   .....  ......  ......  ....  ......   .....  .....  ..... ...  ....     .......
      
              0  0x7f0d27ffba00   N/A       0       52   0.12%     13      6    7    12      12       0       0     7      14      40      4     16    0    0           0
              1  0x7f0d27ff61c0   N/A       0     6353  14.04%   1475    801  674   779     779       0       0   718    1392    5574   1299   1967    0  115           0
              2  0x7f0d26d3ec80   N/A       0       71   0.15%     16      4   12    13      13       0       0    12      24      58      1     20    0    9           0
              3  0x7f0d26d3ec00   N/A       0       98   0.22%     23     17    6    19      19       0       0     6      12      79      0     40    0   10           0
      
      i.e. with the list not being ordered by Total Hitm.
      
      Fixes: 722ddfde
      
       ("perf tools: Fix time sorting")
      Signed-off-by: default avatarAndres Freund <andres@anarazel.de>
      Tested-by: default avatarMichael Petlan <mpetlan@redhat.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: stable@vger.kernel.org # v3.16+
      Link: http://lore.kernel.org/lkml/20200109043030.233746-1-andres@anarazel.de
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      806dbe2d
    • Herbert Xu's avatar
      crypto: pcrypt - Fix user-after-free on module unload · db4d8e42
      Herbert Xu authored
      [ Upstream commit 07bfd9bd ]
      
      On module unload of pcrypt we must unregister the crypto algorithms
      first and then tear down the padata structure.  As otherwise the
      crypto algorithms are still alive and can be used while the padata
      structure is being freed.
      
      Fixes: 5068c7a8
      
       ("crypto: pcrypt - Add pcrypt crypto...")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      db4d8e42
    • Xiaochen Shen's avatar
      x86/resctrl: Fix a deadlock due to inaccurate reference · e3f5c2e9
      Xiaochen Shen authored
      commit 334b0f4e upstream.
      
      There is a race condition which results in a deadlock when rmdir and
      mkdir execute concurrently:
      
      $ ls /sys/fs/resctrl/c1/mon_groups/m1/
      cpus  cpus_list  mon_data  tasks
      
      Thread 1: rmdir /sys/fs/resctrl/c1
      Thread 2: mkdir /sys/fs/resctrl/c1/mon_groups/m1
      
      3 locks held by mkdir/48649:
       #0:  (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
       #1:  (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c13b>] filename_create+0x7b/0x170
       #2:  (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
      
      4 locks held by rmdir/48652:
       #0:  (sb_writers#17){.+.+}, at: [<ffffffffb4ca2aa0>] mnt_want_write+0x20/0x50
       #1:  (&type->i_mutex_dir_key#8/1){+.+.}, at: [<ffffffffb4c8c3cf>] do_rmdir+0x13f/0x1e0
       #2:  (&type->i_mutex_dir_key#8){++++}, at: [<ffffffffb4c86d5d>] vfs_rmdir+0x4d/0x120
       #3:  (rdtgroup_mutex){+.+.}, at: [<ffffffffb4a4389d>] rdtgroup_kn_lock_live+0x3d/0x70
      
      Thread 1 is deleting control group "c1". Holding rdtgroup_mutex,
      kernfs_remove() removes all kernfs nodes under directory "c1"
      recursively, then waits for sub kernfs node "mon_groups" to drop active
      reference.
      
      Thread 2 is trying to create a subdirectory "m1" in the "mon_groups"
      directory. The wrapper kernfs_iop_mkdir() takes an active reference to
      the "mon_groups" directory but the code drops the active reference to
      the parent directory "c1" instead.
      
      As a result, Thread 1 is blocked on waiting for active reference to drop
      and never release rdtgroup_mutex, while Thread 2 is also blocked on
      trying to get rdtgroup_mutex.
      
      Thread 1 (rdtgroup_rmdir)   Thread 2 (rdtgroup_mkdir)
      (rmdir /sys/fs/resctrl/c1)  (mkdir /sys/fs/resctrl/c1/mon_groups/m1)
      -------------------------   -------------------------
                                  kernfs_iop_mkdir
                                    /*
                                     * kn: "m1", parent_kn: "mon_groups",
                                     * prgrp_kn: parent_kn->parent: "c1",
                                     *
                                     * "mon_groups", parent_kn->active++: 1
                                     */
                                    kernfs_get_active(parent_kn)
      kernfs_iop_rmdir
        /* "c1", kn->active++ */
        kernfs_get_active(kn)
      
        rdtgroup_kn_lock_live
          atomic_inc(&rdtgrp->waitcount)
          /* "c1", kn->active-- */
          kernfs_break_active_protection(kn)
          mutex_lock
      
        rdtgroup_rmdir_ctrl
          free_all_child_rdtgrp
            sentry->flags = RDT_DELETED
      
          rdtgroup_ctrl_remove
            rdtgrp->flags = RDT_DELETED
            kernfs_get(kn)
            kernfs_remove(rdtgrp->kn)
              __kernfs_remove
                /* "mon_groups", sub_kn */
                atomic_add(KN_DEACTIVATED_BIAS, &sub_kn->active)
                kernfs_drain(sub_kn)
                  /*
                   * sub_kn->active == KN_DEACTIVATED_BIAS + 1,
                   * waiting on sub_kn->active to drop, but it
                   * never drops in Thread 2 which is blocked
                   * on getting rdtgroup_mutex.
                   */
      Thread 1 hangs here ---->
                  wait_event(sub_kn->active == KN_DEACTIVATED_BIAS)
                  ...
                                    rdtgroup_mkdir
                                      rdtgroup_mkdir_mon(parent_kn, prgrp_kn)
                                        mkdir_rdt_prepare(parent_kn, prgrp_kn)
                                          rdtgroup_kn_lock_live(prgrp_kn)
                                            atomic_inc(&rdtgrp->waitcount)
                                            /*
                                             * "c1", prgrp_kn->active--
                                             *
                                             * The active reference on "c1" is
                                             * dropped, but not matching the
                                             * actual active reference taken
                                             * on "mon_groups", thus causing
                                             * Thread 1 to wait forever while
                                             * holding rdtgroup_mutex.
                                             */
                                            kernfs_break_active_protection(
                                                                     prgrp_kn)
                                            /*
                                             * Trying to get rdtgroup_mutex
                                             * which is held by Thread 1.
                                             */
      Thread 2 hangs here ---->             mutex_lock
                                            ...
      
      The problem is that the creation of a subdirectory in the "mon_groups"
      directory incorrectly releases the active protection of its parent
      directory instead of itself before it starts waiting for rdtgroup_mutex.
      This is triggered by the rdtgroup_mkdir() flow calling
      rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() with kernfs node of the
      parent control group ("c1") as argument. It should be called with kernfs
      node "mon_groups" instead. What is currently missing is that the
      kn->priv of "mon_groups" is NULL instead of pointing to the rdtgrp.
      
      Fix it by pointing kn->priv to rdtgrp when "mon_groups" is created. Then
      it could be passed to rdtgroup_kn_lock_live()/rdtgroup_kn_unlock()
      instead. And then it operates on the same rdtgroup structure but handles
      the active reference of kernfs node "mon_groups" to prevent deadlock.
      The same changes are also made to the "mon_data" directories.
      
      This results in some unused function parameters that will be cleaned up
      in follow-up patch as the focus here is on the fix only in support of
      backporting efforts.
      
      Backporting notes:
      
      Since upstream commit fa7d9493 ("x86/resctrl: Rename and move rdt
      files to a separate directory"), the file
      arch/x86/kernel/cpu/intel_rdt_rdtgroup.c has been renamed and moved to
      arch/x86/kernel/cpu/resctrl/rdtgroup.c.
      Apply the change against file arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
      for older stable trees.
      
      Fixes: c7d9aac6
      
       ("x86/intel_rdt/cqm: Add mkdir support for RDT monitoring")
      Suggested-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Signed-off-by: default avatarXiaochen Shen <xiaochen.shen@intel.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Reviewed-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Reviewed-by: default avatarTony Luck <tony.luck@intel.com>
      Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/1578500886-21771-4-git-send-email-xiaochen.shen@intel.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e3f5c2e9
    • Xiaochen Shen's avatar
      x86/resctrl: Fix use-after-free due to inaccurate refcount of rdtgroup · df57e8ba
      Xiaochen Shen authored
      commit 074fadee upstream.
      
      There is a race condition in the following scenario which results in an
      use-after-free issue when reading a monitoring file and deleting the
      parent ctrl_mon group concurrently:
      
      Thread 1 calls atomic_inc() to take refcount of rdtgrp and then calls
      kernfs_break_active_protection() to drop the active reference of kernfs
      node in rdtgroup_kn_lock_live().
      
      In Thread 2, kernfs_remove() is a blocking routine. It waits on all sub
      kernfs nodes to drop the active reference when removing all subtree
      kernfs nodes recursively. Thread 2 could block on kernfs_remove() until
      Thread 1 calls kernfs_break_active_protection(). Only after
      kernfs_remove() completes the refcount of rdtgrp could be trusted.
      
      Before Thread 1 calls atomic_inc() and kernfs_break_active_protection(),
      Thread 2 could call kfree() when the refcount of rdtgrp (sentry) is 0
      instead of 1 due to the race.
      
      In Thread 1, in rdtgroup_kn_unlock(), referring to earlier rdtgrp memory
      (rdtgrp->waitcount) which was already freed in Thread 2 results in
      use-after-free issue.
      
      Thread 1 (rdtgroup_mondata_show)  Thread 2 (rdtgroup_rmdir)
      --------------------------------  -------------------------
      rdtgroup_kn_lock_live
        /*
         * kn active protection until
         * kernfs_break_active_protection(kn)
         */
        rdtgrp = kernfs_to_rdtgroup(kn)
                                        rdtgroup_kn_lock_live
                                          atomic_inc(&rdtgrp->waitcount)
                                          mutex_lock
                                        rdtgroup_rmdir_ctrl
                                          free_all_child_rdtgrp
                                            /*
                                             * sentry->waitcount should be 1
                                             * but is 0 now due to the race.
                                             */
                                            kfree(sentry)*[1]
        /*
         * Only after kernfs_remove()
         * completes, the refcount of
         * rdtgrp could be trusted.
         */
        atomic_inc(&rdtgrp->waitcount)
        /* kn->active-- */
        kernfs_break_active_protection(kn)
                                          rdtgroup_ctrl_remove
                                            rdtgrp->flags = RDT_DELETED
                                            /*
                                             * Blocking routine, wait for
                                             * all sub kernfs nodes to drop
                                             * active reference in
                                             * kernfs_break_active_protection.
                                             */
                                            kernfs_remove(rdtgrp->kn)
                                        rdtgroup_kn_unlock
                                          mutex_unlock
                                          atomic_dec_and_test(
                                                      &rdtgrp->waitcount)
                                          && (flags & RDT_DELETED)
                                            kernfs_unbreak_active_protection(kn)
                                            kfree(rdtgrp)
        mutex_lock
      mon_event_read
      rdtgroup_kn_unlock
        mutex_unlock
        /*
         * Use-after-free: refer to earlier rdtgrp
         * memory which was freed in [1].
         */
        atomic_dec_and_test(&rdtgrp->waitcount)
        && (flags & RDT_DELETED)
          /* kn->active++ */
          kernfs_unbreak_active_protection(kn)
          kfree(rdtgrp)
      
      Fix it by moving free_all_child_rdtgrp() to after kernfs_remove() in
      rdtgroup_rmdir_ctrl() to ensure it has the accurate refcount of rdtgrp.
      
      Backporting notes:
      
      Since upstream commit fa7d9493 ("x86/resctrl: Rename and move rdt
      files to a separate directory"), the file
      arch/x86/kernel/cpu/intel_rdt_rdtgroup.c has been renamed and moved to
      arch/x86/kernel/cpu/resctrl/rdtgroup.c.
      Apply the change against file arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
      for older stable trees.
      
      Upstream commit 17eafd07 ("x86/intel_rdt: Split resource group
      removal in two") moved part of resource group removal code from
      rdtgroup_rmdir_mon() into a separate function rdtgroup_ctrl_remove().
      Apply the change against original code base of rdtgroup_rmdir_mon() for
      older stable trees.
      
      Fixes: f3cbeaca
      
       ("x86/intel_rdt/cqm: Add rmdir support")
      Suggested-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Signed-off-by: default avatarXiaochen Shen <xiaochen.shen@intel.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Reviewed-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Reviewed-by: default avatarTony Luck <tony.luck@intel.com>
      Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/1578500886-21771-3-git-send-email-xiaochen.shen@intel.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      df57e8ba
    • Xiaochen Shen's avatar
      x86/resctrl: Fix use-after-free when deleting resource groups · d20edc0b
      Xiaochen Shen authored
      commit b8511ccc upstream.
      
      A resource group (rdtgrp) contains a reference count (rdtgrp->waitcount)
      that indicates how many waiters expect this rdtgrp to exist. Waiters
      could be waiting on rdtgroup_mutex or some work sitting on a task's
      workqueue for when the task returns from kernel mode or exits.
      
      The deletion of a rdtgrp is intended to have two phases:
      
        (1) while holding rdtgroup_mutex the necessary cleanup is done and
        rdtgrp->flags is set to RDT_DELETED,
      
        (2) after releasing the rdtgroup_mutex, the rdtgrp structure is freed
        only if there are no waiters and its flag is set to RDT_DELETED. Upon
        gaining access to rdtgroup_mutex or rdtgrp, a waiter is required to check
        for the RDT_DELETED flag.
      
      When unmounting the resctrl file system or deleting ctrl_mon groups,
      all of the subdirectories are removed and the data structure of rdtgrp
      is forcibly freed without checking rdtgrp->waitcount. If at this point
      there was a waiter on rdtgrp then a use-after-free issue occurs when the
      waiter starts running and accesses the rdtgrp structure it was waiting
      on.
      
      See kfree() calls in [1], [2] and [3] in these two call paths in
      following scenarios:
      (1) rdt_kill_sb() -> rmdir_all_sub() -> free_all_child_rdtgrp()
      (2) rdtgroup_rmdir() -> rdtgroup_rmdir_ctrl() -> free_all_child_rdtgrp()
      
      There are several scenarios that result in use-after-free issue in
      following:
      
      Scenario 1:
      -----------
      In Thread 1, rdtgroup_tasks_write() adds a task_work callback
      move_myself(). If move_myself() is scheduled to execute after Thread 2
      rdt_kill_sb() is finished, referring to earlier rdtgrp memory
      (rdtgrp->waitcount) which was already freed in Thread 2 results in
      use-after-free issue.
      
      Thread 1 (rdtgroup_tasks_write)        Thread 2 (rdt_kill_sb)
      -------------------------------        ----------------------
      rdtgroup_kn_lock_live
        atomic_inc(&rdtgrp->waitcount)
        mutex_lock
      rdtgroup_move_task
        __rdtgroup_move_task
          /*
           * Take an extra refcount, so rdtgrp cannot be freed
           * before the call back move_myself has been invoked
           */
          atomic_inc(&rdtgrp->waitcount)
          /* Callback move_myself will be scheduled for later */
          task_work_add(move_myself)
      rdtgroup_kn_unlock
        mutex_unlock
        atomic_dec_and_test(&rdtgrp->waitcount)
        && (flags & RDT_DELETED)
                                             mutex_lock
                                             rmdir_all_sub
                                               /*
                                                * sentry and rdtgrp are freed
                                                * without checking refcount
                                                */
                                               free_all_child_rdtgrp
                                                 kfree(sentry)*[1]
                                               kfree(rdtgrp)*[2]
                                             mutex_unlock
      /*
       * Callback is scheduled to execute
       * after rdt_kill_sb is finished
       */
      move_myself
        /*
         * Use-after-free: refer to earlier rdtgrp
         * memory which was freed in [1] or [2].
         */
        atomic_dec_and_test(&rdtgrp->waitcount)
        && (flags & RDT_DELETED)
          kfree(rdtgrp)
      
      Scenario 2:
      -----------
      In Thread 1, rdtgroup_tasks_write() adds a task_work callback
      move_myself(). If move_myself() is scheduled to execute after Thread 2
      rdtgroup_rmdir() is finished, referring to earlier rdtgrp memory
      (rdtgrp->waitcount) which was already freed in Thread 2 results in
      use-after-free issue.
      
      Thread 1 (rdtgroup_tasks_write)        Thread 2 (rdtgroup_rmdir)
      -------------------------------        -------------------------
      rdtgroup_kn_lock_live
        atomic_inc(&rdtgrp->waitcount)
        mutex_lock
      rdtgroup_move_task
        __rdtgroup_move_task
          /*
           * Take an extra refcount, so rdtgrp cannot be freed
           * before the call back move_myself has been invoked
           */
          atomic_inc(&rdtgrp->waitcount)
          /* Callback move_myself will be scheduled for later */
          task_work_add(move_myself)
      rdtgroup_kn_unlock
        mutex_unlock
        atomic_dec_and_test(&rdtgrp->waitcount)
        && (flags & RDT_DELETED)
                                             rdtgroup_kn_lock_live
                                               atomic_inc(&rdtgrp->waitcount)
                                               mutex_lock
                                             rdtgroup_rmdir_ctrl
                                               free_all_child_rdtgrp
                                                 /*
                                                  * sentry is freed without
                                                  * checking refcount
                                                  */
                                                 kfree(sentry)*[3]
                                               rdtgroup_ctrl_remove
                                                 rdtgrp->flags = RDT_DELETED
                                             rdtgroup_kn_unlock
                                               mutex_unlock
                                               atomic_dec_and_test(
                                                           &rdtgrp->waitcount)
                                               && (flags & RDT_DELETED)
                                                 kfree(rdtgrp)
      /*
       * Callback is scheduled to execute
       * after rdt_kill_sb is finished
       */
      move_myself
        /*
         * Use-after-free: refer to earlier rdtgrp
         * memory which was freed in [3].
         */
        atomic_dec_and_test(&rdtgrp->waitcount)
        && (flags & RDT_DELETED)
          kfree(rdtgrp)
      
      If CONFIG_DEBUG_SLAB=y, Slab corruption on kmalloc-2k can be observed
      like following. Note that "0x6b" is POISON_FREE after kfree(). The
      corrupted bits "0x6a", "0x64" at offset 0x424 correspond to
      waitcount member of struct rdtgroup which was freed:
      
        Slab corruption (Not tainted): kmalloc-2k start=ffff9504c5b0d000, len=2048
        420: 6b 6b 6b 6b 6a 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkjkkkkkkkkkkk
        Single bit error detected. Probably bad RAM.
        Run memtest86+ or a similar memory test tool.
        Next obj: start=ffff9504c5b0d800, len=2048
        000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
        010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
      
        Slab corruption (Not tainted): kmalloc-2k start=ffff9504c58ab800, len=2048
        420: 6b 6b 6b 6b 64 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkdkkkkkkkkkkk
        Prev obj: start=ffff9504c58ab000, len=2048
        000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
        010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
      
      Fix this by taking reference count (waitcount) of rdtgrp into account in
      the two call paths that currently do not do so. Instead of always
      freeing the resource group it will only be freed if there are no waiters
      on it. If there are waiters, the resource group will have its flags set
      to RDT_DELETED.
      
      It will be left to the waiter to free the resource group when it starts
      running and finding that it was the last waiter and the resource group
      has been removed (rdtgrp->flags & RDT_DELETED) since. (1) rdt_kill_sb()
      -> rmdir_all_sub() -> free_all_child_rdtgrp() (2) rdtgroup_rmdir() ->
      rdtgroup_rmdir_ctrl() -> free_all_child_rdtgrp()
      
      Backporting notes:
      
      Since upstream commit fa7d9493 ("x86/resctrl: Rename and move rdt
      files to a separate directory"), the file
      arch/x86/kernel/cpu/intel_rdt_rdtgroup.c has been renamed and moved to
      arch/x86/kernel/cpu/resctrl/rdtgroup.c.
      
      Apply the change against file arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
      in older stable trees.
      
      Fixes: f3cbeaca ("x86/intel_rdt/cqm: Add rmdir support")
      Fixes: 60cf5e10
      
       ("x86/intel_rdt: Add mkdir to resctrl file system")
      Suggested-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Signed-off-by: default avatarXiaochen Shen <xiaochen.shen@intel.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Reviewed-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Reviewed-by: default avatarTony Luck <tony.luck@intel.com>
      Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/1578500886-21771-2-git-send-email-xiaochen.shen@intel.com
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d20edc0b
    • Al Viro's avatar
      vfs: fix do_last() regression · 40642747
      Al Viro authored
      commit 6404674a
      
       upstream.
      
      Brown paperbag time: fetching ->i_uid/->i_mode really should've been
      done from nd->inode.  I even suggested that, but the reason for that has
      slipped through the cracks and I went for dir->d_inode instead - made
      for more "obvious" patch.
      
      Analysis:
      
       - at the entry into do_last() and all the way to step_into(): dir (aka
         nd->path.dentry) is known not to have been freed; so's nd->inode and
         it's equal to dir->d_inode unless we are already doomed to -ECHILD.
         inode of the file to get opened is not known.
      
       - after step_into(): inode of the file to get opened is known; dir
         might be pointing to freed memory/be negative/etc.
      
       - at the call of may_create_in_sticky(): guaranteed to be out of RCU
         mode; inode of the file to get opened is known and pinned; dir might
         be garbage.
      
      The last was the reason for the original patch.  Except that at the
      do_last() entry we can be in RCU mode and it is possible that
      nd->path.dentry->d_inode has already changed under us.
      
      In that case we are going to fail with -ECHILD, but we need to be
      careful; nd->inode is pointing to valid struct inode and it's the same
      as nd->path.dentry->d_inode in "won't fail with -ECHILD" case, so we
      should use that.
      Reported-by: default avatar"Rantala, Tommi T. (Nokia - FI/Espoo)" <tommi.t.rantala@nokia.com>
      Reported-by: syzbot+190005201ced78a74ad6@syzkaller.appspotmail.com
      Wearing-brown-paperbag: Al Viro <viro@zeniv.linux.org.uk>
      Cc: stable@kernel.org
      Fixes: d0cb5018
      
       ("do_last(): fetch directory ->i_mode and ->i_uid before it's too late")
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      40642747
    • Herbert Xu's avatar
      crypto: af_alg - Use bh_lock_sock in sk_destruct · 713ff7e4
      Herbert Xu authored
      commit 37f96694
      
       upstream.
      
      As af_alg_release_parent may be called from BH context (most notably
      due to an async request that only completes after socket closure,
      or as reported here because of an RCU-delayed sk_destruct call), we
      must use bh_lock_sock instead of lock_sock.
      
      Reported-by: syzbot+c2f1558d49e25cc36e5e@syzkaller.appspotmail.com
      Reported-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
      Fixes: c840ac6a
      
       ("crypto: af_alg - Disallow bind/setkey/...")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      713ff7e4
    • Johan Hovold's avatar
      rsi: fix use-after-free on probe errors · c662ea4f
      Johan Hovold authored
      commit 92aafe77 upstream.
      
      The driver would fail to stop the command timer in most error paths,
      something which specifically could lead to the timer being freed while
      still active on I/O errors during probe.
      
      Fix this by making sure that each function starting the timer also stops
      it in all relevant error paths.
      
      Reported-by: syzbot+1d1597a5aa3679c65b9f@syzkaller.appspotmail.com
      Fixes: b78e91bc
      
       ("rsi: Add new firmware loading method")
      Cc: stable <stable@vger.kernel.org>     # 4.12
      Cc: Prameela Rani Garnepudi <prameela.j04cs@gmail.com>
      Cc: Amitkumar Karwar <amit.karwar@redpinesignals.com>
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c662ea4f
    • Eric Dumazet's avatar
      net_sched: ematch: reject invalid TCF_EM_SIMPLE · b4cdf506
      Eric Dumazet authored
      [ Upstream commit 55cd9f67 ]
      
      It is possible for malicious userspace to set TCF_EM_SIMPLE bit
      even for matches that should not have this bit set.
      
      This can fool two places using tcf_em_is_simple()
      
      1) tcf_em_tree_destroy() -> memory leak of em->data
         if ops->destroy() is NULL
      
      2) tcf_em_tree_dump() wrongly report/leak 4 low-order bytes
         of a kernel pointer.
      
      BUG: memory leak
      unreferenced object 0xffff888121850a40 (size 32):
        comm "syz-executor927", pid 7193, jiffies 4294941655 (age 19.840s)
        hex dump (first 32 bytes):
          00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000f67036ea>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline]
          [<00000000f67036ea>] slab_post_alloc_hook mm/slab.h:586 [inline]
          [<00000000f67036ea>] slab_alloc mm/slab.c:3320 [inline]
          [<00000000f67036ea>] __do_kmalloc mm/slab.c:3654 [inline]
          [<00000000f67036ea>] __kmalloc_track_caller+0x165/0x300 mm/slab.c:3671
          [<00000000fab0cc8e>] kmemdup+0x27/0x60 mm/util.c:127
          [<00000000d9992e0a>] kmemdup include/linux/string.h:453 [inline]
          [<00000000d9992e0a>] em_nbyte_change+0x5b/0x90 net/sched/em_nbyte.c:32
          [<000000007e04f711>] tcf_em_validate net/sched/ematch.c:241 [inline]
          [<000000007e04f711>] tcf_em_tree_validate net/sched/ematch.c:359 [inline]
          [<000000007e04f711>] tcf_em_tree_validate+0x332/0x46f net/sched/ematch.c:300
          [<000000007a769204>] basic_set_parms net/sched/cls_basic.c:157 [inline]
          [<000000007a769204>] basic_change+0x1d7/0x5f0 net/sched/cls_basic.c:219
          [<00000000e57a5997>] tc_new_tfilter+0x566/0xf70 net/sched/cls_api.c:2104
          [<0000000074b68559>] rtnetlink_rcv_msg+0x3b2/0x4b0 net/core/rtnetlink.c:5415
          [<00000000b7fe53fb>] netlink_rcv_skb+0x61/0x170 net/netlink/af_netlink.c:2477
          [<00000000e83a40d0>] rtnetlink_rcv+0x1d/0x30 net/core/rtnetlink.c:5442
          [<00000000d62ba933>] netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
          [<00000000d62ba933>] netlink_unicast+0x223/0x310 net/netlink/af_netlink.c:1328
          [<0000000088070f72>] netlink_sendmsg+0x2c0/0x570 net/netlink/af_netlink.c:1917
          [<00000000f70b15ea>] sock_sendmsg_nosec net/socket.c:639 [inline]
          [<00000000f70b15ea>] sock_sendmsg+0x54/0x70 net/socket.c:659
          [<00000000ef95a9be>] ____sys_sendmsg+0x2d0/0x300 net/socket.c:2330
          [<00000000b650f1ab>] ___sys_sendmsg+0x8a/0xd0 net/socket.c:2384
          [<0000000055bfa74a>] __sys_sendmsg+0x80/0xf0 net/socket.c:2417
          [<000000002abac183>] __do_sys_sendmsg net/socket.c:2426 [inline]
          [<000000002abac183>] __se_sys_sendmsg net/socket.c:2424 [inline]
          [<000000002abac183>] __x64_sys_sendmsg+0x23/0x30 net/socket.c:2424
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Reported-by: syzbot+03c4738ed29d5d366ddf@syzkaller.appspotmail.com
      Cc: Cong Wang <xiyou.wangcong@gmail.com>
      Acked-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b4cdf506
    • Laura Abbott's avatar
      usb-storage: Disable UAS on JMicron SATA enclosure · ebb7fb7d
      Laura Abbott authored
      [ Upstream commit bc3bdb12
      
       ]
      
      Steve Ellis reported incorrect block sizes and alignement
      offsets with a SATA enclosure. Adding a quirk to disable
      UAS fixes the problems.
      Reported-by: default avatarSteven Ellis <sellis@redhat.com>
      Cc: Pacho Ramos <pachoramos@gmail.com>
      Signed-off-by: default avatarLaura Abbott <labbott@fedoraproject.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ebb7fb7d
    • Slawomir Pawlowski's avatar
      PCI: Add DMA alias quirk for Intel VCA NTB · 5ed8ea17
      Slawomir Pawlowski authored
      [ Upstream commit 56b4cd4b ]
      
      Intel Visual Compute Accelerator (VCA) is a family of PCIe add-in devices
      exposing computational units via Non Transparent Bridges (NTB, PEX 87xx).
      
      Similarly to MIC x200, we need to add DMA aliases to allow buffer access
      when IOMMU is enabled.
      
      Add aliases to allow computational unit access to host memory.  These
      aliases mark the whole VCA device as one IOMMU group.
      
      All possible slot numbers (0x20) are used, since we are unable to tell what
      slot is used on other side.  This quirk is intended for both host and
      computational unit sides.  The VCA devices have up to five functions: four
      for DMA channels and one additional.
      
      Link: https://lore.kernel.org/r/5683A335CC8BE1438C3C30C49DCC38DF637CED8E@IRSMSX102.ger.corp.intel.com
      
      Signed-off-by: default avatarSlawomir Pawlowski <slawomir.pawlowski@intel.com>
      Signed-off-by: default avatarPrzemek Kitszel <przemyslawx.kitszel@intel.com>
      Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5ed8ea17
    • Arnd Bergmann's avatar
      atm: eni: fix uninitialized variable warning · 5be2654a
      Arnd Bergmann authored
      [ Upstream commit 30780d08
      
       ]
      
      With -O3, gcc has found an actual unintialized variable stored
      into an mmio register in two instances:
      
      drivers/atm/eni.c: In function 'discard':
      drivers/atm/eni.c:465:13: error: 'dma[1]' is used uninitialized in this function [-Werror=uninitialized]
         writel(dma[i*2+1],eni_dev->rx_dma+dma_wr*8+4);
                   ^
      drivers/atm/eni.c:465:13: error: 'dma[3]' is used uninitialized in this function [-Werror=uninitialized]
      
      Change the code to always write zeroes instead.
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5be2654a
    • Dmitry Osipenko's avatar
      gpio: max77620: Add missing dependency on GPIOLIB_IRQCHIP · c698d678
      Dmitry Osipenko authored
      [ Upstream commit c5706c7d
      
       ]
      
      Driver fails to compile in a minimized kernel's configuration because of
      the missing dependency on GPIOLIB_IRQCHIP.
      
       error: ‘struct gpio_chip’ has no member named ‘irq’
         44 |   virq = irq_find_mapping(gpio->gpio_chip.irq.domain, offset);
      Signed-off-by: default avatarDmitry Osipenko <digetx@gmail.com>
      Link: https://lore.kernel.org/r/20200106015154.12040-1-digetx@gmail.com
      
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c698d678
    • Krzysztof Kozlowski's avatar
      net: wan: sdla: Fix cast from pointer to integer of different size · e52f8ff3
      Krzysztof Kozlowski authored
      [ Upstream commit 00c0688c
      
       ]
      
      Since net_device.mem_start is unsigned long, it should not be cast to
      int right before casting to pointer.  This fixes warning (compile
      testing on alpha architecture):
      
          drivers/net/wan/sdla.c: In function ‘sdla_transmit’:
          drivers/net/wan/sdla.c:711:13: warning:
              cast to pointer from integer of different size [-Wint-to-pointer-cast]
      Signed-off-by: default avatarKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e52f8ff3
    • Fenghua Yu's avatar
      drivers/net/b44: Change to non-atomic bit operations on pwol_mask · d24cfcdb
      Fenghua Yu authored
      [ Upstream commit f11421ba
      
       ]
      
      Atomic operations that span cache lines are super-expensive on x86
      (not just to the current processor, but also to other processes as all
      memory operations are blocked until the operation completes). Upcoming
      x86 processors have a switch to cause such operations to generate a #AC
      trap. It is expected that some real time systems will enable this mode
      in BIOS.
      
      In preparation for this, it is necessary to fix code that may execute
      atomic instructions with operands that cross cachelines because the #AC
      trap will crash the kernel.
      
      Since "pwol_mask" is local and never exposed to concurrency, there is
      no need to set bits in pwol_mask using atomic operations.
      
      Directly operate on the byte which contains the bit instead of using
      __set_bit() to avoid any big endian concern due to type cast to
      unsigned long in __set_bit().
      Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarFenghua Yu <fenghua.yu@intel.com>
      Signed-off-by: default avatarTony Luck <tony.luck@intel.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d24cfcdb
    • wuxu.wu's avatar
      spi: spi-dw: Add lock protect dw_spi rx/tx to prevent concurrent calls · b56f2a4a
      wuxu.wu authored
      [ Upstream commit 19b61392
      
       ]
      
      dw_spi_irq() and dw_spi_transfer_one concurrent calls.
      
      I find a panic in dw_writer(): txw = *(u8 *)(dws->tx), when dw->tx==null,
      dw->len==4, and dw->tx_end==1.
      
      When tpm driver's message overtime dw_spi_irq() and dw_spi_transfer_one
      may concurrent visit dw_spi, so I think dw_spi structure lack of protection.
      
      Otherwise dw_spi_transfer_one set dw rx/tx buffer and then open irq,
      store dw rx/tx instructions and other cores handle irq load dw rx/tx
      instructions may out of order.
      
      	[ 1025.321302] Call trace:
      	...
      	[ 1025.321319]  __crash_kexec+0x98/0x148
      	[ 1025.321323]  panic+0x17c/0x314
      	[ 1025.321329]  die+0x29c/0x2e8
      	[ 1025.321334]  die_kernel_fault+0x68/0x78
      	[ 1025.321337]  __do_kernel_fault+0x90/0xb0
      	[ 1025.321346]  do_page_fault+0x88/0x500
      	[ 1025.321347]  do_translation_fault+0xa8/0xb8
      	[ 1025.321349]  do_mem_abort+0x68/0x118
      	[ 1025.321351]  el1_da+0x20/0x8c
      	[ 1025.321362]  dw_writer+0xc8/0xd0
      	[ 1025.321364]  interrupt_transfer+0x60/0x110
      	[ 1025.321365]  dw_spi_irq+0x48/0x70
      	...
      Signed-off-by: default avatarwuxu.wu <wuxu.wu@huawei.com>
      Link: https://lore.kernel.org/r/1577849981-31489-1-git-send-email-wuxu.wu@huawei.com
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b56f2a4a
    • Andreas Kemnade's avatar
      watchdog: rn5t618_wdt: fix module aliases · 60cf76ec
      Andreas Kemnade authored
      [ Upstream commit a76dfb85
      
       ]
      
      Platform device aliases were missing so module autoloading
      did not work.
      Signed-off-by: default avatarAndreas Kemnade <andreas@kemnade.info>
      Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Link: https://lore.kernel.org/r/20191213214802.22268-1-andreas@kemnade.info
      
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarWim Van Sebroeck <wim@linux-watchdog.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      60cf76ec