26 Dec, 2020

1 commit

  • commit 9eb78c25327548b905598975aa3ded4ef244b94a upstream.

    The table for Unicode upcase conversion requires an order-5 allocation,
    which may fail on a highly-fragmented system:

    pool-udisksd: page allocation failure: order:5,
    mode:0x40dc0(GFP_KERNEL|__GFP_COMP|__GFP_ZERO), nodemask=(null),
    cpuset=/,mems_allowed=0
    CPU: 4 PID: 3756880 Comm: pool-udisksd Tainted: G U
    5.8.10-200.fc32.x86_64 #1
    Hardware name: Dell Inc. XPS 13 9360/0PVG6D, BIOS 2.13.0 11/14/2019
    Call Trace:
    dump_stack+0x6b/0x88
    warn_alloc.cold+0x75/0xd9
    ? _cond_resched+0x16/0x40
    ? __alloc_pages_direct_compact+0x144/0x150
    __alloc_pages_slowpath.constprop.0+0xcfa/0xd30
    ? __schedule+0x28a/0x840
    ? __wait_on_bit_lock+0x92/0xa0
    __alloc_pages_nodemask+0x2df/0x320
    kmalloc_order+0x1b/0x80
    kmalloc_order_trace+0x1d/0xa0
    exfat_create_upcase_table+0x115/0x390 [exfat]
    exfat_fill_super+0x3ef/0x7f0 [exfat]
    ? sget_fc+0x1d0/0x240
    ? exfat_init_fs_context+0x120/0x120 [exfat]
    get_tree_bdev+0x15c/0x250
    vfs_get_tree+0x25/0xb0
    do_mount+0x7c3/0xaf0
    ? copy_mount_options+0xab/0x180
    __x64_sys_mount+0x8e/0xd0
    do_syscall_64+0x4d/0x90
    entry_SYSCALL_64_after_hwframe+0x44/0xa9

    Make the driver use kvcalloc() to eliminate the issue.

    Fixes: 370e812b3ec1 ("exfat: add nls operations")
    Cc: stable@vger.kernel.org #v5.7+
    Signed-off-by: Artem Labazov
    Signed-off-by: Namjae Jeon
    Signed-off-by: Greg Kroah-Hartman

    Artem Labazov
     

25 Oct, 2020

1 commit

  • Pull misc vfs updates from Al Viro:
    "Assorted stuff all over the place (the largest group here is
    Christoph's stat cleanups)"

    * 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    fs: remove KSTAT_QUERY_FLAGS
    fs: remove vfs_stat_set_lookup_flags
    fs: move vfs_fstatat out of line
    fs: implement vfs_stat and vfs_lstat in terms of vfs_fstatat
    fs: remove vfs_statx_fd
    fs: omfs: use kmemdup() rather than kmalloc+memcpy
    [PATCH] reduce boilerplate in fsid handling
    fs: Remove duplicated flag O_NDELAY occurring twice in VALID_OPEN_FLAGS
    selftests: mount: add nosymfollow tests
    Add a "nosymfollow" mount option.

    Linus Torvalds
     

22 Oct, 2020

7 commits


07 Oct, 2020

