1. 25 Jun, 2020 40 commits
    • Ahmed S. Darwish's avatar
      net: core: device_rename: Use rwsem instead of a seqcount · 29d1d0c7
      Ahmed S. Darwish authored
      [ Upstream commit 11d6011c ]
      
      Sequence counters write paths are critical sections that must never be
      preempted, and blocking, even for CONFIG_PREEMPTION=n, is not allowed.
      
      Commit 5dbe7c17 ("net: fix kernel deadlock with interface rename and
      netdev name retrieval.") handled a deadlock, observed with
      CONFIG_PREEMPTION=n, where the devnet_rename seqcount read side was
      infinitely spinning: it got scheduled after the seqcount write side
      blocked inside its own critical section.
      
      To fix that deadlock, among other issues, the commit added a
      cond_resched() inside the read side section. While this will get the
      non-preemptible kernel eventually unstuck, the seqcount reader is fully
      exhausting its slice just spinning -- until TIF_NEED_RESCHED is set.
      
      The fix is also still broken: if the seqcount reader belongs to a
      real-time scheduling policy, it can spin forever and the kernel will
      livelock.
      
      Disabling preemption over the seqcount write side critical section will
      not work: inside it are a number of GFP_KERNEL allocations and mutex
      locking through the drivers/base/ :: device_rename() call chain.
      
      >From all the above, replace the seqcount with a rwsem.
      
      Fixes: 5dbe7c17 (net: fix kernel deadlock with interface rename and netdev name retrieval.)
      Fixes: 30e6c9fa (net: devnet_rename_seq should be a seqcount)
      Fixes: c91f6df2 (sockopt: Change getsockopt() of SO_BINDTODEVICE to return an interface name)
      Cc: <stable@vger.kernel.org>
      Reported-by: kbuild test robot <lkp@intel.com> [ v1 missing up_read() on error exit ]
      Reported-by: Dan Carpenter <dan.carpenter@oracle.com> [ v1 missing up_read() on error exit ]
      Signed-off-by: default avatarAhmed S. Darwish <a.darwish@linutronix.de>
      Reviewed-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      29d1d0c7
    • Thomas Gleixner's avatar
      sched/rt, net: Use CONFIG_PREEMPTION.patch · b855db2a
      Thomas Gleixner authored
      [ Upstream commit 2da2b32f ]
      
      CONFIG_PREEMPTION is selected by CONFIG_PREEMPT and by CONFIG_PREEMPT_RT.
      Both PREEMPT and PREEMPT_RT require the same functionality which today
      depends on CONFIG_PREEMPT.
      
      Update the comment to use CONFIG_PREEMPTION.
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: netdev@vger.kernel.org
      Link: https://lore.kernel.org/r/20191015191821.11479-22-bigeasy@linutronix.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b855db2a
    • Jiri Olsa's avatar
      kretprobe: Prevent triggering kretprobe from within kprobe_flush_task · 98abe944
      Jiri Olsa authored
      [ Upstream commit 9b38cc70 ]
      
      Ziqian reported lockup when adding retprobe on _raw_spin_lock_irqsave.
      My test was also able to trigger lockdep output:
      
       ============================================
       WARNING: possible recursive locking detected
       5.6.0-rc6+ #6 Not tainted
       --------------------------------------------
       sched-messaging/2767 is trying to acquire lock:
       ffffffff9a492798 (&(kretprobe_table_locks[i].lock)){-.-.}, at: kretprobe_hash_lock+0x52/0xa0
      
       but task is already holding lock:
       ffffffff9a491a18 (&(kretprobe_table_locks[i].lock)){-.-.}, at: kretprobe_trampoline+0x0/0x50
      
       other info that might help us debug this:
        Possible unsafe locking scenario:
      
              CPU0
              ----
         lock(&(kretprobe_table_locks[i].lock));
         lock(&(kretprobe_table_locks[i].lock));
      
        *** DEADLOCK ***
      
        May be due to missing lock nesting notation
      
       1 lock held by sched-messaging/2767:
        #0: ffffffff9a491a18 (&(kretprobe_table_locks[i].lock)){-.-.}, at: kretprobe_trampoline+0x0/0x50
      
       stack backtrace:
       CPU: 3 PID: 2767 Comm: sched-messaging Not tainted 5.6.0-rc6+ #6
       Call Trace:
        dump_stack+0x96/0xe0
        __lock_acquire.cold.57+0x173/0x2b7
        ? native_queued_spin_lock_slowpath+0x42b/0x9e0
        ? lockdep_hardirqs_on+0x590/0x590
        ? __lock_acquire+0xf63/0x4030
        lock_acquire+0x15a/0x3d0
        ? kretprobe_hash_lock+0x52/0xa0
        _raw_spin_lock_irqsave+0x36/0x70
        ? kretprobe_hash_lock+0x52/0xa0
        kretprobe_hash_lock+0x52/0xa0
        trampoline_handler+0xf8/0x940
        ? kprobe_fault_handler+0x380/0x380
        ? find_held_lock+0x3a/0x1c0
        kretprobe_trampoline+0x25/0x50
        ? lock_acquired+0x392/0xbc0
        ? _raw_spin_lock_irqsave+0x50/0x70
        ? __get_valid_kprobe+0x1f0/0x1f0
        ? _raw_spin_unlock_irqrestore+0x3b/0x40
        ? finish_task_switch+0x4b9/0x6d0
        ? __switch_to_asm+0x34/0x70
        ? __switch_to_asm+0x40/0x70
      
      The code within the kretprobe handler checks for probe reentrancy,
      so we won't trigger any _raw_spin_lock_irqsave probe in there.
      
      The problem is in outside kprobe_flush_task, where we call:
      
        kprobe_flush_task
          kretprobe_table_lock
            raw_spin_lock_irqsave
              _raw_spin_lock_irqsave
      
      where _raw_spin_lock_irqsave triggers the kretprobe and installs
      kretprobe_trampoline handler on _raw_spin_lock_irqsave return.
      
      The kretprobe_trampoline handler is then executed with already
      locked kretprobe_table_locks, and first thing it does is to
      lock kretprobe_table_locks ;-) the whole lockup path like:
      
        kprobe_flush_task
          kretprobe_table_lock
            raw_spin_lock_irqsave
              _raw_spin_lock_irqsave ---> probe triggered, kretprobe_trampoline installed
      
              ---> kretprobe_table_locks locked
      
              kretprobe_trampoline
                trampoline_handler
                  kretprobe_hash_lock(current, &head, &flags);  <--- deadlock
      
      Adding kprobe_busy_begin/end helpers that mark code with fake
      probe installed to prevent triggering of another kprobe within
      this code.
      
      Using these helpers in kprobe_flush_task, so the probe recursion
      protection check is hit and the probe is never set to prevent
      above lockup.
      
      Link: http://lkml.kernel.org/r/158927059835.27680.7011202830041561604.stgit@devnote2
      
      Fixes: ef53d9c5 ("kprobes: improve kretprobe scalability with hashed locking")
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: "Gustavo A . R . Silva" <gustavoars@kernel.org>
      Cc: Anders Roxell <anders.roxell@linaro.org>
      Cc: "Naveen N . Rao" <naveen.n.rao@linux.ibm.com>
      Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
      Cc: David Miller <davem@davemloft.net>
      Cc: Ingo Molnar <mingo@elte.hu>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Reported-by: default avatar"Ziqian SUN (Zamir)" <zsun@redhat.com>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      98abe944
    • Alexander Sverdlin's avatar
      net: octeon: mgmt: Repair filling of RX ring · 10699fb9
      Alexander Sverdlin authored
      commit 0c34bb59 upstream.
      
      The removal of mips_swiotlb_ops exposed a problem in octeon_mgmt Ethernet
      driver. mips_swiotlb_ops had an mb() after most of the operations and the
      removal of the ops had broken the receive functionality of the driver.
      My code inspection has shown no other places except
      octeon_mgmt_rx_fill_ring() where an explicit barrier would be obviously
      missing. The latter function however has to make sure that "ringing the
      bell" doesn't happen before RX ring entry is really written.
      
      The patch has been successfully tested on Octeon II.
      
      Fixes: a999933d ("MIPS: remove mips_swiotlb_ops")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarAlexander Sverdlin <alexander.sverdlin@nokia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      10699fb9
    • Chen Yu's avatar
      e1000e: Do not wake up the system via WOL if device wakeup is disabled · f31b2cab
      Chen Yu authored
      commit 6bf6be11 upstream.
      
      Currently the system will be woken up via WOL(Wake On LAN) even if the
      device wakeup ability has been disabled via sysfs:
       cat /sys/devices/pci0000:00/0000:00:1f.6/power/wakeup
       disabled
      
      The system should not be woken up if the user has explicitly
      disabled the wake up ability for this device.
      
      This patch clears the WOL ability of this network device if the
      user has disabled the wake up ability in sysfs.
      
      Fixes: bc7f75fa ("[E1000E]: New pci-express e1000 driver")
      Reported-by: default avatar"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarChen Yu <yu.c.chen@intel.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 avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f31b2cab
    • Masami Hiramatsu's avatar
      kprobes: Fix to protect kick_kprobe_optimizer() by kprobe_mutex · 34895355
      Masami Hiramatsu authored
      commit 1a0aa991 upstream.
      
      In kprobe_optimizer() kick_kprobe_optimizer() is called
      without kprobe_mutex, but this can race with other caller
      which is protected by kprobe_mutex.
      
      To fix that, expand kprobe_mutex protected area to protect
      kick_kprobe_optimizer() call.
      
      Link: http://lkml.kernel.org/r/158927057586.27680.5036330063955940456.stgit@devnote2
      
      Fixes: cd7ebe22 ("kprobes: Use text_poke_smp_batch for optimizing")
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: "Gustavo A . R . Silva" <gustavoars@kernel.org>
      Cc: Anders Roxell <anders.roxell@linaro.org>
      Cc: "Naveen N . Rao" <naveen.n.rao@linux.ibm.com>
      Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
      Cc: David Miller <davem@davemloft.net>
      Cc: Ingo Molnar <mingo@elte.hu>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ziqian SUN <zsun@redhat.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      34895355
    • Eric Biggers's avatar
      crypto: algboss - don't wait during notifier callback · c0ef44cb
      Eric Biggers authored
      commit 77251e41 upstream.
      
      When a crypto template needs to be instantiated, CRYPTO_MSG_ALG_REQUEST
      is sent to crypto_chain.  cryptomgr_schedule_probe() handles this by
      starting a thread to instantiate the template, then waiting for this
      thread to complete via crypto_larval::completion.
      
      This can deadlock because instantiating the template may require loading
      modules, and this (apparently depending on userspace) may need to wait
      for the crc-t10dif module (lib/crc-t10dif.c) to be loaded.  But
      crc-t10dif's module_init function uses crypto_register_notifier() and
      therefore takes crypto_chain.rwsem for write.  That can't proceed until
      the notifier callback has finished, as it holds this semaphore for read.
      
      Fix this by removing the wait on crypto_larval::completion from within
      cryptomgr_schedule_probe().  It's actually unnecessary because
      crypto_alg_mod_lookup() calls crypto_larval_wait() itself after sending
      CRYPTO_MSG_ALG_REQUEST.
      
      This only actually became a problem in v4.20 due to commit b7637754
      ("crc-t10dif: Pick better transform if one becomes available"), but the
      unnecessary wait was much older.
      
      BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=207159Reported-by: default avatarMike Gerow <gerow@google.com>
      Fixes: 39871037 ("crypto: algapi - Move larval completion into algboss")
      Cc: <stable@vger.kernel.org> # v3.6+
      Cc: Martin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
      Reported-by: default avatarKai Lüke <kai@kinvolk.io>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c0ef44cb
    • Herbert Xu's avatar
      crypto: algif_skcipher - Cap recv SG list at ctx->used · b3ad0cdb
      Herbert Xu authored
      commit 7cf81954 upstream.
      
      Somewhere along the line the cap on the SG list length for receive
      was lost.  This patch restores it and removes the subsequent test
      which is now redundant.
      
      Fixes: 2d97591e ("crypto: af_alg - consolidation of...")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Reviewed-by: default avatarStephan Mueller <smueller@chronox.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b3ad0cdb
    • Imre Deak's avatar
      drm/i915/icl+: Fix hotplug interrupt disabling after storm detection · d9d3352c
      Imre Deak authored
      commit a3005c2e upstream.
      
      Atm, hotplug interrupts on TypeC ports are left enabled after detecting
      an interrupt storm, fix this.
      Reported-by: default avatarKunal Joshi <kunal1.joshi@intel.com>
      References: https://gitlab.freedesktop.org/drm/intel/-/issues/351
      Bugzilla: https://gitlab.freedesktop.org/drm/intel/-/issues/1964
      Cc: Kunal Joshi <kunal1.joshi@intel.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarImre Deak <imre.deak@intel.com>
      Reviewed-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20200612121731.19596-1-imre.deak@intel.com
      (cherry picked from commit 587a87b9)
      Signed-off-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d9d3352c
    • Chris Wilson's avatar
      drm/i915: Whitelist context-local timestamp in the gen9 cmdparser · 4f520660
      Chris Wilson authored
      commit 273500ae upstream.
      
      Allow batch buffers to read their own _local_ cumulative HW runtime of
      their logical context.
      
      Fixes: 0f2f3975 ("drm/i915: Add gen9 BCS cmdparsing")
      Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
      Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
      Cc: <stable@vger.kernel.org> # v5.4+
      Reviewed-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20200601161942.30854-1-chris@chris-wilson.co.uk
      (cherry picked from commit f9496520)
      Signed-off-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4f520660
    • Dmitry V. Levin's avatar
      s390: fix syscall_get_error for compat processes · 1d3c79f4
      Dmitry V. Levin authored
      commit b3583fca upstream.
      
      If both the tracer and the tracee are compat processes, and gprs[2]
      is assigned a value by __poke_user_compat, then the higher 32 bits
      of gprs[2] are cleared, IS_ERR_VALUE() always returns false, and
      syscall_get_error() always returns 0.
      
      Fix the implementation by sign-extending the value for compat processes
      the same way as x86 implementation does.
      
      The bug was exposed to user space by commit 201766a2 ("ptrace: add
      PTRACE_GET_SYSCALL_INFO request") and detected by strace test suite.
      
      This change fixes strace syscall tampering on s390.
      
      Link: https://lkml.kernel.org/r/20200602180051.GA2427@altlinux.org
      Fixes: 753c4dd6 ("[S390] ptrace changes")
      Cc: Elvira Khabirova <lineprinter@altlinux.org>
      Cc: stable@vger.kernel.org # v2.6.28+
      Signed-off-by: default avatarDmitry V. Levin <ldv@altlinux.org>
      Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1d3c79f4
    • Miquel Raynal's avatar
      mtd: rawnand: tmio: Fix the probe error path · a686c2b4
      Miquel Raynal authored
      [ Upstream commit 75e9a330 ]
      
      nand_release() is supposed be called after MTD device registration.
      Here, only nand_scan() happened, so use nand_cleanup() instead.
      
      There is no real Fixes tag applying here as the use of nand_release()
      in this driver predates by far the introduction of nand_cleanup() in
      commit d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      which makes this change possible. However, pointing this commit as the
      culprit for backporting purposes makes sense even if this commit is not
      introducing any bug.
      
      Fixes: d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-57-miquel.raynal@bootlin.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      a686c2b4
    • Miquel Raynal's avatar
      mtd: rawnand: mtk: Fix the probe error path · f0524138
      Miquel Raynal authored
      [ Upstream commit 8a82bbca ]
      
      nand_release() is supposed be called after MTD device registration.
      Here, only nand_scan() happened, so use nand_cleanup() instead.
      
      There is no real Fixes tag applying here as the use of nand_release()
      in this driver predates the introduction of nand_cleanup() in
      commit d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      which makes this change possible. However, pointing this commit as the
      culprit for backporting purposes makes sense even if this commit is not
      introducing any bug.
      
      Fixes: d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-28-miquel.raynal@bootlin.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      f0524138
    • Miquel Raynal's avatar
      mtd: rawnand: plat_nand: Fix the probe error path · 5bf01fce
      Miquel Raynal authored
      [ Upstream commit 5284024b ]
      
      nand_release() is supposed be called after MTD device registration.
      Here, only nand_scan() happened, so use nand_cleanup() instead.
      
      There is no real Fixes tag applying here as the use of nand_release()
      in this driver predates by far the introduction of nand_cleanup() in
      commit d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      which makes this change possible, hence pointing it as the commit to
      fix for backporting purposes, even if this commit is not introducing
      any bug.
      
      Fixes: d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-43-miquel.raynal@bootlin.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      5bf01fce
    • Miquel Raynal's avatar
      mtd: rawnand: socrates: Fix the probe error path · 4603f411
      Miquel Raynal authored
      [ Upstream commit 9c6c2e5c ]
      
      nand_release() is supposed be called after MTD device registration.
      Here, only nand_scan() happened, so use nand_cleanup() instead.
      
      There is no real Fixes tag applying here as the use of nand_release()
      in this driver predates by far the introduction of nand_cleanup() in
      commit d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      which makes this change possible. However, pointing this commit as the
      culprit for backporting purposes makes sense even if this commit is not
      introducing any bug.
      
      Fixes: d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-51-miquel.raynal@bootlin.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      4603f411
    • Miquel Raynal's avatar
      mtd: rawnand: oxnas: Fix the probe error path · 45ed31be
      Miquel Raynal authored
      [ Upstream commit 154298e2 ]
      
      nand_release() is supposed be called after MTD device registration.
      Here, only nand_scan() happened, so use nand_cleanup() instead.
      
      While at it, be consistent and move the function call in the error
      path thanks to a goto statement.
      
      Fixes: 66859249 ("mtd: nand: Add OX820 NAND Support")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-37-miquel.raynal@bootlin.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      45ed31be
    • Nishka Dasgupta's avatar
      mtd: rawnand: oxnas: Add of_node_put() · 09fc51a9
      Nishka Dasgupta authored
      [ Upstream commit c436f68b ]
      
      Each iteration of for_each_child_of_node puts the previous node, but in
      the case of a goto from the middle of the loop, there is no put, thus
      causing a memory leak. Hence add an of_node_put under a new goto to put
      the node at a loop exit.
      Issue found with Coccinelle.
      Signed-off-by: default avatarNishka Dasgupta <nishkadg.linux@gmail.com>
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      09fc51a9
    • Miquel Raynal's avatar
      mtd: rawnand: orion: Fix the probe error path · 3431ad8c
      Miquel Raynal authored
      [ Upstream commit be238fbf ]
      
      nand_release() is supposed be called after MTD device registration.
      Here, only nand_scan() happened, so use nand_cleanup() instead.
      
      There is no real Fixes tag applying here as the use of nand_release()
      in this driver predates by far the introduction of nand_cleanup() in
      commit d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      which makes this change possible. However, pointing this commit as the
      culprit for backporting purposes makes sense even if this commit is not
      introducing any bug.
      
      Fixes: d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-34-miquel.raynal@bootlin.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      3431ad8c
    • Miquel Raynal's avatar
      mtd: rawnand: xway: Fix the probe error path · 26a14389
      Miquel Raynal authored
      [ Upstream commit 34531be5 ]
      
      nand_release() is supposed be called after MTD device registration.
      Here, only nand_scan() happened, so use nand_cleanup() instead.
      
      There is no real Fixes tag applying here as the use of nand_release()
      in this driver predates the introduction of nand_cleanup() in
      commit d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      which makes this change possible. However, pointing this commit as the
      culprit for backporting purposes makes sense even if this commit is not
      introducing any bug.
      
      Fixes: d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-61-miquel.raynal@bootlin.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      26a14389
    • Miquel Raynal's avatar
      mtd: rawnand: sharpsl: Fix the probe error path · 9b9e207b
      Miquel Raynal authored
      [ Upstream commit 0f44b327 ]
      
      nand_release() is supposed be called after MTD device registration.
      Here, only nand_scan() happened, so use nand_cleanup() instead.
      
      There is no Fixes tag applying here as the use of nand_release()
      in this driver predates by far the introduction of nand_cleanup() in
      commit d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      which makes this change possible. However, pointing this commit as the
      culprit for backporting purposes makes sense.
      
      Fixes: d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-49-miquel.raynal@bootlin.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      9b9e207b
    • Miquel Raynal's avatar
      mtd: rawnand: diskonchip: Fix the probe error path · f92c582d
      Miquel Raynal authored
      [ Upstream commit c5be12e4 ]
      
      Not sure nand_cleanup() is the right function to call here but in any
      case it is not nand_release(). Indeed, even a comment says that
      calling nand_release() is a bit of a hack as there is no MTD device to
      unregister. So switch to nand_cleanup() for now and drop this
      comment.
      
      There is no Fixes tag applying here as the use of nand_release()
      in this driver predates by far the introduction of nand_cleanup() in
      commit d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      which makes this change possible. However, pointing this commit as the
      culprit for backporting purposes makes sense even if it did not intruce
      any bug.
      
      Fixes: d44154f9 ("mtd: nand: Provide nand_cleanup() function to free NAND related resources")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/linux-mtd/20200519130035.1883-13-miquel.raynal@bootlin.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      f92c582d
    • Boris Brezillon's avatar
      mtd: rawnand: Pass a nand_chip object to nand_release() · eef17834
      Boris Brezillon authored
      [ Upstream commit 59ac276f ]
      
      Let's make the raw NAND API consistent by patching all helpers to
      take a nand_chip object instead of an mtd_info one.
      
      Now is nand_release()'s turn.
      Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      eef17834
    • Boris Brezillon's avatar
      mtd: rawnand: Pass a nand_chip object to nand_scan() · 4c9539a3
      Boris Brezillon authored
      [ Upstream commit 00ad378f ]
      
      Let's make the raw NAND API consistent by patching all helpers to take
      a nand_chip object instead of an mtd_info one.
      
      We start with nand_scan().
      Signed-off-by: default avatarBoris Brezillon <boris.brezillon@bootlin.com>
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4c9539a3
    • Ahmed S. Darwish's avatar
      block: nr_sects_write(): Disable preemption on seqcount write · e1906ca1
      Ahmed S. Darwish authored
      [ Upstream commit 15b81ce5 ]
      
      For optimized block readers not holding a mutex, the "number of sectors"
      64-bit value is protected from tearing on 32-bit architectures by a
      sequence counter.
      
      Disable preemption before entering that sequence counter's write side
      critical section. Otherwise, the read side can preempt the write side
      section and spin for the entire scheduler tick. If the reader belongs to
      a real-time scheduling class, it can spin forever and the kernel will
      livelock.
      
      Fixes: c83f6bf9 ("block: add partition resize function to blkpg ioctl")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAhmed S. Darwish <a.darwish@linutronix.de>
      Reviewed-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e1906ca1
    • Ard Biesheuvel's avatar
      x86/boot/compressed: Relax sed symbol type regex for LLVM ld.lld · 4cc4e2db
      Ard Biesheuvel authored
      commit bc310baf upstream.
      
      The final build stage of the x86 kernel captures some symbol
      addresses from the decompressor binary and copies them into zoffset.h.
      It uses sed with a regular expression that matches the address, symbol
      type and symbol name, and mangles the captured addresses and the names
      of symbols of interest into #define directives that are added to
      zoffset.h
      
      The symbol type is indicated by a single letter, which we match
      strictly: only letters in the set 'ABCDGRSTVW' are matched, even
      though the actual symbol type is relevant and therefore ignored.
      
      Commit bc7c9d62 ("efi/libstub/x86: Force 'hidden' visibility for
      extern declarations") made a change to the way external symbol
      references are classified, resulting in 'startup_32' now being
      emitted as a hidden symbol. This prevents the use of GOT entries to
      refer to this symbol via its absolute address, which recent toolchains
      (including Clang based ones) already avoid by default, making this
      change a no-op in the majority of cases.
      
      However, as it turns out, the LLVM linker classifies such hidden
      symbols as symbols with static linkage in fully linked ELF binaries,
      causing tools such as NM to output a lowercase 't' rather than an upper
      case 'T' for the type of such symbols. Since our sed expression only
      matches upper case letters for the symbol type, the line describing
      startup_32 is disregarded, resulting in a build error like the following
      
        arch/x86/boot/header.S:568:18: error: symbol 'ZO_startup_32' can not be
                                              undefined in a subtraction expression
        init_size: .long (0x00000000008fd000 - ZO_startup_32 +
                          (((0x0000000001f6361c + ((0x0000000001f6361c >> 8) + 65536)
                           - 0x00000000008c32e5) + 4095) & ~4095)) # kernel initialization size
      
      Given that we are only interested in the value of the symbol, let's match
      any character in the set 'a-zA-Z' instead.
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Tested-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4cc4e2db
    • Lyude Paul's avatar
      drm/dp_mst: Increase ACT retry timeout to 3s · e0a59a6e
      Lyude Paul authored
      [ Upstream commit 873a95e0 ]
      
      Currently we only poll for an ACT up to 30 times, with a busy-wait delay
      of 100µs between each attempt - giving us a timeout of 2900µs. While
      this might seem sensible, it would appear that in certain scenarios it
      can take dramatically longer then that for us to receive an ACT. On one
      of the EVGA MST hubs that I have available, I observed said hub
      sometimes taking longer then a second before signalling the ACT. These
      delays mostly seem to occur when previous sideband messages we've sent
      are NAKd by the hub, however it wouldn't be particularly surprising if
      it's possible to reproduce times like this simply by introducing branch
      devices with large LCTs since payload allocations have to take effect on
      every downstream device up to the payload's target.
      
      So, instead of just retrying 30 times we poll for the ACT for up to 3ms,
      and additionally use usleep_range() to avoid a very long and rude
      busy-wait. Note that the previous retry count of 30 appears to have been
      arbitrarily chosen, as I can't find any mention of a recommended timeout
      or retry count for ACTs in the DisplayPort 2.0 specification. This also
      goes for the range we were previously using for udelay(), although I
      suspect that was just copied from the recommended delay for link
      training on SST devices.
      
      Changes since v1:
      * Use readx_poll_timeout() instead of open-coding timeout loop - Sean
        Paul
      Changes since v2:
      * Increase poll interval to 200us - Sean Paul
      * Print status in hex when we timeout waiting for ACT - Sean Paul
      Signed-off-by: default avatarLyude Paul <lyude@redhat.com>
      Fixes: ad7f8a1f ("drm/helper: add Displayport multi-stream helper (v0.6)")
      Cc: Sean Paul <sean@poorly.run>
      Cc: <stable@vger.kernel.org> # v3.17+
      Reviewed-by: default avatarSean Paul <sean@poorly.run>
      Link: https://patchwork.freedesktop.org/patch/msgid/20200406221253.1307209-4-lyude@redhat.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
      e0a59a6e
    • Theodore Ts'o's avatar
      ext4: avoid race conditions when remounting with options that change dax · 5dbb6255
      Theodore Ts'o authored
      [ Upstream commit 829b37b8 ]
      
      Trying to change dax mount options when remounting could allow mount
      options to be enabled for a small amount of time, and then the mount
      option change would be reverted.
      
      In the case of "mount -o remount,dax", this can cause a race where
      files would temporarily treated as DAX --- and then not.
      
      Cc: stable@kernel.org
      Reported-by: syzbot+bca9799bf129256190da@syzkaller.appspotmail.com
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5dbb6255
    • Sasha Levin's avatar
      ext4: fix partial cluster initialization when splitting extent · 051bf267
      Sasha Levin authored
      [ Upstream commit cfb3c85a ]
      
      Fix the bug when calculating the physical block number of the first
      block in the split extent.
      
      This bug will cause xfstests shared/298 failure on ext4 with bigalloc
      enabled occasionally. Ext4 error messages indicate that previously freed
      blocks are being freed again, and the following fsck will fail due to
      the inconsistency of block bitmap and bg descriptor.
      
      The following is an example case:
      
      1. First, Initialize a ext4 filesystem with cluster size '16K', block size
      '4K', in which case, one cluster contains four blocks.
      
      2. Create one file (e.g., xxx.img) on this ext4 filesystem. Now the extent
      tree of this file is like:
      
      ...
      36864:[0]4:220160
      36868:[0]14332:145408
      51200:[0]2:231424
      ...
      
      3. Then execute PUNCH_HOLE fallocate on this file. The hole range is
      like:
      
      ..
      ext4_ext_remove_space: dev 254,16 ino 12 since 49506 end 49506 depth 1
      ext4_ext_remove_space: dev 254,16 ino 12 since 49544 end 49546 depth 1
      ext4_ext_remove_space: dev 254,16 ino 12 since 49605 end 49607 depth 1
      ...
      
      4. Then the extent tree of this file after punching is like
      
      ...
      49507:[0]37:158047
      49547:[0]58:158087
      ...
      
      5. Detailed procedure of punching hole [49544, 49546]
      
      5.1. The block address space:
      ```
      lblk        ~49505  49506   49507~49543     49544~49546    49547~
      	  ---------+------+-------------+----------------+--------
      	    extent | hole |   extent	|	hole	 | extent
      	  ---------+------+-------------+----------------+--------
      pblk       ~158045  158046  158047~158083  158084~158086   158087~
      ```
      
      5.2. The detailed layout of cluster 39521:
      ```
      		cluster 39521
      	<------------------------------->
      
      		hole		  extent
      	<----------------------><--------
      
      lblk      49544   49545   49546   49547
      	+-------+-------+-------+-------+
      	|	|	|	|	|
      	+-------+-------+-------+-------+
      pblk     158084  1580845  158086  158087
      ```
      
      5.3. The ftrace output when punching hole [49544, 49546]:
      - ext4_ext_remove_space (start 49544, end 49546)
        - ext4_ext_rm_leaf (start 49544, end 49546, last_extent [49507(158047), 40], partial [pclu 39522 lblk 0 state 2])
          - ext4_remove_blocks (extent [49507(158047), 40], from 49544 to 49546, partial [pclu 39522 lblk 0 state 2]
            - ext4_free_blocks: (block 158084 count 4)
              - ext4_mballoc_free (extent 1/6753/1)
      
      5.4. Ext4 error message in dmesg:
      EXT4-fs error (device vdb): mb_free_blocks:1457: group 1, block 158084:freeing already freed block (bit 6753); block bitmap corrupt.
      EXT4-fs error (device vdb): ext4_mb_generate_buddy:747: group 1, block bitmap and bg descriptor inconsistent: 19550 vs 19551 free clusters
      
      In this case, the whole cluster 39521 is freed mistakenly when freeing
      pblock 158084~158086 (i.e., the first three blocks of this cluster),
      although pblock 158087 (the last remaining block of this cluster) has
      not been freed yet.
      
      The root cause of this isuue is that, the pclu of the partial cluster is
      calculated mistakenly in ext4_ext_remove_space(). The correct
      partial_cluster.pclu (i.e., the cluster number of the first block in the
      next extent, that is, lblock 49597 (pblock 158086)) should be 39521 rather
      than 39522.
      
      Fixes: f4226d9e ("ext4: fix partial cluster initialization")
      Signed-off-by: default avatarJeffle Xu <jefflexu@linux.alibaba.com>
      Reviewed-by: default avatarEric Whitney <enwlinux@gmail.com>
      Cc: stable@kernel.org # v3.19+
      Link: https://lore.kernel.org/r/1590121124-37096-1-git-send-email-jefflexu@linux.alibaba.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      051bf267
    • Tom Rix's avatar
      selinux: fix double free · cd80735a
      Tom Rix authored
      commit 65de5096 upstream.
      
      Clang's static analysis tool reports these double free memory errors.
      
      security/selinux/ss/services.c:2987:4: warning: Attempt to free released memory [unix.Malloc]
                              kfree(bnames[i]);
                              ^~~~~~~~~~~~~~~~
      security/selinux/ss/services.c:2990:2: warning: Attempt to free released memory [unix.Malloc]
              kfree(bvalues);
              ^~~~~~~~~~~~~~
      
      So improve the security_get_bools error handling by freeing these variables
      and setting their return pointers to NULL and the return len to 0
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Acked-by: default avatarStephen Smalley <stephen.smalley.work@gmail.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cd80735a
    • Sandeep Raghuraman's avatar
      drm/amdgpu: Replace invalid device ID with a valid device ID · 9a20612e
      Sandeep Raghuraman authored
      commit 790243d3 upstream.
      
      Initializes Powertune data for a specific Hawaii card by fixing what
      looks like a typo in the code. The device ID 66B1 is not a supported
      device ID for this driver, and is not mentioned elsewhere. 67B1 is a
      valid device ID, and is a Hawaii Pro GPU.
      
      I have tested on my R9 390 which has device ID 67B1, and it works
      fine without problems.
      Signed-off-by: default avatarSandeep Raghuraman <sandy.8925@gmail.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9a20612e
    • Huacai Chen's avatar
      drm/qxl: Use correct notify port address when creating cursor ring · ed7db983
      Huacai Chen authored
      commit 80e5f89d upstream.
      
      The command ring and cursor ring use different notify port addresses
      definition: QXL_IO_NOTIFY_CMD and QXL_IO_NOTIFY_CURSOR. However, in
      qxl_device_init() we use QXL_IO_NOTIFY_CMD to create both command ring
      and cursor ring. This doesn't cause any problems now, because QEMU's
      behaviors on QXL_IO_NOTIFY_CMD and QXL_IO_NOTIFY_CURSOR are the same.
      However, QEMU's behavior may be change in future, so let's fix it.
      
      P.S.: In the X.org QXL driver, the notify port address of cursor ring
            is correct.
      Signed-off-by: default avatarHuacai Chen <chenhc@lemote.com>
      Cc: <stable@vger.kernel.org>
      Link: http://patchwork.freedesktop.org/patch/msgid/1585635488-17507-1-git-send-email-chenhc@lemote.comSigned-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ed7db983
    • Lyude Paul's avatar
      drm/dp_mst: Reformat drm_dp_check_act_status() a bit · f3f05971
      Lyude Paul authored
      commit a5cb5fa6 upstream.
      
      Just add a bit more line wrapping, get rid of some extraneous
      whitespace, remove an unneeded goto label, and move around some variable
      declarations. No functional changes here.
      Signed-off-by: default avatarLyude Paul <lyude@redhat.com>
      [this isn't a fix, but it's needed for the fix that comes after this]
      Fixes: ad7f8a1f ("drm/helper: add Displayport multi-stream helper (v0.6)")
      Cc: Sean Paul <sean@poorly.run>
      Cc: <stable@vger.kernel.org> # v3.17+
      Reviewed-by: default avatarSean Paul <sean@poorly.run>
      Link: https://patchwork.freedesktop.org/patch/msgid/20200406221253.1307209-3-lyude@redhat.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f3f05971
    • Wolfram Sang's avatar
      drm: encoder_slave: fix refcouting error for modules · e5b20d0b
      Wolfram Sang authored
      [ Upstream commit f78d4032 ]
      
      module_put() balances try_module_get(), not request_module(). Fix the
      error path to match that.
      
      Fixes: 2066facc ("drm/kms: slave encoder interface.")
      Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
      Reviewed-by: default avatarEmil Velikov <emil.l.velikov@gmail.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e5b20d0b
    • Kai-Heng Feng's avatar
      libata: Use per port sync for detach · edcb7efd
      Kai-Heng Feng authored
      [ Upstream commit b5292111 ]
      
      Commit 130f4caf ("libata: Ensure ata_port probe has completed before
      detach") may cause system freeze during suspend.
      
      Using async_synchronize_full() in PM callbacks is wrong, since async
      callbacks that are already scheduled may wait for not-yet-scheduled
      callbacks, causes a circular dependency.
      
      Instead of using big hammer like async_synchronize_full(), use async
      cookie to make sure port probe are synced, without affecting other
      scheduled PM callbacks.
      
      Fixes: 130f4caf ("libata: Ensure ata_port probe has completed before detach")
      Suggested-by: default avatarJohn Garry <john.garry@huawei.com>
      Signed-off-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
      Tested-by: default avatarJohn Garry <john.garry@huawei.com>
      BugLink: https://bugs.launchpad.net/bugs/1867983Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      edcb7efd
    • Will Deacon's avatar
      arm64: hw_breakpoint: Don't invoke overflow handler on uaccess watchpoints · a39340ab
      Will Deacon authored
      [ Upstream commit 24ebec25 ]
      
      Unprivileged memory accesses generated by the so-called "translated"
      instructions (e.g. STTR) at EL1 can cause EL0 watchpoints to fire
      unexpectedly if kernel debugging is enabled. In such cases, the
      hw_breakpoint logic will invoke the user overflow handler which will
      typically raise a SIGTRAP back to the current task. This is futile when
      returning back to the kernel because (a) the signal won't have been
      delivered and (b) userspace can't handle the thing anyway.
      
      Avoid invoking the user overflow handler for watchpoints triggered by
      kernel uaccess routines, and instead single-step over the faulting
      instruction as we would if no overflow handler had been installed.
      
      (Fixes tag identifies the introduction of unprivileged memory accesses,
       which exposed this latent bug in the hw_breakpoint code)
      
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: James Morse <james.morse@arm.com>
      Fixes: 57f4959b ("arm64: kernel: Add support for User Access Override")
      Reported-by: default avatarLuis Machado <luis.machado@linaro.org>
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a39340ab
    • Jason Yan's avatar
      block: Fix use-after-free in blkdev_get() · 49289b1f
      Jason Yan authored
      [ Upstream commit 2d3a8e2d ]
      
      In blkdev_get() we call __blkdev_get() to do some internal jobs and if
      there is some errors in __blkdev_get(), the bdput() is called which
      means we have released the refcount of the bdev (actually the refcount of
      the bdev inode). This means we cannot access bdev after that point. But
      acctually bdev is still accessed in blkdev_get() after calling
      __blkdev_get(). This results in use-after-free if the refcount is the
      last one we released in __blkdev_get(). Let's take a look at the
      following scenerio:
      
        CPU0            CPU1                    CPU2
      blkdev_open     blkdev_open           Remove disk
                        bd_acquire
      		  blkdev_get
      		    __blkdev_get      del_gendisk
      					bdev_unhash_inode
        bd_acquire          bdev_get_gendisk
          bd_forget           failed because of unhashed
      	  bdput
      	              bdput (the last one)
      		        bdev_evict_inode
      
      	  	    access bdev => use after free
      
      [  459.350216] BUG: KASAN: use-after-free in __lock_acquire+0x24c1/0x31b0
      [  459.351190] Read of size 8 at addr ffff88806c815a80 by task syz-executor.0/20132
      [  459.352347]
      [  459.352594] CPU: 0 PID: 20132 Comm: syz-executor.0 Not tainted 4.19.90 #2
      [  459.353628] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
      [  459.354947] Call Trace:
      [  459.355337]  dump_stack+0x111/0x19e
      [  459.355879]  ? __lock_acquire+0x24c1/0x31b0
      [  459.356523]  print_address_description+0x60/0x223
      [  459.357248]  ? __lock_acquire+0x24c1/0x31b0
      [  459.357887]  kasan_report.cold+0xae/0x2d8
      [  459.358503]  __lock_acquire+0x24c1/0x31b0
      [  459.359120]  ? _raw_spin_unlock_irq+0x24/0x40
      [  459.359784]  ? lockdep_hardirqs_on+0x37b/0x580
      [  459.360465]  ? _raw_spin_unlock_irq+0x24/0x40
      [  459.361123]  ? finish_task_switch+0x125/0x600
      [  459.361812]  ? finish_task_switch+0xee/0x600
      [  459.362471]  ? mark_held_locks+0xf0/0xf0
      [  459.363108]  ? __schedule+0x96f/0x21d0
      [  459.363716]  lock_acquire+0x111/0x320
      [  459.364285]  ? blkdev_get+0xce/0xbe0
      [  459.364846]  ? blkdev_get+0xce/0xbe0
      [  459.365390]  __mutex_lock+0xf9/0x12a0
      [  459.365948]  ? blkdev_get+0xce/0xbe0
      [  459.366493]  ? bdev_evict_inode+0x1f0/0x1f0
      [  459.367130]  ? blkdev_get+0xce/0xbe0
      [  459.367678]  ? destroy_inode+0xbc/0x110
      [  459.368261]  ? mutex_trylock+0x1a0/0x1a0
      [  459.368867]  ? __blkdev_get+0x3e6/0x1280
      [  459.369463]  ? bdev_disk_changed+0x1d0/0x1d0
      [  459.370114]  ? blkdev_get+0xce/0xbe0
      [  459.370656]  blkdev_get+0xce/0xbe0
      [  459.371178]  ? find_held_lock+0x2c/0x110
      [  459.371774]  ? __blkdev_get+0x1280/0x1280
      [  459.372383]  ? lock_downgrade+0x680/0x680
      [  459.373002]  ? lock_acquire+0x111/0x320
      [  459.373587]  ? bd_acquire+0x21/0x2c0
      [  459.374134]  ? do_raw_spin_unlock+0x4f/0x250
      [  459.374780]  blkdev_open+0x202/0x290
      [  459.375325]  do_dentry_open+0x49e/0x1050
      [  459.375924]  ? blkdev_get_by_dev+0x70/0x70
      [  459.376543]  ? __x64_sys_fchdir+0x1f0/0x1f0
      [  459.377192]  ? inode_permission+0xbe/0x3a0
      [  459.377818]  path_openat+0x148c/0x3f50
      [  459.378392]  ? kmem_cache_alloc+0xd5/0x280
      [  459.379016]  ? entry_SYSCALL_64_after_hwframe+0x49/0xbe
      [  459.379802]  ? path_lookupat.isra.0+0x900/0x900
      [  459.380489]  ? __lock_is_held+0xad/0x140
      [  459.381093]  do_filp_open+0x1a1/0x280
      [  459.381654]  ? may_open_dev+0xf0/0xf0
      [  459.382214]  ? find_held_lock+0x2c/0x110
      [  459.382816]  ? lock_downgrade+0x680/0x680
      [  459.383425]  ? __lock_is_held+0xad/0x140
      [  459.384024]  ? do_raw_spin_unlock+0x4f/0x250
      [  459.384668]  ? _raw_spin_unlock+0x1f/0x30
      [  459.385280]  ? __alloc_fd+0x448/0x560
      [  459.385841]  do_sys_open+0x3c3/0x500
      [  459.386386]  ? filp_open+0x70/0x70
      [  459.386911]  ? trace_hardirqs_on_thunk+0x1a/0x1c
      [  459.387610]  ? trace_hardirqs_off_caller+0x55/0x1c0
      [  459.388342]  ? do_syscall_64+0x1a/0x520
      [  459.388930]  do_syscall_64+0xc3/0x520
      [  459.389490]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
      [  459.390248] RIP: 0033:0x416211
      [  459.390720] Code: 75 14 b8 02 00 00 00 0f 05 48 3d 01 f0 ff ff 0f 83
      04 19 00 00 c3 48 83 ec 08 e8 0a fa ff ff 48 89 04 24 b8 02 00 00 00 0f
         05 <48> 8b 3c 24 48 89 c2 e8 53 fa ff ff 48 89 d0 48 83 c4 08 48 3d
            01
      [  459.393483] RSP: 002b:00007fe45dfe9a60 EFLAGS: 00000293 ORIG_RAX: 0000000000000002
      [  459.394610] RAX: ffffffffffffffda RBX: 00007fe45dfea6d4 RCX: 0000000000416211
      [  459.395678] RDX: 00007fe45dfe9b0a RSI: 0000000000000002 RDI: 00007fe45dfe9b00
      [  459.396758] RBP: 000000000076bf20 R08: 0000000000000000 R09: 000000000000000a
      [  459.397930] R10: 0000000000000075 R11: 0000000000000293 R12: 00000000ffffffff
      [  459.399022] R13: 0000000000000bd9 R14: 00000000004cdb80 R15: 000000000076bf2c
      [  459.400168]
      [  459.400430] Allocated by task 20132:
      [  459.401038]  kasan_kmalloc+0xbf/0xe0
      [  459.401652]  kmem_cache_alloc+0xd5/0x280
      [  459.402330]  bdev_alloc_inode+0x18/0x40
      [  459.402970]  alloc_inode+0x5f/0x180
      [  459.403510]  iget5_locked+0x57/0xd0
      [  459.404095]  bdget+0x94/0x4e0
      [  459.404607]  bd_acquire+0xfa/0x2c0
      [  459.405113]  blkdev_open+0x110/0x290
      [  459.405702]  do_dentry_open+0x49e/0x1050
      [  459.406340]  path_openat+0x148c/0x3f50
      [  459.406926]  do_filp_open+0x1a1/0x280
      [  459.407471]  do_sys_open+0x3c3/0x500
      [  459.408010]  do_syscall_64+0xc3/0x520
      [  459.408572]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
      [  459.409415]
      [  459.409679] Freed by task 1262:
      [  459.410212]  __kasan_slab_free+0x129/0x170
      [  459.410919]  kmem_cache_free+0xb2/0x2a0
      [  459.411564]  rcu_process_callbacks+0xbb2/0x2320
      [  459.412318]  __do_softirq+0x225/0x8ac
      
      Fix this by delaying bdput() to the end of blkdev_get() which means we
      have finished accessing bdev.
      
      Fixes: 77ea887e ("implement in-kernel gendisk events handling")
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarJason Yan <yanaijie@huawei.com>
      Tested-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: Ming Lei <ming.lei@redhat.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      49289b1f
    • David Howells's avatar
      afs: afs_write_end() should change i_size under the right lock · 2788511b
      David Howells authored
      [ Upstream commit 1f32ef79 ]
      
      Fix afs_write_end() to change i_size under vnode->cb_lock rather than
      ->wb_lock so that it doesn't race with afs_vnode_commit_status() and
      afs_getattr().
      
      The ->wb_lock is only meant to guard access to ->wb_keys which isn't
      accessed by that piece of code.
      
      Fixes: 4343d008 ("afs: Get rid of the afs_writeback record")
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2788511b
    • David Howells's avatar
      afs: Fix non-setting of mtime when writing into mmap · 08de5907
      David Howells authored
      [ Upstream commit bb413489 ]
      
      The mtime on an inode needs to be updated when a write is made into an
      mmap'ed section.  There are three ways in which this could be done: update
      it when page_mkwrite is called, update it when a page is changed from dirty
      to writeback or leave it to the server and fix the mtime up from the reply
      to the StoreData RPC.
      
      Found with the generic/215 xfstest.
      
      Fixes: 1cf7a151 ("afs: Implement shared-writeable mmap")
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      08de5907
    • Zhiqiang Liu's avatar
      bcache: fix potential deadlock problem in btree_gc_coalesce · 2ee8f6e7
      Zhiqiang Liu authored
      [ Upstream commit be23e837 ]
      
      coccicheck reports:
        drivers/md//bcache/btree.c:1538:1-7: preceding lock on line 1417
      
      In btree_gc_coalesce func, if the coalescing process fails, we will goto
      to out_nocoalesce tag directly without releasing new_nodes[i]->write_lock.
      Then, it will cause a deadlock when trying to acquire new_nodes[i]->
      write_lock for freeing new_nodes[i] before return.
      
      btree_gc_coalesce func details as follows:
      	if alloc new_nodes[i] fails:
      		goto out_nocoalesce;
      	// obtain new_nodes[i]->write_lock
      	mutex_lock(&new_nodes[i]->write_lock)
      	// main coalescing process
      	for (i = nodes - 1; i > 0; --i)
      		[snipped]
      		if coalescing process fails:
      			// Here, directly goto out_nocoalesce
      			 // tag will cause a deadlock
      			goto out_nocoalesce;
      		[snipped]
      	// release new_nodes[i]->write_lock
      	mutex_unlock(&new_nodes[i]->write_lock)
      	// coalesing succ, return
      	return;
      out_nocoalesce:
      	btree_node_free(new_nodes[i])	// free new_nodes[i]
      	// obtain new_nodes[i]->write_lock
      	mutex_lock(&new_nodes[i]->write_lock);
      	// set flag for reuse
      	clear_bit(BTREE_NODE_dirty, &ew_nodes[i]->flags);
      	// release new_nodes[i]->write_lock
      	mutex_unlock(&new_nodes[i]->write_lock);
      
      To fix the problem, we add a new tag 'out_unlock_nocoalesce' for
      releasing new_nodes[i]->write_lock before out_nocoalesce tag. If
      coalescing process fails, we will go to out_unlock_nocoalesce tag
      for releasing new_nodes[i]->write_lock before free new_nodes[i] in
      out_nocoalesce tag.
      
      (Coly Li helps to clean up commit log format.)
      
      Fixes: 2a285686 ("bcache: btree locking rework")
      Signed-off-by: default avatarZhiqiang Liu <liuzhiqiang26@huawei.com>
      Signed-off-by: default avatarColy Li <colyli@suse.de>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2ee8f6e7
    • yangerkun's avatar
      ext4: stop overwrite the errcode in ext4_setup_super · b0873334
      yangerkun authored
      [ Upstream commit 5adaccac ]
      
      Now the errcode from ext4_commit_super will overwrite EROFS exists in
      ext4_setup_super. Actually, no need to call ext4_commit_super since we
      will return EROFS. Fix it by goto done directly.
      
      Fixes: c89128a0 ("ext4: handle errors on ext4_commit_super")
      Signed-off-by: default avataryangerkun <yangerkun@huawei.com>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Link: https://lore.kernel.org/r/20200601073404.3712492-1-yangerkun@huawei.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b0873334