Skip to content
  1. Dec 24, 2021
    • Baokun Li's avatar
      ubifs: fix double return leb in ubifs_garbage_collect · 0d765021
      Baokun Li authored
      
      
      If ubifs_garbage_collect_leb() returns -EAGAIN and enters the "out"
      branch, ubifs_return_leb will execute twice on the same lnum. This
      can cause data loss in concurrency situations.
      
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarBaokun Li <libaokun1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      0d765021
    • Baokun Li's avatar
      ubifs: fix slab-out-of-bounds in ubifs_change_lp · 88618fee
      Baokun Li authored
      
      
      Hulk Robot reported a KASAN report about slab-out-of-bounds:
       ==================================================================
       BUG: KASAN: slab-out-of-bounds in ubifs_change_lp+0x3a9/0x1390 [ubifs]
       Read of size 8 at addr ffff888101c961f8 by task fsstress/1068
       [...]
       Call Trace:
        check_memory_region+0x1c1/0x1e0
        ubifs_change_lp+0x3a9/0x1390 [ubifs]
        ubifs_change_one_lp+0x170/0x220 [ubifs]
        ubifs_garbage_collect+0x7f9/0xda0 [ubifs]
        ubifs_budget_space+0xfe4/0x1bd0 [ubifs]
        ubifs_write_begin+0x528/0x10c0 [ubifs]
      
       Allocated by task 1068:
        kmemdup+0x25/0x50
        ubifs_lpt_lookup_dirty+0x372/0xb00 [ubifs]
        ubifs_update_one_lp+0x46/0x260 [ubifs]
        ubifs_tnc_end_commit+0x98b/0x1720 [ubifs]
        do_commit+0x6cb/0x1950 [ubifs]
        ubifs_run_commit+0x15a/0x2b0 [ubifs]
        ubifs_budget_space+0x1061/0x1bd0 [ubifs]
        ubifs_write_begin+0x528/0x10c0 [ubifs]
       [...]
       ==================================================================
      
      In ubifs_garbage_collect(), if ubifs_find_dirty_leb returns an error,
      lp is an uninitialized variable. But lp.num might be used in the out
      branch, which is a random value. If the value is -1 or another value
      that can pass the check, soob may occur in the ubifs_change_lp() in
      the following procedure.
      
      To solve this problem, we initialize lp.lnum to -1, and then initialize
      it correctly in ubifs_find_dirty_leb, which is not equal to -1, and
      ubifs_return_leb is executed only when lp.lnum != -1.
      
      if find a retained or indexing LEB and continue to next loop, but break
      before find another LEB, the "taken" flag of this LEB will be cleaned
      in ubi_return_lebi(). This bug has also been fixed in this patch.
      
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarBaokun Li <libaokun1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      88618fee
    • Dan Carpenter's avatar
      ubifs: fix snprintf() length check · d3de970b
      Dan Carpenter authored
      
      
      The snprintf() function returns the number of bytes (not including the
      NUL terminator) which would have been printed if there were enough
      space.  So it can be greater than UBIFS_DFS_DIR_LEN.  And actually if
      it equals UBIFS_DFS_DIR_LEN then that's okay so this check is too
      strict.
      
      Fixes: 9a620291fc01 ("ubifs: Export filesystem error counters")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      d3de970b
    • Stefan Schaeckeler's avatar
      ubifs: Document sysfs nodes · 58225631
      Stefan Schaeckeler authored
      
      
      Add documentation for the new sysfs nodes
      
       /sys/fs/ubifs/ubiX_Y/errors_magic
       /sys/fs/ubifs/ubiX_Y/errors_node
       /sys/fs/ubifs/ubiX_Y/errors_crc
      
      Signed-off-by: default avatarStefan Schaeckeler <sschaeck@cisco.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      58225631
    • Stefan Schaeckeler's avatar
      ubifs: Export filesystem error counters · 2e3cbf42
      Stefan Schaeckeler authored
      
      
      Not all ubifs filesystem errors are propagated to userspace.
      
      Export bad magic, bad node and crc errors via sysfs. This allows userspace
      to notice filesystem errors:
      
       /sys/fs/ubifs/ubiX_Y/errors_magic
       /sys/fs/ubifs/ubiX_Y/errors_node
       /sys/fs/ubifs/ubiX_Y/errors_crc
      
      The counters are reset to 0 with a remount.
      
      Signed-off-by: default avatarStefan Schaeckeler <sschaeck@cisco.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      2e3cbf42
    • Petr Cvachoucek's avatar
      ubifs: Error path in ubifs_remount_rw() seems to wrongly free write buffers · 3fea4d9d
      Petr Cvachoucek authored
      
      
      it seems freeing the write buffers in the error path of the
      ubifs_remount_rw() is wrong. It leads later to a kernel oops like this:
      
      [10016.431274] UBIFS (ubi0:0): start fixing up free space
      [10090.810042] UBIFS (ubi0:0): free space fixup complete
      [10090.814623] UBIFS error (ubi0:0 pid 512): ubifs_remount_fs: cannot
      spawn "ubifs_bgt0_0", error -4
      [10101.915108] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started,
      PID 517
      [10105.275498] Unable to handle kernel NULL pointer dereference at
      virtual address 0000000000000030
      [10105.284352] Mem abort info:
      [10105.287160]   ESR = 0x96000006
      [10105.290252]   EC = 0x25: DABT (current EL), IL = 32 bits
      [10105.295592]   SET = 0, FnV = 0
      [10105.298652]   EA = 0, S1PTW = 0
      [10105.301848] Data abort info:
      [10105.304723]   ISV = 0, ISS = 0x00000006
      [10105.308573]   CM = 0, WnR = 0
      [10105.311564] user pgtable: 4k pages, 48-bit VAs, pgdp=00000000f03d1000
      [10105.318034] [0000000000000030] pgd=00000000f6cee003,
      pud=00000000f4884003, pmd=0000000000000000
      [10105.326783] Internal error: Oops: 96000006 [#1] PREEMPT SMP
      [10105.332355] Modules linked in: ath10k_pci ath10k_core ath mac80211
      libarc4 cfg80211 nvme nvme_core cryptodev(O)
      [10105.342468] CPU: 3 PID: 518 Comm: touch Tainted: G           O
      5.4.3 #1
      [10105.349517] Hardware name: HYPEX CPU (DT)
      [10105.353525] pstate: 40000005 (nZcv daif -PAN -UAO)
      [10105.358324] pc : atomic64_try_cmpxchg_acquire.constprop.22+0x8/0x34
      [10105.364596] lr : mutex_lock+0x1c/0x34
      [10105.368253] sp : ffff000075633aa0
      [10105.371563] x29: ffff000075633aa0 x28: 0000000000000001
      [10105.376874] x27: ffff000076fa80c8 x26: 0000000000000004
      [10105.382185] x25: 0000000000000030 x24: 0000000000000000
      [10105.387495] x23: 0000000000000000 x22: 0000000000000038
      [10105.392807] x21: 000000000000000c x20: ffff000076fa80c8
      [10105.398119] x19: ffff000076fa8000 x18: 0000000000000000
      [10105.403429] x17: 0000000000000000 x16: 0000000000000000
      [10105.408741] x15: 0000000000000000 x14: fefefefefefefeff
      [10105.414052] x13: 0000000000000000 x12: 0000000000000fe0
      [10105.419364] x11: 0000000000000fe0 x10: ffff000076709020
      [10105.424675] x9 : 0000000000000000 x8 : 00000000000000a0
      [10105.429986] x7 : ffff000076fa80f4 x6 : 0000000000000030
      [10105.435297] x5 : 0000000000000000 x4 : 0000000000000000
      [10105.440609] x3 : 0000000000000000 x2 : ffff00006f276040
      [10105.445920] x1 : ffff000075633ab8 x0 : 0000000000000030
      [10105.451232] Call trace:
      [10105.453676]  atomic64_try_cmpxchg_acquire.constprop.22+0x8/0x34
      [10105.459600]  ubifs_garbage_collect+0xb4/0x334
      [10105.463956]  ubifs_budget_space+0x398/0x458
      [10105.468139]  ubifs_create+0x50/0x180
      [10105.471712]  path_openat+0x6a0/0x9b0
      [10105.475284]  do_filp_open+0x34/0x7c
      [10105.478771]  do_sys_open+0x78/0xe4
      [10105.482170]  __arm64_sys_openat+0x1c/0x24
      [10105.486180]  el0_svc_handler+0x84/0xc8
      [10105.489928]  el0_svc+0x8/0xc
      [10105.492808] Code: 52800013 17fffffb d2800003 f9800011 (c85ffc05)
      [10105.498903] ---[ end trace 46b721d93267a586 ]---
      
      To reproduce the problem:
      
      1. Filesystem initially mounted read-only, free space fixup flag set.
      
      2. mount -o remount,rw <mountpoint>
      
      3. it takes some time (free space fixup running)
          ... try to terminate running mount by CTRL-C
          ... does not respond, only after free space fixup is complete
          ... then "ubifs_remount_fs: cannot spawn "ubifs_bgt0_0", error -4"
      
      4. mount -o remount,rw <mountpoint>
          ... now finished instantly (fixup already done).
      
      5. Create file or just unmount the filesystem and we get the oops.
      
      Cc: <stable@vger.kernel.org>
      Fixes: b50b9f40 ("UBIFS: do not free write-buffers when in R/O mode")
      Signed-off-by: default avatarPetr Cvachoucek <cvachoucek@gmail.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      3fea4d9d
    • Cai Huoqing's avatar
      ubifs: Make use of the helper macro kthread_run() · d98c6c35
      Cai Huoqing authored
      
      
      Repalce kthread_create/wake_up_process() with kthread_run()
      to simplify the code.
      
      Signed-off-by: default avatarCai Huoqing <caihuoqing@baidu.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      d98c6c35
    • Kai Song's avatar
      ubi: Fix a mistake in comment · bc7849e2
      Kai Song authored
      
      
      Fixes: 2a734bb8 ("UBI: use debugfs for the extra checks knobs")
      There is a mistake in docstrings, it should be ubi_debugfs_exit_dev
      instead of dbg_debug_exit_dev.
      
      Signed-off-by: default avatarKai Song <songkai01@inspur.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      bc7849e2
    • Alexander Dahl's avatar
      ubifs: Fix spelling mistakes · 7296c8af
      Alexander Dahl authored
      
      
      Found with `codespell -i 3 -w fs/ubifs/**` and proof reading that parts.
      
      Signed-off-by: default avatarAlexander Dahl <ada@thorsis.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      7296c8af
  2. Dec 20, 2021
  3. Dec 19, 2021
  4. Dec 18, 2021