2 commits

  • syzbot reported warning message:

    Call Trace:
    __dump_stack lib/dump_stack.c:77 [inline]
    dump_stack+0x1d6/0x29e lib/dump_stack.c:118
    register_lock_class+0xf06/0x1520 kernel/locking/lockdep.c:893
    __lock_acquire+0xfd/0x2ae0 kernel/locking/lockdep.c:4320
    lock_acquire+0x148/0x720 kernel/locking/lockdep.c:5029
    __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
    _raw_spin_lock+0x2a/0x40 kernel/locking/spinlock.c:151
    spin_lock include/linux/spinlock.h:354 [inline]
    exfat_cache_inval_inode+0x30/0x280 fs/exfat/cache.c:226
    exfat_evict_inode+0x124/0x270 fs/exfat/inode.c:660
    evict+0x2bb/0x6d0 fs/inode.c:576
    exfat_fill_super+0x1e07/0x27d0 fs/exfat/super.c:681
    get_tree_bdev+0x3e9/0x5f0 fs/super.c:1342
    vfs_get_tree+0x88/0x270 fs/super.c:1547
    do_new_mount fs/namespace.c:2875 [inline]
    path_mount+0x179d/0x29e0 fs/namespace.c:3192
    do_mount fs/namespace.c:3205 [inline]
    __do_sys_mount fs/namespace.c:3413 [inline]
    __se_sys_mount+0x126/0x180 fs/namespace.c:3390
    do_syscall_64+0x31/0x70 arch/x86/entry/common.c:46
    entry_SYSCALL_64_after_hwframe+0x44/0xa9

    If exfat_read_root() returns an error, spinlock is used in
    exfat_evict_inode() without initialization. This patch combines
    exfat_cache_init_inode() with exfat_inode_init_once() to initialize
    spinlock by slab constructor.

    Fixes: c35b6810c495 ("exfat: add exfat cache")
    Cc: stable@vger.kernel.org # v5.7+
    Reported-by: syzbot
    Signed-off-by: Namjae Jeon

    Namjae Jeon
     
  • Fix missing result check of exfat_build_inode().
    And use PTR_ERR_OR_ZERO instead of PTR_ERR.

    Signed-off-by: Tetsuhiro Kohada
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     

19 Sep, 2020

1 commit


12 Aug, 2020

5 commits

  • MediaFailure and VolumeDirty should be retained if these are set before
    mounting.

    In '3.1.13.3 Media Failure Field' of exfat specification describe:

    If, upon mounting a volume, the value of this field is 1,
    implementations which scan the entire volume for media failures and
    record all failures as "bad" clusters in the FAT (or otherwise resolve
    media failures) may clear the value of this field to 0.

    Therefore, We should not clear MediaFailure without scanning volume.

    In '8.1 Recommended Write Ordering' of exfat specification describe:

    Clear the value of the VolumeDirty field to 0, if its value prior to
    the first step was 0.

    Therefore, We should not clear VolumeDirty after mounting.
    Also rename ERR_MEDIUM to MEDIA_FAILURE.

    Signed-off-by: Tetsuhiro Kohada
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • Replace part of exfat_zeroed_cluster() with exfat_update_bhs().
    And remove exfat_sync_bhs().

    Signed-off-by: Tetsuhiro Kohada
    Reviewed-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • Add error check when synchronously updating dir-entries.

    Suggested-by: Sungjong Seo
    Signed-off-by: Tetsuhiro Kohada
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • Write multiple sectors at once when updating dir-entries.
    Add exfat_update_bhs() for that. It wait for write completion once
    instead of sector by sector.
    It's only effective if sync enabled.

    Signed-off-by: Tetsuhiro Kohada
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • This flag is set/reset in exfat_put_super()/exfat_sync_fs()
    to avoid sync_blockdev().
    - exfat_put_super():
    Before calling this, the VFS has already called sync_filesystem(),
    so sync is never performed here.
    - exfat_sync_fs():
    After calling this, the VFS calls sync_blockdev(), so, it is meaningless
    to check EXFAT_SB_DIRTY or to bypass sync_blockdev() here.

    Remove the EXFAT_SB_DIRTY check to ensure synchronization.
    And remove the code related to the flag.

    Signed-off-by: Tetsuhiro Kohada
    Reviewed-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     

21 Jul, 2020

4 commits


29 Jun, 2020

