Skip to content
  1. Apr 08, 2022
    • Jonathan Neuschäfer's avatar
      pinctrl: nuvoton: npcm7xx: Use %zu printk format for ARRAY_SIZE() · 29b6fa7f
      Jonathan Neuschäfer authored
      commit 9d0f18bc
      
       upstream.
      
      When compile-testing on 64-bit architectures, GCC complains about the
      mismatch of types between the %d format specifier and value returned by
      ARRAY_LENGTH(). Use %zu, which is correct everywhere.
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Fixes: 3b588e43
      
       ("pinctrl: nuvoton: add NPCM7xx pinctrl and GPIO driver")
      Signed-off-by: default avatarJonathan Neuschäfer <j.neuschaefer@gmx.net>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Link: https://lore.kernel.org/r/20220205155332.1308899-2-j.neuschaefer@gmx.net
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      29b6fa7f
    • Jonathan Neuschäfer's avatar
      pinctrl: nuvoton: npcm7xx: Rename DS() macro to DSTR() · 77190d5f
      Jonathan Neuschäfer authored
      commit 603501c1
      
       upstream.
      
      The name "DS" is defined in arch/x86/um/shared/sysdep/ptrace_64.h,
      which results in a compiler warning when build-testing on ARCH=um.
      Rename this driver's "DS" macro to DSTR so avoid this collision.
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Fixes: 3b588e43
      
       ("pinctrl: nuvoton: add NPCM7xx pinctrl and GPIO driver")
      Signed-off-by: default avatarJonathan Neuschäfer <j.neuschaefer@gmx.net>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Link: https://lore.kernel.org/r/20220205155332.1308899-3-j.neuschaefer@gmx.net
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      77190d5f
    • Randy Dunlap's avatar
      net: sparx5: uses, depends on BRIDGE or !BRIDGE · ae90ae94
      Randy Dunlap authored
      commit f9512d65 upstream.
      
      Fix build errors when BRIDGE=m and SPARX5_SWITCH=y:
      
      riscv64-linux-ld: drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.o: in function `.L305':
      sparx5_switchdev.c:(.text+0xdb0): undefined reference to `br_vlan_enabled'
      riscv64-linux-ld: drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.o: in function `.L283':
      sparx5_switchdev.c:(.text+0xee0): undefined reference to `br_vlan_enabled'
      
      Fixes: 3cfa11ba
      
       ("net: sparx5: add the basic sparx5 driver")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Cc: Horatiu Vultur <horatiu.vultur@microchip.com>
      Cc: Lars Povlsen <lars.povlsen@microchip.com>
      Cc: Steen Hegelund <Steen.Hegelund@microchip.com>
      Cc: UNGLinuxDriver@microchip.com
      Cc: Paolo Abeni <pabeni@redhat.com>
      Link: https://lore.kernel.org/r/20220330012025.29560-1-rdunlap@infradead.org
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ae90ae94
    • Miaoqian Lin's avatar
      watchdog: rti-wdt: Add missing pm_runtime_disable() in probe function · 7992be23
      Miaoqian Lin authored
      commit d055ef3a upstream.
      
      If the probe fails, we should use pm_runtime_disable() to balance
      pm_runtime_enable().
      
      Fixes: 2d63908b
      
       ("watchdog: Add K3 RTI watchdog support")
      Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
      Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Link: https://lore.kernel.org/r/20220105092114.23932-1-linmq006@gmail.com
      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 avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7992be23
    • Chen-Yu Tsai's avatar
      pinctrl: pinconf-generic: Print arguments for bias-pull-* · e18eeb3e
      Chen-Yu Tsai authored
      commit 188e5834 upstream.
      
      The bias-pull-* properties, or PIN_CONFIG_BIAS_PULL_* pin config
      parameters, accept optional arguments in ohms denoting the strength of
      the pin bias.
      
      Print these values out in debugfs as well.
      
      Fixes: eec45071
      
       ("pinctrl: pinconf-generic: Add flag to print arguments")
      Signed-off-by: default avatarChen-Yu Tsai <wenst@chromium.org>
      Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Tested-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
      Link: https://lore.kernel.org/r/20220308100956.2750295-2-wenst@chromium.org
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e18eeb3e
    • Eric Dumazet's avatar
      watch_queue: Free the page array when watch_queue is dismantled · 375cd253
      Eric Dumazet authored
      commit b4902070 upstream.
      
      Commit 7ea1a012
      
       ("watch_queue: Free the alloc bitmap when the
      watch_queue is torn down") took care of the bitmap, but not the page
      array.
      
        BUG: memory leak
        unreferenced object 0xffff88810d9bc140 (size 32):
        comm "syz-executor335", pid 3603, jiffies 4294946994 (age 12.840s)
        hex dump (first 32 bytes):
          40 a7 40 04 00 ea ff ff 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:
           kmalloc_array include/linux/slab.h:621 [inline]
           kcalloc include/linux/slab.h:652 [inline]
           watch_queue_set_size+0x12f/0x2e0 kernel/watch_queue.c:251
           pipe_ioctl+0x82/0x140 fs/pipe.c:632
           vfs_ioctl fs/ioctl.c:51 [inline]
           __do_sys_ioctl fs/ioctl.c:874 [inline]
           __se_sys_ioctl fs/ioctl.c:860 [inline]
           __x64_sys_ioctl+0xfc/0x140 fs/ioctl.c:860
           do_syscall_x64 arch/x86/entry/common.c:50 [inline]
      
      Reported-by: default avatar <syzbot+25ea042ae28f3888727a@syzkaller.appspotmail.com>
      Fixes: c73be61c
      
       ("pipe: Add general notification queue support")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Cc: Jann Horn <jannh@google.com>
      Link: https://lore.kernel.org/r/20220322004654.618274-1-eric.dumazet@gmail.com/
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      375cd253
    • Herbert Xu's avatar
      crypto: arm/aes-neonbs-cbc - Select generic cbc and aes · 00c932b5
      Herbert Xu authored
      commit c8bd296c upstream.
      
      The algorithm __cbc-aes-neonbs requires a fallback so we need
      to select the config options for them or otherwise it will fail
      to register on boot-up.
      
      Fixes: 00b99ad2
      
       ("crypto: arm/aes-neonbs - Use generic cbc...")
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      00c932b5
    • Peter Zijlstra's avatar
      crypto: x86/poly1305 - Fixup SLS · 1a0ca96e
      Peter Zijlstra authored
      commit 7ed7aa4d upstream.
      
      Due to being a perl generated asm file, it got missed by the mass
      convertion script.
      
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_init_x86_64()+0x3a: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_blocks_x86_64()+0xf2: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_emit_x86_64()+0x37: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: __poly1305_block()+0x6d: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: __poly1305_init_avx()+0x1e8: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_blocks_avx()+0x18a: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_blocks_avx()+0xaf8: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_emit_avx()+0x99: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_blocks_avx2()+0x18a: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_blocks_avx2()+0x776: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_blocks_avx512()+0x18a: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_blocks_avx512()+0x796: missing int3 after ret
      arch/x86/crypto/poly1305-x86_64-cryptogams.o: warning: objtool: poly1305_blocks_avx512()+0x10bd: missing int3 after ret
      
      Fixes: f94909ce
      
       ("x86: Prepare asm files for straight-line-speculation")
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1a0ca96e
    • Robin Gong's avatar
      mailbox: imx: fix wakeup failure from freeze mode · b4dafd95
      Robin Gong authored
      commit 892cb524 upstream.
      
      Since IRQF_NO_SUSPEND used for imx mailbox driver, that means this irq
      can't be used for wakeup source so that can't wakeup from freeze mode.
      Add pm_system_wakeup() to wakeup from freeze mode.
      
      Fixes: b7b2796b
      
      ("mailbox: imx: ONLY IPC MU needs IRQF_NO_SUSPEND flag")
      Reviewed-by: default avatarJacky Bai <ping.bai@nxp.com>
      Reviewed-by: default avatarPeng Fan <peng.fan@nxp.com>
      Signed-off-by: default avatarRobin Gong <yibin.gong@nxp.com>
      Signed-off-by: default avatarPeng Fan <peng.fan@nxp.com>
      Signed-off-by: default avatarJassi Brar <jaswinder.singh@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b4dafd95
    • David Howells's avatar
      rxrpc: Fix call timer start racing with call destruction · 5e3c1114
      David Howells authored
      commit 4a7f62f9 upstream.
      
      The rxrpc_call struct has a timer used to handle various timed events
      relating to a call.  This timer can get started from the packet input
      routines that are run in softirq mode with just the RCU read lock held.
      Unfortunately, because only the RCU read lock is held - and neither ref or
      other lock is taken - the call can start getting destroyed at the same time
      a packet comes in addressed to that call.  This causes the timer - which
      was already stopped - to get restarted.  Later, the timer dispatch code may
      then oops if the timer got deallocated first.
      
      Fix this by trying to take a ref on the rxrpc_call struct and, if
      successful, passing that ref along to the timer.  If the timer was already
      running, the ref is discarded.
      
      The timer completion routine can then pass the ref along to the call's work
      item when it queues it.  If the timer or work item where already
      queued/running, the extra ref is discarded.
      
      Fixes: a158bdd3
      
       ("rxrpc: Fix call timeouts")
      Reported-by: default avatarMarc Dionne <marc.dionne@auristor.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Reviewed-by: default avatarMarc Dionne <marc.dionne@auristor.com>
      Tested-by: default avatarMarc Dionne <marc.dionne@auristor.com>
      cc: linux-afs@lists.infradead.org
      Link: http://lists.infradead.org/pipermail/linux-afs/2022-March/005073.html
      Link: https://lore.kernel.org/r/164865115696.2943015.11097991776647323586.stgit@warthog.procyon.org.uk
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5e3c1114
    • Xiaolong Huang's avatar
      rxrpc: fix some null-ptr-deref bugs in server_key.c · 4e1f670e
      Xiaolong Huang authored
      commit ff8376ad
      
       upstream.
      
      Some function calls are not implemented in rxrpc_no_security, there are
      preparse_server_key, free_preparse_server_key and destroy_server_key.
      When rxrpc security type is rxrpc_no_security, user can easily trigger a
      null-ptr-deref bug via ioctl. So judgment should be added to prevent it
      
      The crash log:
      user@syzkaller:~$ ./rxrpc_preparse_s
      [   37.956878][T15626] BUG: kernel NULL pointer dereference, address: 0000000000000000
      [   37.957645][T15626] #PF: supervisor instruction fetch in kernel mode
      [   37.958229][T15626] #PF: error_code(0x0010) - not-present page
      [   37.958762][T15626] PGD 4aadf067 P4D 4aadf067 PUD 4aade067 PMD 0
      [   37.959321][T15626] Oops: 0010 [#1] PREEMPT SMP
      [   37.959739][T15626] CPU: 0 PID: 15626 Comm: rxrpc_preparse_ Not tainted 5.17.0-01442-gb47d5a4f6b8d #43
      [   37.960588][T15626] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1 04/01/2014
      [   37.961474][T15626] RIP: 0010:0x0
      [   37.961787][T15626] Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6.
      [   37.962480][T15626] RSP: 0018:ffffc9000d9abdc0 EFLAGS: 00010286
      [   37.963018][T15626] RAX: ffffffff84335200 RBX: ffff888012a1ce80 RCX: 0000000000000000
      [   37.963727][T15626] RDX: 0000000000000000 RSI: ffffffff84a736dc RDI: ffffc9000d9abe48
      [   37.964425][T15626] RBP: ffffc9000d9abe48 R08: 0000000000000000 R09: 0000000000000002
      [   37.965118][T15626] R10: 000000000000000a R11: f000000000000000 R12: ffff888013145680
      [   37.965836][T15626] R13: 0000000000000000 R14: ffffffffffffffec R15: ffff8880432aba80
      [   37.966441][T15626] FS:  00007f2177907700(0000) GS:ffff88803ec00000(0000) knlGS:0000000000000000
      [   37.966979][T15626] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [   37.967384][T15626] CR2: ffffffffffffffd6 CR3: 000000004aaf1000 CR4: 00000000000006f0
      [   37.967864][T15626] Call Trace:
      [   37.968062][T15626]  <TASK>
      [   37.968240][T15626]  rxrpc_preparse_s+0x59/0x90
      [   37.968541][T15626]  key_create_or_update+0x174/0x510
      [   37.968863][T15626]  __x64_sys_add_key+0x139/0x1d0
      [   37.969165][T15626]  do_syscall_64+0x35/0xb0
      [   37.969451][T15626]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [   37.969824][T15626] RIP: 0033:0x43a1f9
      
      Signed-off-by: default avatarXiaolong Huang <butterflyhuangxx@gmail.com>
      Tested-by: default avatarXiaolong Huang <butterflyhuangxx@gmail.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Acked-by: default avatarMarc Dionne <marc.dionne@auristor.com>
      cc: linux-afs@lists.infradead.org
      Link: http://lists.infradead.org/pipermail/linux-afs/2022-March/005069.html
      Fixes: 12da59fc
      
       ("rxrpc: Hand server key parsing off to the security class")
      Link: https://lore.kernel.org/r/164865013439.2941502.8966285221215590921.stgit@warthog.procyon.org.uk
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e1f670e
    • Guangbin Huang's avatar
      net: hns3: fix software vlan talbe of vlan 0 inconsistent with hardware · 3c4903cf
      Guangbin Huang authored
      commit 7ed258f1 upstream.
      
      When user delete vlan 0, as driver will not delete vlan 0 for hardware in
      function hclge_set_vlan_filter_hw(), so vlan 0 in software vlan talbe should
      not be deleted.
      
      Fixes: fe4144d4
      
       ("net: hns3: sync VLAN filter entries when kill VLAN ID failed")
      Signed-off-by: default avatarGuangbin Huang <huangguangbin2@huawei.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3c4903cf
    • Yufeng Mo's avatar
      net: hns3: fix the concurrency between functions reading debugfs · 7c93be86
      Yufeng Mo authored
      commit 9c9a0421 upstream.
      
      Currently, the debugfs mechanism is that all functions share a
      global variable to save the pointer for obtaining data. When
      different functions concurrently access the same file node,
      repeated release exceptions occur. Therefore, the granularity
      of the pointer for storing the obtained data is adjusted to be
      private for each function.
      
      Fixes: 5e69ea7e
      
       ("net: hns3: refactor the debugfs process")
      Signed-off-by: default avatarYufeng Mo <moyufeng@huawei.com>
      Signed-off-by: default avatarGuangbin Huang <huangguangbin2@huawei.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7c93be86
    • Andrew Price's avatar
      gfs2: Make sure FITRIM minlen is rounded up to fs block size · b376ffc4
      Andrew Price authored
      commit 27ca8273 upstream.
      
      Per fstrim(8) we must round up the minlen argument to the fs block size.
      The current calculation doesn't take into account devices that have a
      discard granularity and requested minlen less than 1 fs block, so the
      value can get shifted away to zero in the translation to fs blocks.
      
      The zero minlen passed to gfs2_rgrp_send_discards() then allows
      sb_issue_discard() to be called with nr_sects == 0 which returns -EINVAL
      and results in gfs2_rgrp_send_discards() returning -EIO.
      
      Make sure minlen is never < 1 fs block by taking the max of the
      requested minlen and the fs block size before comparing to the device's
      discard granularity and shifting to fs blocks.
      
      Fixes: 076f0faa
      
       ("GFS2: Fix FITRIM argument handling")
      Signed-off-by: default avatarAndrew Price <anprice@redhat.com>
      Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b376ffc4
    • Andreas Gruenbacher's avatar
      gfs2: Fix gfs2_file_buffered_write endless loop workaround · fbb74bc0
      Andreas Gruenbacher authored
      commit 46f3e042 upstream.
      
      Since commit 554c577c, gfs2_file_buffered_write() can accidentally
      return a truncated iov_iter, which might confuse callers.  Fix that.
      
      Fixes: 554c577c
      
       ("gfs2: Prevent endless loops in gfs2_file_buffered_write")
      Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fbb74bc0
    • Andreas Gruenbacher's avatar
      gfs2: gfs2_setattr_size error path fix · d690d148
      Andreas Gruenbacher authored
      commit 7336905a upstream.
      
      When gfs2_setattr_size() fails, it calls gfs2_rs_delete(ip, NULL) to get
      rid of any reservations the inode may have.  Instead, it should pass in
      the inode's write count as the second parameter to allow
      gfs2_rs_delete() to figure out if the inode has any writers left.
      
      In a next step, there are two instances of gfs2_rs_delete(ip, NULL) left
      where we know that there can be no other users of the inode.  Replace
      those with gfs2_rs_deltree(&ip->i_res) to avoid the unnecessary write
      count check.
      
      With that, gfs2_rs_delete() is only called with the inode's actual write
      count, so get rid of the second parameter.
      
      Fixes: a097dc7e
      
       ("GFS2: Make rgrp reservations part of the gfs2_inode structure")
      Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d690d148
    • Carlos Llamas's avatar
      loop: fix ioctl calls using compat_loop_info · d25ea02f
      Carlos Llamas authored
      commit f941c51e upstream.
      
      Support for cryptoloop was deleted in commit 47e96246 ("block:
      remove support for cryptoloop and the xor transfer"), making the usage
      of loop_info->lo_encrypt_type obsolete. However, this member was also
      removed from the compat_loop_info definition and this breaks userspace
      ioctl calls for 32-bit binaries and CONFIG_COMPAT=y.
      
      This patch restores the compat_loop_info->lo_encrypt_type member and
      marks it obsolete as well as in the uapi header definitions.
      
      Fixes: 47e96246
      
       ("block: remove support for cryptoloop and the xor transfer")
      Signed-off-by: default avatarCarlos Llamas <cmllamas@google.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Link: https://lore.kernel.org/r/20220329201815.1347500-1-cmllamas@google.com
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d25ea02f
    • Tom Rix's avatar
      rtc: check if __rtc_read_time was successful · 11eaa135
      Tom Rix authored
      commit 915593a7 upstream.
      
      Clang static analysis reports this issue
      interface.c:810:8: warning: Passed-by-value struct
        argument contains uninitialized data
        now = rtc_tm_to_ktime(tm);
            ^~~~~~~~~~~~~~~~~~~
      
      tm is set by a successful call to __rtc_read_time()
      but its return status is not checked.  Check if
      it was successful before setting the enabled flag.
      Move the decl of err to function scope.
      
      Fixes: 2b2f5ff0
      
       ("rtc: interface: ignore expired timers when enqueuing new timers")
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Link: https://lore.kernel.org/r/20220326194236.2916310-1-trix@redhat.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      11eaa135
    • Miaoqian Lin's avatar
      rtc: gamecube: Fix refcount leak in gamecube_rtc_read_offset_from_sram · de66e4f2
      Miaoqian Lin authored
      commit 4b2dc39c upstream.
      
      The of_find_compatible_node() function returns a node pointer with
      refcount incremented, We should use of_node_put() on it when done
      Add the missing of_node_put() to release the refcount.
      
      Fixes: 86559400
      
       ("rtc: gamecube: Add a RTC driver for the GameCube, Wii and Wii U")
      Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Link: https://lore.kernel.org/r/20220309092225.6930-1-linmq006@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      de66e4f2
    • Masahiro Yamada's avatar
      modpost: restore the warning message for missing symbol versions · 455014ca
      Masahiro Yamada authored
      commit bf5c0c22 upstream.
      
      This log message was accidentally chopped off.
      
      I was wondering why this happened, but checking the ML log, Mark
      precisely followed my suggestion [1].
      
      I just used "..." because I was too lazy to type the sentence fully.
      Sorry for the confusion.
      
      [1]: https://lore.kernel.org/all/CAK7LNAR6bXXk9-ZzZYpTqzFqdYbQsZHmiWspu27rtsFxvfRuVA@mail.gmail.com/
      
      Fixes: 4a679593
      
       ("kbuild: modpost: Explicitly warn about unprototyped symbols")
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Acked-by: default avatarMark Brown <broonie@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      455014ca
    • Matthew Wilcox (Oracle)'s avatar
      XArray: Update the LRU list in xas_split() · 0fe42c4d
      Matthew Wilcox (Oracle) authored
      commit 3ed4bb77 upstream.
      
      When splitting a value entry, we may need to add the new nodes to the LRU
      list and remove the parent node from the LRU list.  The WARN_ON checks
      in shadow_lru_isolate() catch this oversight.  This bug was latent
      until we stopped splitting folios in shrink_page_list() with commit
      820c4e2e ("mm/vmscan: Free non-shmem folios without splitting them").
      That allows the creation of large shadow entries, and subsequently when
      trying to page in a small page, we will split the large shadow entry
      in __filemap_add_folio().
      
      Fixes: 8fc75643
      
       ("XArray: add xas_split")
      Reported-by: default avatarHugh Dickins <hughd@google.com>
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0fe42c4d
    • Matthew Wilcox (Oracle)'s avatar
      XArray: Include bitmap.h from xarray.h · 6e9b477f
      Matthew Wilcox (Oracle) authored
      commit 22f56b8e upstream.
      
      xas_find_chunk() calls find_next_bit(), which is defined in find.h,
      included from bitmap.h.  Inside the kernel, this isn't a problem because
      bitmap.h is included from cpumask.h which is dragged in (eventually)
      by gfp.h.  When building the test-suite, that doesn't happen, so we need
      to include bitmap.h explicitly.
      
      Fixes: 4ade0818
      
       ("tools: sync tools/bitmap with mother linux")
      Reported-by: default avatarLiam Howlett <liam.howlett@oracle.com>
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6e9b477f
    • Tom Rix's avatar
      can: mcp251xfd: mcp251xfd_register_get_dev_id(): fix return of error value · bcb0ab16
      Tom Rix authored
      commit fa7b514d upstream.
      
      Clang static analysis reports this issue:
      
      | mcp251xfd-core.c:1813:7: warning: The left operand
      |   of '&' is a garbage value
      |   FIELD_GET(MCP251XFD_REG_DEVID_ID_MASK, dev_id),
      |   ^                                      ~~~~~~
      
      dev_id is set in a successful call to mcp251xfd_register_get_dev_id().
      Though the status of calls made by mcp251xfd_register_get_dev_id() are
      checked and handled, their status' are not returned. So return err.
      
      Fixes: 55e5b97f
      
       ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN")
      Link: https://lore.kernel.org/all/20220319153128.2164120-1-trix@redhat.com
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bcb0ab16
    • Pavel Skripkin's avatar
      can: mcba_usb: properly check endpoint type · f2ec3cd0
      Pavel Skripkin authored
      commit 136bed0b upstream.
      
      Syzbot reported warning in usb_submit_urb() which is caused by wrong
      endpoint type. We should check that in endpoint is actually present to
      prevent this warning.
      
      Found pipes are now saved to struct mcba_priv and code uses them
      directly instead of making pipes in place.
      
      Fail log:
      
      | usb 5-1: BOGUS urb xfer, pipe 3 != type 1
      | WARNING: CPU: 1 PID: 49 at drivers/usb/core/urb.c:502 usb_submit_urb+0xed2/0x18a0 drivers/usb/core/urb.c:502
      | Modules linked in:
      | CPU: 1 PID: 49 Comm: kworker/1:2 Not tainted 5.17.0-rc6-syzkaller-00184-g38f80f42147f #0
      | Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
      | Workqueue: usb_hub_wq hub_event
      | RIP: 0010:usb_submit_urb+0xed2/0x18a0 drivers/usb/core/urb.c:502
      | ...
      | Call Trace:
      |  <TASK>
      |  mcba_usb_start drivers/net/can/usb/mcba_usb.c:662 [inline]
      |  mcba_usb_probe+0x8a3/0xc50 drivers/net/can/usb/mcba_usb.c:858
      |  usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396
      |  call_driver_probe drivers/base/dd.c:517 [inline]
      
      Fixes: 51f3baad
      
       ("can: mcba_usb: Add support for Microchip CAN BUS Analyzer")
      Link: https://lore.kernel.org/all/20220313100903.10868-1-paskripkin@gmail.com
      Reported-and-tested-by: default avatar <syzbot+3bc1dce0cc0052d60fde@syzkaller.appspotmail.com>
      Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Reviewed-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f2ec3cd0
    • Hangyu Hua's avatar
      can: mcba_usb: mcba_usb_start_xmit(): fix double dev_kfree_skb in error path · 42a4b0df
      Hangyu Hua authored
      commit 04c9b00b upstream.
      
      There is no need to call dev_kfree_skb() when usb_submit_urb() fails
      because can_put_echo_skb() deletes original skb and
      can_free_echo_skb() deletes the cloned skb.
      
      Fixes: 51f3baad
      
       ("can: mcba_usb: Add support for Microchip CAN BUS Analyzer")
      Link: https://lore.kernel.org/all/20220311080208.45047-1-hbh25y@gmail.com
      Signed-off-by: default avatarHangyu Hua <hbh25y@gmail.com>
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      42a4b0df
    • Matthew Wilcox (Oracle)'s avatar
      XArray: Fix xas_create_range() when multi-order entry present · 18f13edf
      Matthew Wilcox (Oracle) authored
      commit 3e3c6580 upstream.
      
      If there is already an entry present that is of order >= XA_CHUNK_SHIFT
      when we call xas_create_range(), xas_create_range() will misinterpret
      that entry as a node and dereference xa_node->parent, generally leading
      to a crash that looks something like this:
      
      general protection fault, probably for non-canonical address 0xdffffc0000000001:
      0000 [#1] PREEMPT SMP KASAN
      KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
      CPU: 0 PID: 32 Comm: khugepaged Not tainted 5.17.0-rc8-syzkaller-00003-g56e337f2cf13 #0
      RIP: 0010:xa_parent_locked include/linux/xarray.h:1207 [inline]
      RIP: 0010:xas_create_range+0x2d9/0x6e0 lib/xarray.c:725
      
      It's deterministically reproducable once you know what the problem is,
      but producing it in a live kernel requires khugepaged to hit a race.
      While the problem has been present since xas_create_range() was
      introduced, I'm not aware of a way to hit it before the page cache was
      converted to use multi-index entries.
      
      Fixes: 6b24ca4a
      
       ("mm: Use multi-index entries in the page cache")
      Reported-by: default avatar <syzbot+0d2b0bf32ca5cfd09f2e@syzkaller.appspotmail.com>
      Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      18f13edf
    • Jason A. Donenfeld's avatar
      wireguard: socket: ignore v6 endpoints when ipv6 is disabled · d277108f
      Jason A. Donenfeld authored
      commit 77fc73ac upstream.
      
      The previous commit fixed a memory leak on the send path in the event
      that IPv6 is disabled at compile time, but how did a packet even arrive
      there to begin with? It turns out we have previously allowed IPv6
      endpoints even when IPv6 support is disabled at compile time. This is
      awkward and inconsistent. Instead, let's just ignore all things IPv6,
      the same way we do other malformed endpoints, in the case where IPv6 is
      disabled.
      
      Fixes: e7096c13
      
       ("net: WireGuard secure network tunnel")
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d277108f
    • Wang Hai's avatar
      wireguard: socket: free skb in send6 when ipv6 is disabled · 0b19bcb7
      Wang Hai authored
      commit bbbf962d
      
       upstream.
      
      I got a memory leak report:
      
      unreferenced object 0xffff8881191fc040 (size 232):
        comm "kworker/u17:0", pid 23193, jiffies 4295238848 (age 3464.870s)
        hex dump (first 32 bytes):
          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 00 00 00 00 00  ................
        backtrace:
          [<ffffffff814c3ef4>] slab_post_alloc_hook+0x84/0x3b0
          [<ffffffff814c8977>] kmem_cache_alloc_node+0x167/0x340
          [<ffffffff832974fb>] __alloc_skb+0x1db/0x200
          [<ffffffff82612b5d>] wg_socket_send_buffer_to_peer+0x3d/0xc0
          [<ffffffff8260e94a>] wg_packet_send_handshake_initiation+0xfa/0x110
          [<ffffffff8260ec81>] wg_packet_handshake_send_worker+0x21/0x30
          [<ffffffff8119c558>] process_one_work+0x2e8/0x770
          [<ffffffff8119ca2a>] worker_thread+0x4a/0x4b0
          [<ffffffff811a88e0>] kthread+0x120/0x160
          [<ffffffff8100242f>] ret_from_fork+0x1f/0x30
      
      In function wg_socket_send_buffer_as_reply_to_skb() or wg_socket_send_
      buffer_to_peer(), the semantics of send6() is required to free skb. But
      when CONFIG_IPV6 is disable, kfree_skb() is missing. This patch adds it
      to fix this bug.
      
      Signed-off-by: default avatarWang Hai <wanghai38@huawei.com>
      Fixes: e7096c13
      
       ("net: WireGuard secure network tunnel")
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0b19bcb7
    • Jason A. Donenfeld's avatar
      wireguard: queueing: use CFI-safe ptr_ring cleanup function · fdf5fd40
      Jason A. Donenfeld authored
      commit ec59f128
      
       upstream.
      
      We make too nuanced use of ptr_ring to entirely move to the skb_array
      wrappers, but we at least should avoid the naughty function pointer cast
      when cleaning up skbs. Otherwise RAP/CFI will honk at us. This patch
      uses the __skb_array_destroy_skb wrapper for the cleanup, rather than
      directly providing kfree_skb, which is what other drivers in the same
      situation do too.
      
      Reported-by: default avatarPaX Team <pageexec@freemail.hu>
      Fixes: 886fcee9
      
       ("wireguard: receive: use ring buffer for incoming handshakes")
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fdf5fd40
    • Pankaj Raghav's avatar
      nvme: fix the read-only state for zoned namespaces with unsupposed features · 113aac06
      Pankaj Raghav authored
      commit 726be2c7 upstream.
      
      commit 2f4c9ba2 ("nvme: export zoned namespaces without Zone Append
      support read-only") marks zoned namespaces without append support
      read-only.  It does iso by setting NVME_NS_FORCE_RO in ns->flags in
      nvme_update_zone_info and checking for that flag later in
      nvme_update_disk_info to mark the disk as read-only.
      
      But commit 73d90386 ("nvme: cleanup zone information initialization")
      rearranged nvme_update_disk_info to be called before
      nvme_update_zone_info and thus not marking the disk as read-only.
      The call order cannot be just reverted because nvme_update_zone_info sets
      certain queue parameters such as zone_write_granularity that depend on the
      prior call to nvme_update_disk_info.
      
      Remove the call to set_disk_ro in nvme_update_disk_info. and call
      set_disk_ro after nvme_update_zone_info and nvme_update_disk_info to set
      the permission for ZNS drives correctly. The same applies to the
      multipath disk path.
      
      Fixes: 73d90386
      
       ("nvme: cleanup zone information initialization")
      Signed-off-by: default avatarPankaj Raghav <p.raghav@samsung.com>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      113aac06
    • Sungup Moon's avatar
      nvme: allow duplicate NSIDs for private namespaces · 529a9e8f
      Sungup Moon authored
      commit 5974ea7c upstream.
      
      A NVMe subsystem with multiple controller can have private namespaces
      that use the same NSID under some conditions:
      
       "If Namespace Management, ANA Reporting, or NVM Sets are supported, the
        NSIDs shall be unique within the NVM subsystem. If the Namespace
        Management, ANA Reporting, and NVM Sets are not supported, then NSIDs:
         a) for shared namespace shall be unique; and
         b) for private namespace are not required to be unique."
      
      Reference: Section 6.1.6 NSID and Namespace Usage; NVM Express 1.4c spec.
      
      Make sure this specific setup is supported in Linux.
      
      Fixes: 9ad1927a
      
       ("nvme: always search for namespace head")
      Signed-off-by: default avatarSungup Moon <sungup.moon@samsung.com>
      [hch: refactored and fixed the controller vs subsystem based naming
            conflict]
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      529a9e8f
    • Baokun Li's avatar
      ubifs: rename_whiteout: correct old_dir size computing · 6f36551c
      Baokun Li authored
      commit 70575727 upstream.
      
      When renaming the whiteout file, the old whiteout file is not deleted.
      Therefore, we add the old dentry size to the old dir like XFS.
      Otherwise, an error may be reported due to `fscki->calc_sz != fscki->size`
      in check_indes.
      
      Fixes: 9e0a1fff
      
       ("ubifs: Implement RENAME_WHITEOUT")
      Reported-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarBaokun Li <libaokun1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6f36551c
    • Zhihao Cheng's avatar
      ubifs: Fix to add refcount once page is set private · fbeb2139
      Zhihao Cheng authored
      commit 3b67db8a upstream.
      
      MM defined the rule [1] very clearly that once page was set with PG_private
      flag, we should increment the refcount in that page, also main flows like
      pageout(), migrate_page() will assume there is one additional page
      reference count if page_has_private() returns true. Otherwise, we may
      get a BUG in page migration:
      
        page:0000000080d05b9d refcount:-1 mapcount:0 mapping:000000005f4d82a8
        index:0xe2 pfn:0x14c12
        aops:ubifs_file_address_operations [ubifs] ino:8f1 dentry name:"f30e"
        flags: 0x1fffff80002405(locked|uptodate|owner_priv_1|private|node=0|
        zone=1|lastcpupid=0x1fffff)
        page dumped because: VM_BUG_ON_PAGE(page_count(page) != 0)
        ------------[ cut here ]------------
        kernel BUG at include/linux/page_ref.h:184!
        invalid opcode: 0000 [#1] SMP
        CPU: 3 PID: 38 Comm: kcompactd0 Not tainted 5.15.0-rc5
        RIP: 0010:migrate_page_move_mapping+0xac3/0xe70
        Call Trace:
          ubifs_migrate_page+0x22/0xc0 [ubifs]
          move_to_new_page+0xb4/0x600
          migrate_pages+0x1523/0x1cc0
          compact_zone+0x8c5/0x14b0
          kcompactd+0x2bc/0x560
          kthread+0x18c/0x1e0
          ret_from_fork+0x1f/0x30
      
      Before the time, we should make clean a concept, what does refcount means
      in page gotten from grab_cache_page_write_begin(). There are 2 situations:
      Situation 1: refcount is 3, page is created by __page_cache_alloc.
        TYPE_A - the write process is using this page
        TYPE_B - page is assigned to one certain mapping by calling
      	   __add_to_page_cache_locked()
        TYPE_C - page is added into pagevec list corresponding current cpu by
      	   calling lru_cache_add()
      Situation 2: refcount is 2, page is gotten from the mapping's tree
        TYPE_B - page has been assigned to one certain mapping
        TYPE_A - the write process is using this page (by calling
      	   page_cache_get_speculative())
      Filesystem releases one refcount by calling put_page() in xxx_write_end(),
      the released refcount corresponds to TYPE_A (write task is using it). If
      there are any processes using a page, page migration process will skip the
      page by judging whether expected_page_refs() equals to page refcount.
      
      The BUG is caused by following process:
          PA(cpu 0)                           kcompactd(cpu 1)
      				compact_zone
      ubifs_write_begin
        page_a = grab_cache_page_write_begin
          add_to_page_cache_lru
            lru_cache_add
              pagevec_add // put page into cpu 0's pagevec
        (refcnf = 3, for page creation process)
      ubifs_write_end
        SetPagePrivate(page_a) // doesn't increase page count !
        unlock_page(page_a)
        put_page(page_a)  // refcnt = 2
      				[...]
      
          PB(cpu 0)
      filemap_read
        filemap_get_pages
          add_to_page_cache_lru
            lru_cache_add
              __pagevec_lru_add // traverse all pages in cpu 0's pagevec
      	  __pagevec_lru_add_fn
      	    SetPageLRU(page_a)
      				isolate_migratepages
                                        isolate_migratepages_block
      				    get_page_unless_zero(page_a)
      				    // refcnt = 3
                                            list_add(page_a, from_list)
      				migrate_pages(from_list)
      				  __unmap_and_move
      				    move_to_new_page
      				      ubifs_migrate_page(page_a)
      				        migrate_page_move_mapping
      					  expected_page_refs get 3
                                        (migration[1] + mapping[1] + private[1])
      	 release_pages
      	   put_page_testzero(page_a) // refcnt = 3
                                                page_ref_freeze  // refcnt = 0
      	     page_ref_dec_and_test(0 - 1 = -1)
                                                page_ref_unfreeze
                                                  VM_BUG_ON_PAGE(-1 != 0, page)
      
      UBIFS doesn't increase the page refcount after setting private flag, which
      leads to page migration task believes the page is not used by any other
      processes, so the page is migrated. This causes concurrent accessing on
      page refcount between put_page() called by other process(eg. read process
      calls lru_cache_add) and page_ref_unfreeze() called by migration task.
      
      Actually zhangjun has tried to fix this problem [2] by recalculating page
      refcnt in ubifs_migrate_page(). It's better to follow MM rules [1], because
      just like Kirill suggested in [2], we need to check all users of
      page_has_private() helper. Like f2fs does in [3], fix it by adding/deleting
      refcount when setting/clearing private for a page. BTW, according to [4],
      we set 'page->private' as 1 because ubifs just simply SetPagePrivate().
      And, [5] provided a common helper to set/clear page private, ubifs can
      use this helper following the example of iomap, afs, btrfs, etc.
      
      Jump [6] to find a reproducer.
      
      [1] https://lore.kernel.org/lkml/2b19b3c4-2bc4-15fa-15cc-27a13e5c7af1@aol.com
      [2] https://www.spinics.net/lists/linux-mtd/msg04018.html
      [3] http://lkml.iu.edu/hypermail/linux/kernel/1903.0/03313.html
      [4] https://lore.kernel.org/linux-f2fs-devel/20210422154705.GO3596236@casper.infradead.org
      [5] https://lore.kernel.org/all/20200517214718.468-1-guoqing.jiang@cloud.ionos.com
      [6] https://bugzilla.kernel.org/show_bug.cgi?id=214961
      
      Fixes: 1e51764a
      
       ("UBIFS: add new flash file system")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fbeb2139
    • Zhihao Cheng's avatar
      ubifs: Fix read out-of-bounds in ubifs_wbuf_write_nolock() · 3b7fb891
      Zhihao Cheng authored
      commit 4f2262a3 upstream.
      
      Function ubifs_wbuf_write_nolock() may access buf out of bounds in
      following process:
      
      ubifs_wbuf_write_nolock():
        aligned_len = ALIGN(len, 8);   // Assume len = 4089, aligned_len = 4096
        if (aligned_len <= wbuf->avail) ... // Not satisfy
        if (wbuf->used) {
          ubifs_leb_write()  // Fill some data in avail wbuf
          len -= wbuf->avail;   // len is still not 8-bytes aligned
          aligned_len -= wbuf->avail;
        }
        n = aligned_len >> c->max_write_shift;
        if (n) {
          n <<= c->max_write_shift;
          err = ubifs_leb_write(c, wbuf->lnum, buf + written,
                                wbuf->offs, n);
          // n > len, read out of bounds less than 8(n-len) bytes
        }
      
      , which can be catched by KASAN:
        =========================================================
        BUG: KASAN: slab-out-of-bounds in ecc_sw_hamming_calculate+0x1dc/0x7d0
        Read of size 4 at addr ffff888105594ff8 by task kworker/u8:4/128
        Workqueue: writeback wb_workfn (flush-ubifs_0_0)
        Call Trace:
          kasan_report.cold+0x81/0x165
          nand_write_page_swecc+0xa9/0x160
          ubifs_leb_write+0xf2/0x1b0 [ubifs]
          ubifs_wbuf_write_nolock+0x421/0x12c0 [ubifs]
          write_head+0xdc/0x1c0 [ubifs]
          ubifs_jnl_write_inode+0x627/0x960 [ubifs]
          wb_workfn+0x8af/0xb80
      
      Function ubifs_wbuf_write_nolock() accepts that parameter 'len' is not 8
      bytes aligned, the 'len' represents the true length of buf (which is
      allocated in 'ubifs_jnl_xxx', eg. ubifs_jnl_write_inode), so
      ubifs_wbuf_write_nolock() must handle the length read from 'buf' carefully
      to write leb safely.
      
      Fetch a reproducer in [Link].
      
      Fixes: 1e51764a
      
       ("UBIFS: add new flash file system")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=214785
      Reported-by: default avatarChengsong Ke <kechengsong@huawei.com>
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3b7fb891
    • Zhihao Cheng's avatar
      ubifs: setflags: Make dirtied_ino_d 8 bytes aligned · 6262b150
      Zhihao Cheng authored
      commit 1b83ec05 upstream.
      
      Make 'ui->data_len' aligned with 8 bytes before it is assigned to
      dirtied_ino_d. Since 8871d84c("ubifs: convert to fileattr")
      applied, 'setflags()' only affects regular files and directories, only
      xattr inode, symlink inode and special inode(pipe/char_dev/block_dev)
      have none- zero 'ui->data_len' field, so assertion
      '!(req->dirtied_ino_d & 7)' cannot fail in ubifs_budget_space().
      To avoid assertion fails in future evolution(eg. setflags can operate
      special inodes), it's better to make dirtied_ino_d 8 bytes aligned,
      after all aligned size is still zero for regular files.
      
      Fixes: 1e51764a
      
       ("UBIFS: add new flash file system")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6262b150
    • Zhihao Cheng's avatar
      ubifs: Rectify space amount budget for mkdir/tmpfile operations · 02808530
      Zhihao Cheng authored
      commit a6dab660 upstream.
      
      UBIFS should make sure the flash has enough space to store dirty (Data
      that is newer than disk) data (in memory), space budget is exactly
      designed to do that. If space budget calculates less data than we need,
      'make_reservation()' will do more work(return -ENOSPC if no free space
      lelf, sometimes we can see "cannot reserve xxx bytes in jhead xxx, error
      -28" in ubifs error messages) with ubifs inodes locked, which may effect
      other syscalls.
      
      A simple way to decide how much space do we need when make a budget:
      See how much space is needed by 'make_reservation()' in ubifs_jnl_xxx()
      function according to corresponding operation.
      
      It's better to report ENOSPC in ubifs_budget_space(), as early as we can.
      
      Fixes: 474b9370 ("ubifs: Implement O_TMPFILE")
      Fixes: 1e51764a
      
       ("UBIFS: add new flash file system")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      02808530
    • Zhihao Cheng's avatar
      ubifs: Fix 'ui->dirty' race between do_tmpfile() and writeback work · 52b18c0b
      Zhihao Cheng authored
      commit 60eb3b9c upstream.
      
      'ui->dirty' is not protected by 'ui_mutex' in function do_tmpfile() which
      may race with ubifs_write_inode[wb_workfn] to access/update 'ui->dirty',
      finally dirty space is released twice.
      
      	open(O_TMPFILE)                wb_workfn
      do_tmpfile
        ubifs_budget_space(ino_req = { .dirtied_ino = 1})
        d_tmpfile // mark inode(tmpfile) dirty
        ubifs_jnl_update // without holding tmpfile's ui_mutex
          mark_inode_clean(ui)
            if (ui->dirty)
              ubifs_release_dirty_inode_budget(ui)  // release first time
                                         ubifs_write_inode
      				     mutex_lock(&ui->ui_mutex)
                                           ubifs_release_dirty_inode_budget(ui)
      				     // release second time
      				     mutex_unlock(&ui->ui_mutex)
            ui->dirty = 0
      
      Run generic/476 can reproduce following message easily
      (See reproducer in [Link]):
      
        UBIFS error (ubi0:0 pid 2578): ubifs_assert_failed [ubifs]: UBIFS assert
        failed: c->bi.dd_growth >= 0, in fs/ubifs/budget.c:554
        UBIFS warning (ubi0:0 pid 2578): ubifs_ro_mode [ubifs]: switched to
        read-only mode, error -22
        Workqueue: writeback wb_workfn (flush-ubifs_0_0)
        Call Trace:
          ubifs_ro_mode+0x54/0x60 [ubifs]
          ubifs_assert_failed+0x4b/0x80 [ubifs]
          ubifs_release_budget+0x468/0x5a0 [ubifs]
          ubifs_release_dirty_inode_budget+0x53/0x80 [ubifs]
          ubifs_write_inode+0x121/0x1f0 [ubifs]
          ...
          wb_workfn+0x283/0x7b0
      
      Fix it by holding tmpfile ubifs inode lock during ubifs_jnl_update().
      Similar problem exists in whiteout renaming, but previous fix("ubifs:
      Rename whiteout atomically") has solved the problem.
      
      Fixes: 474b9370
      
       ("ubifs: Implement O_TMPFILE")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=214765
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      52b18c0b
    • Zhihao Cheng's avatar
      ubifs: Rename whiteout atomically · 868de33a
      Zhihao Cheng authored
      commit 278d9a24 upstream.
      
      Currently, rename whiteout has 3 steps:
        1. create tmpfile(which associates old dentry to tmpfile inode) for
           whiteout, and store tmpfile to disk
        2. link whiteout, associate whiteout inode to old dentry agagin and
           store old dentry, old inode, new dentry on disk
        3. writeback dirty whiteout inode to disk
      
      Suddenly power-cut or error occurring(eg. ENOSPC returned by budget,
      memory allocation failure) during above steps may cause kinds of problems:
        Problem 1: ENOSPC returned by whiteout space budget (before step 2),
      	     old dentry will disappear after rename syscall, whiteout file
      	     cannot be found either.
      
      	     ls dir  // we get file, whiteout
      	     rename(dir/file, dir/whiteout, REANME_WHITEOUT)
      	     ENOSPC = ubifs_budget_space(&wht_req) // return
      	     ls dir  // empty (no file, no whiteout)
        Problem 2: Power-cut happens before step 3, whiteout inode with 'nlink=1'
      	     is not stored on disk, whiteout dentry(old dentry) is written
      	     on disk, whiteout file is lost on next mount (We get "dead
      	     directory entry" after executing 'ls -l' on whiteout file).
      
      Now, we use following 3 steps to finish rename whiteout:
        1. create an in-mem inode with 'nlink = 1' as whiteout
        2. ubifs_jnl_rename (Write on disk to finish associating old dentry to
           whiteout inode, associating new dentry with old inode)
        3. iput(whiteout)
      
      Rely writing in-mem inode on disk by ubifs_jnl_rename() to finish rename
      whiteout, which avoids middle disk state caused by suddenly power-cut
      and error occurring.
      
      Fixes: 9e0a1fff
      
       ("ubifs: Implement RENAME_WHITEOUT")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      868de33a
    • Zhihao Cheng's avatar
      ubifs: Add missing iput if do_tmpfile() failed in rename whiteout · 085062c6
      Zhihao Cheng authored
      commit 716b4573 upstream.
      
      whiteout inode should be put when do_tmpfile() failed if inode has been
      initialized. Otherwise we will get following warning during umount:
        UBIFS error (ubi0:0 pid 1494): ubifs_assert_failed [ubifs]: UBIFS
        assert failed: c->bi.dd_growth == 0, in fs/ubifs/super.c:1930
        VFS: Busy inodes after unmount of ubifs. Self-destruct in 5 seconds.
      
      Fixes: 9e0a1fff
      
       ("ubifs: Implement RENAME_WHITEOUT")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Suggested-by: default avatarSascha Hauer <s.hauer@pengutronix.de>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      085062c6
    • Zhihao Cheng's avatar
      ubifs: Fix deadlock in concurrent rename whiteout and inode writeback · 8b278c8d
      Zhihao Cheng authored
      commit afd42704 upstream.
      
      Following hung tasks:
      [   77.028764] task:kworker/u8:4    state:D stack:    0 pid:  132
      [   77.028820] Call Trace:
      [   77.029027]  schedule+0x8c/0x1b0
      [   77.029067]  mutex_lock+0x50/0x60
      [   77.029074]  ubifs_write_inode+0x68/0x1f0 [ubifs]
      [   77.029117]  __writeback_single_inode+0x43c/0x570
      [   77.029128]  writeback_sb_inodes+0x259/0x740
      [   77.029148]  wb_writeback+0x107/0x4d0
      [   77.029163]  wb_workfn+0x162/0x7b0
      
      [   92.390442] task:aa              state:D stack:    0 pid: 1506
      [   92.390448] Call Trace:
      [   92.390458]  schedule+0x8c/0x1b0
      [   92.390461]  wb_wait_for_completion+0x82/0xd0
      [   92.390469]  __writeback_inodes_sb_nr+0xb2/0x110
      [   92.390472]  writeback_inodes_sb_nr+0x14/0x20
      [   92.390476]  ubifs_budget_space+0x705/0xdd0 [ubifs]
      [   92.390503]  do_rename.cold+0x7f/0x187 [ubifs]
      [   92.390549]  ubifs_rename+0x8b/0x180 [ubifs]
      [   92.390571]  vfs_rename+0xdb2/0x1170
      [   92.390580]  do_renameat2+0x554/0x770
      
      , are caused by concurrent rename whiteout and inode writeback processes:
      	rename_whiteout(Thread 1)	        wb_workfn(Thread2)
      ubifs_rename
        do_rename
          lock_4_inodes (Hold ui_mutex)
          ubifs_budget_space
            make_free_space
              shrink_liability
      	  __writeback_inodes_sb_nr
      	    bdi_split_work_to_wbs (Queue new wb work)
      					      wb_do_writeback(wb work)
      						__writeback_single_inode
      					          ubifs_write_inode
      					            LOCK(ui_mutex)
      							   ↑
      	      wb_wait_for_completion (Wait wb work) <-- deadlock!
      
      Reproducer (Detail program in [Link]):
        1. SYS_renameat2("/mp/dir/file", "/mp/dir/whiteout", RENAME_WHITEOUT)
        2. Consume out of space before kernel(mdelay) doing budget for whiteout
      
      Fix it by doing whiteout space budget before locking ubifs inodes.
      BTW, it also fixes wrong goto tag 'out_release' in whiteout budget
      error handling path(It should at least recover dir i_size and unlock
      4 ubifs inodes).
      
      Fixes: 9e0a1fff
      
       ("ubifs: Implement RENAME_WHITEOUT")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=214733
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8b278c8d