5 commits

  • generic_file_fsync() exfat used could not guarantee the consistency of
    a file because it has flushed not dirty metadata but only dirty data pages
    for a file.

    Instead of that, use exfat_file_fsync() for files and directories so that
    it guarantees to commit both the metadata and data pages for a file.

    Signed-off-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Sungjong Seo
     
  • Move setting VOL_DIRTY over exfat_remove_entries() to avoid unneeded
    leaving VOL_DIRTY on -ENOTEMPTY.

    Fixes: 5f2aa075070c ("exfat: add inode operations")
    Cc: stable@vger.kernel.org # v5.7
    Reported-by: Tetsuhiro Kohada
    Reviewed-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Namjae Jeon
     
  • We need to commit dirty metadata and pages to disk
    before remounting exfat as read-only.

    This fixes a failure in xfstests generic/452

    generic/452 does the following:
    cp something /
    mount -o remount,ro

    the /something is corrupted. because while
    exfat is remounted as read-only, exfat doesn't
    have a chance to commit metadata and
    vfs invalidates page caches in a block device.

    Signed-off-by: Hyunchul Lee
    Acked-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Hyunchul Lee
     
  • If the second exfat_get_dentry() call fails then we need to release
    "old_bh" before returning. There is a similar bug in exfat_move_file().

    Fixes: 5f2aa075070c ("exfat: add inode operations")
    Reported-by: Markus Elfring
    Signed-off-by: Dan Carpenter
    Signed-off-by: Namjae Jeon

    Dan Carpenter
     
  • Some fsck tool complain that padding part of the FileName field
    is not set to the value 0000h. So let's maintain filesystem cleaner,
    as exfat's spec. recommendation.

    Signed-off-by: Hyeongseok.Kim
    Reviewed-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Hyeongseok.Kim
     

10 Jun, 2020

1 commit

  • Pull exfat update from Namjae Jeon:
    "Bug fixes:
    - Fix memory leak on mount failure with iocharset= option
    - Fix incorrect update of stream entry
    - Fix cluster range validation error

    Clean-ups:
    - Remove unused code and unneeded assignment
    - Rename variables in exfat structure as specification
    - Reorganize boot sector analysis code
    - Simplify exfat_utf8_d_hash and exfat_utf8_d_cmp()
    - Optimize exfat entry cache functions
    - Improve wording of EXFAT_DEFAULT_IOCHARSET config option

    New Feature:
    - Add boot region verification"

    * tag 'exfat-for-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat:
    exfat: Fix potential use after free in exfat_load_upcase_table()
    exfat: fix range validation error in alloc and free cluster
    exfat: fix incorrect update of stream entry in __exfat_truncate()
    exfat: fix memory leak in exfat_parse_param()
    exfat: remove unnecessary reassignment of p_uniname->name_len
    exfat: standardize checksum calculation
    exfat: add boot region verification
    exfat: separate the boot sector analysis
    exfat: redefine PBR as boot_sector
    exfat: optimize dir-cache
    exfat: replace 'time_ms' with 'time_cs'
    exfat: remove the assignment of 0 to bool variable
    exfat: Remove unused functions exfat_high_surrogate() and exfat_low_surrogate()
    exfat: Simplify exfat_utf8_d_hash() for code points above U+FFFF
    exfat: Improve wording of EXFAT_DEFAULT_IOCHARSET config option
    exfat: Use a more common logging style
    exfat: Simplify exfat_utf8_d_cmp() for code points above U+FFFF

    Linus Torvalds
     

09 Jun, 2020

13 commits

  • This code calls brelse(bh) and then dereferences "bh" on the next line
    resulting in a possible use after free. The brelse() should just be
    moved down a line.

    Fixes: b676fdbcf4c8 ("exfat: standardize checksum calculation")
    Signed-off-by: Dan Carpenter
    Signed-off-by: Namjae Jeon

    Dan Carpenter
     
  • There is check error in range condition that can never be entered
    even with invalid input.
    Replace incorrent checking code with already existing valid checker.

    Signed-off-by: hyeongseok.kim
    Acked-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    hyeongseok.kim
     
  • At truncate, there is a problem of incorrect updating in the file entry
    pointer instead of stream entry. This will cause the problem of
    overwriting the time field of the file entry to new_size. Fix it to
    update stream entry.

    Fixes: 98d917047e8b ("exfat: add file operations")
    Cc: stable@vger.kernel.org # v5.7
    Signed-off-by: Namjae Jeon

    Namjae Jeon
     
  • butt3rflyh4ck reported memory leak found by syzkaller.

    A param->string held by exfat_mount_options.

    BUG: memory leak

    unreferenced object 0xffff88801972e090 (size 8):
    comm "syz-executor.2", pid 16298, jiffies 4295172466 (age 14.060s)
    hex dump (first 8 bytes):
    6b 6f 69 38 2d 75 00 00 koi8-u..
    backtrace:
    [] kstrdup+0x36/0x70 mm/util.c:60
    [] exfat_parse_param+0x160/0x5e0
    fs/exfat/super.c:276
    [] vfs_parse_fs_param+0x2b4/0x610
    fs/fs_context.c:147
    [] vfs_parse_fs_string+0xe6/0x150
    fs/fs_context.c:191
    [] generic_parse_monolithic+0x16f/0x1f0
    fs/fs_context.c:231
    [] do_new_mount fs/namespace.c:2812 [inline]
    [] do_mount+0x12bb/0x1b30 fs/namespace.c:3141
    [] __do_sys_mount fs/namespace.c:3350 [inline]
    [] __se_sys_mount fs/namespace.c:3327 [inline]
    [] __x64_sys_mount+0x18f/0x230 fs/namespace.c:3327
    [] do_syscall_64+0xf6/0x7d0
    arch/x86/entry/common.c:295
    [] entry_SYSCALL_64_after_hwframe+0x49/0xb3

    exfat_free() should call exfat_free_iocharset(), to prevent a leak
    in case we fail after parsing iocharset= but before calling
    get_tree_bdev().

    Additionally, there's no point copying param->string in
    exfat_parse_param() - just steal it, leaving NULL in param->string.
    That's independent from the leak or fix thereof - it's simply
    avoiding an extra copy.

    Fixes: 719c1e182916 ("exfat: add super block operations")
    Cc: stable@vger.kernel.org # v5.7
    Reported-by: butt3rflyh4ck
    Signed-off-by: Al Viro
    Signed-off-by: Namjae Jeon

    Al Viro
     
  • kbuild test robot reported :

    fs/exfat/nls.c:531:22: warning: Variable 'p_uniname->name_len'
    is reassigned a value before the old one has been used.

    The reassignment of p_uniname->name_len is not needed and remove it.

    Reported-by: kbuild test robot
    Signed-off-by: Namjae Jeon

    Namjae Jeon
     
  • To clarify that it is a 16-bit checksum, the parts related to the 16-bit
    checksum are renamed and change type to u16.
    Furthermore, replace checksum calculation in exfat_load_upcase_table()
    with exfat_calc_checksum32().

    Signed-off-by: Tetsuhiro Kohada
    Reviewed-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • Add Boot-Regions verification specified in exFAT specification.
    Note that the checksum type is strongly related to the raw structure,
    so the'u32 'type is used to clarify the number of bits.

    Signed-off-by: Tetsuhiro Kohada
    Reviewed-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • Separate the boot sector analysis to read_boot_sector().
    And add a check for the fs_name field.
    Furthermore, add a strict consistency check, because overlapping areas
    can cause serious corruption.

    Signed-off-by: Tetsuhiro Kohada
    Reviewed-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • Aggregate PBR related definitions and redefine as "boot_sector" to comply
    with the exFAT specification.
    And, rename variable names including 'pbr'.

    Signed-off-by: Tetsuhiro Kohada
    Reviewed-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • Optimize directory access based on exfat_entry_set_cache.
    - Hold bh instead of copied d-entry.
    - Modify bh->data directly instead of the copied d-entry.
    - Write back the retained bh instead of rescanning the d-entry-set.
    And
    - Remove unused cache related definitions.

    Signed-off-by: Tetsuhiro Kohada
    Reviewed-by: Sungjong Seo
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • Replace time_ms with time_cs in the file directory entry structure
    and related functions.

    The unit of create_time_ms/modify_time_ms in File Directory Entry are not
    'milli-second', but 'centi-second'.
    The exfat specification uses the term '10ms', but instead use 'cs' as in
    msdos_fs.h.

    Signed-off-by: Tetsuhiro Kohada
    Signed-off-by: Namjae Jeon

    Tetsuhiro Kohada
     
  • There is no need to init 'sync' in exfat_set_vol_flags().
    This also fixes the following coccicheck warning:

    fs/exfat/super.c:104:6-10: WARNING: Assignment of 0/1 to bool variable

    Signed-off-by: Jason Yan
    Signed-off-by: Namjae Jeon

    Jason Yan
     
  • After applying previous two patches, these functions are not used anymore.

    Signed-off-by: Pali Rohár
    Signed-off-by: Namjae Jeon

    Pali Rohár