Commit Graph

63 Commits

Author SHA1 Message Date
Namjae Jeon
d7fd859bea exfat: fix wrong hint_stat initialization in exfat_find_dir_entry()
We found the wrong hint_stat initialization in exfat_find_dir_entry().
It should be initialized when cluster is EXFAT_EOF_CLUSTER.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-07-03 12:40:30 +09:00
Namjae Jeon
6b09f3cef3 exfat: fix build error on 32bit & 4.19 lower kernel version
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-07-03 12:40:25 +09:00
Tetsuhiro Kohada
3870b2e3db exfat: optimize exfat_zeroed_cluster()
Replace part of exfat_zeroed_cluster() with exfat_update_bhs().

Signed-off-by: Tetsuhiro Kohada <kohada.t2@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-07-03 12:40:21 +09:00
Tetsuhiro Kohada
f9c8dcdd04 exfat: add error check when updating dir-entries
Add error check when synchronously updating dir-entries.

Suggested-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Tetsuhiro Kohada <kohada.t2@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-07-03 12:40:18 +09:00
Tetsuhiro Kohada
773256e416 exfat: write multiple sectors at once
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 <kohada.t2@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-07-03 12:40:14 +09:00
Sungjong Seo
dc9cda0d12 exfat: flush dirty metadata in fsync
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 <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-22 10:51:38 +09:00
Al Viro
a29e2ba970 exfat: fix memory leak in exfat_parse_param()
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:
    [<000000005bfe35d6>] kstrdup+0x36/0x70 mm/util.c:60
    [<0000000018ed3277>] exfat_parse_param+0x160/0x5e0
fs/exfat/super.c:276
    [<000000007680462b>] vfs_parse_fs_param+0x2b4/0x610
fs/fs_context.c:147
    [<0000000097c027f2>] vfs_parse_fs_string+0xe6/0x150
fs/fs_context.c:191
    [<00000000371bf78f>] generic_parse_monolithic+0x16f/0x1f0
fs/fs_context.c:231
    [<000000005ce5eb1b>] do_new_mount fs/namespace.c:2812 [inline]
    [<000000005ce5eb1b>] do_mount+0x12bb/0x1b30 fs/namespace.c:3141
    [<00000000b642040c>] __do_sys_mount fs/namespace.c:3350 [inline]
    [<00000000b642040c>] __se_sys_mount fs/namespace.c:3327 [inline]
    [<00000000b642040c>] __x64_sys_mount+0x18f/0x230 fs/namespace.c:3327
    [<000000003b024e98>] do_syscall_64+0xf6/0x7d0
arch/x86/entry/common.c:295
    [<00000000ce2b698c>] 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 <butterflyhuangxx@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-06-17 22:28:41 +09:00
Namjae Jeon
e20a3ecca3 exfat: move setting VOL_DIRTY over exfat_remove_entries()
Move setting VOL_DIRTY over exfat_remove_entries() to avoid unneeded
leaving VOL_DIRTY on -ENOTEMPTY.

Reported-by: Tetsuhiro Kohada <kohada.t2@gmail.com>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-17 22:08:41 +09:00
Namjae Jeon
305ebdd9a4 exfat: enable generic/452 test
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-17 22:08:38 +09:00
Hyunchul Lee
c5a2c1ed8b exfat: call sync_filesystem for read-only remount
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 <exfat>/
mount -o remount,ro <exfat>

the <exfat>/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 <hyc.lee@gmail.com>
Acked-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-17 22:08:35 +09:00
Tetsuhiro Kohada
117088f39d exfat: remove EXFAT_SB_DIRTY flag
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 <kohada.t2@gmail.com>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-17 22:08:32 +09:00
Matthew Wilcox (Oracle)
b457fd79f9 fs: convert mpage_readpages to mpage_readahead
Implement the new readahead aop and convert all callers (block_dev,
exfat, ext2, fat, gfs2, hpfs, isofs, jfs, nilfs2, ocfs2, omfs, qnx6,
reiserfs & udf).

The callers are all trivial except for GFS2 & OCFS2.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com> # ocfs2
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> # ocfs2
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Cc: Chao Yu <yuchao0@huawei.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Darrick J. Wong <darrick.wong@oracle.com>
Cc: Eric Biggers <ebiggers@google.com>
Cc: Gao Xiang <gaoxiang25@huawei.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: Miklos Szeredi <mszeredi@redhat.com>
Link: http://lkml.kernel.org/r/20200414150233.24495-17-willy@infradead.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-17 22:08:28 +09:00
Namjae Jeon
859f936085 exfat: add exfat version
cat /sys/module/exfat/version
5.8.1

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-06-13 10:33:17 +09:00
Dan Carpenter
7705950daf exfat: add missing brelse() calls on error paths
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 <Markus.Elfring@web.de>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-13 10:33:13 +09:00
Hyeongseok.Kim
3eff71ede6 exfat: Set the unused characters of FileName field to the value 0000h
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 <Hyeongseok@gmail.com>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-10 12:10:32 +09:00
hyeongseok.kim
d599ce4b37 exfat: fix range validation error in alloc and free cluster
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 <hyeongseok@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-09 09:37:13 +09:00
Dan Carpenter
eef5c756ed exfat: Fix pontential use after free in exfat_load_upcase_table()
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 <dan.carpenter@oracle.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-09 08:45:56 +09:00
Namjae Jeon
029c820f74 exfat: remove metadata journing tests
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-09 08:45:52 +09:00
Namjae Jeon
cd342c404e exfat: don't create exfat directory in the latest kernel
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-05 15:00:41 +09:00
Namjae Jeon
a9ac0a3eb4 exfat: fix incorrect update of stream entry in __exfat_truncate()
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. This patch
change entry pointer with stream entry.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-04 15:42:57 +09:00
Namjae Jeon
726d9e5327 exfat: remove unnecessary reassignment for p_uniname->name_len
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 for p_uniname->name_len is not needed and remove it.

Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-04 15:42:53 +09:00
Namjae Jeon
6a3cf32b8b exfat: add the dummy mount options to be backward compatible with staging/exfat
As Ubuntu and Fedora release new version used kernel version equal to or
higher than v5.4, They started to support kernel exfat filesystem.

Linus reported a mount error with new version of exfat on Fedora:

        exfat: Unknown parameter 'namecase'

This is because there is a difference in mount option between old
staging/exfat and new exfat.  And utf8, debug, and codepage options as
well as namecase have been removed from new exfat.

This patch add the dummy mount options as deprecated option to be
backward compatible with old one.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Eric Sandeen <sandeen@sandeen.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-04 15:42:50 +09:00
Tetsuhiro Kohada
149ef0460e exfat: standardize checksum calculation
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 <kohada.t2@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-04 15:42:47 +09:00
Tetsuhiro Kohada
af08f9af6f exfat: add boot region verification
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 <kohada.t2@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-04 15:42:44 +09:00
Tetsuhiro Kohada
c099996e89 exfat: separate the boot sector analysis
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 <kohada.t2@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-04 15:42:41 +09:00
Tetsuhiro Kohada
461d45b45c exfat: redefine PBR as boot_sector
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 <kohada.t2@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-04 15:42:38 +09:00
Tetsuhiro Kohada
9f140e2c22 exfat: optimize dir-cache
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 <kohada.tetsuhiro@dc.mitsubishielectric.co.jp>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-06-04 15:42:34 +09:00
Namjae Jeon
c486d443f8 exfat: use renamed repo in travis script
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-05-31 20:48:47 +09:00
Wei Yongjun
377751a684 exfat: fix possible memory leak in exfat_find()
'es' is malloced from exfat_get_dentry_set() in exfat_find() and should
be freed before leaving from the error handling cases, otherwise it will
cause memory leak.

Fixes: 5f2aa075070c ("exfat: add inode operations")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-05-26 21:36:02 +09:00
Namjae Jeon
acb6ab8052 exfat: add missing time_offset mount option for kernel version that is lower than 5.4 version
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-05-26 21:32:18 +09:00
Namjae Jeon
16897b770c exfat: remove so library copy
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-05-04 00:15:23 +09:00
Namjae Jeon
5b0b76fb88 exfat: add fsx xfstests
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-05-03 23:58:06 +09:00
Eric Sandeen
3f985aa6d5 exfat: use iter_file_splice_write
Doing copy_file_range() on exfat with a file opened for direct IO leads
to an -EFAULT:

# xfs_io -f -d -c "truncate 32768" \
       -c "copy_range -d 16384 -l 16384 -f 0" /mnt/test/junk
copy_range: Bad address

and the reason seems to be that we go through:

default_file_splice_write
 splice_from_pipe
  __splice_from_pipe
   write_pipe_buf
    __kernel_write
     new_sync_write
      generic_file_write_iter
       generic_file_direct_write
        exfat_direct_IO
         do_blockdev_direct_IO
          iov_iter_get_pages

and land in iterate_all_kinds(), which does "return -EFAULT" for our kvec
iter.

Setting exfat's splice_write to iter_file_splice_write fixes this and lets
fsx (which originally detected the problem) run to success from the xfstests
harness.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-05-03 23:26:10 +09:00
Tetsuhiro Kohada
9772742131 exfat: replace 'time_ms' with 'time_cs'
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 <kohada.t2@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-05-03 23:11:32 +09:00
Eric Sandeen
09241c144b exfat: truncate atimes to 2s granularity
exfat atimes are restricted to only 2s granularity so after
we set an atime, round it down to the nearest 2s and set the
sub-second component of the timestamp to 0.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-21 10:17:24 +09:00
Eric Sandeen
b0333de3ff exfat: properly set s_time_gran
The s_time_gran superblock field indicates the on-disk nanosecond
granularity of timestamps, and for exfat that seems to be 10ms, so
set s_time_gran to 10000000ns. Without this, in-memory timestamps
change when they get re-read from disk.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-21 10:17:21 +09:00
Jason Yan
db8bd78e86 exfat: remove the assignment of 0 to bool variable
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 <yanaijie@huawei.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-04-16 09:52:09 +09:00
Pali Rohár
d2424acd1d exfat: Remove unused functions exfat_high_surrogate() and exfat_low_surrogate()
After applying previous two patches, these functions are not used anymore.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-04-16 09:46:18 +09:00
Pali Rohár
233b4ba5ab exfat: Simplify exfat_utf8_d_hash() for code points above U+FFFF
Function partial_name_hash() takes long type value into which can be stored
one Unicode code point. Therefore conversion from UTF-32 to UTF-16 is not
needed.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2020-04-16 09:46:11 +09:00
Tetsuhiro Kohada
f65abe88d5 exfat: remove 'bps' mount-option
remount fails because exfat_show_options() returns unsupported option 'bps'.
> # mount -o ro,remount
> exfat: Unknown parameter 'bps'

To fix the problem, just remove 'bps' option from exfat_show_options().

Signed-off-by: Tetsuhiro Kohada <Kohada.Tetsuhiro@dc.MitsubishiElectric.co.jp>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-08 13:32:33 +09:00
Namjae Jeon
a4aad16ccf exfat: add create file and directory test
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-07 15:09:18 +09:00
Namjae Jeon
c3dd1a225a exfat: add more xfstests test in travis-CI
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-07 14:32:24 +09:00
Namjae Jeon
39018f1bca exfat: use truncate instead of dd command
Signed-off-by: Namjae Jeon <linkinjeon@gmail.com>
2020-04-06 22:21:36 +09:00
Namjae Jeon
2ac0fc42e4 exfat: disable build exfat with linus tree
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-06 14:58:30 +09:00
Namjae Jeon
1f5b9538b0 exfat: fix wrong exfat_oot repo directory name
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-06 14:29:20 +09:00
Namjae Jeon
91a2de7e4d exfat: fix wrong format option
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-06 14:24:30 +09:00
Tetsuhiro Kohada
0790539add exfat: Unify access to the boot sector
Unify access to boot sector via 'sbi->pbr_bh'.
This fixes vol_flags inconsistency at read failed in fs_set_vol_flags(),
and buffer_head leak in __exfat_fill_super().

Signed-off-by: Tetsuhiro Kohada <Kohada.Tetsuhiro@dc.MitsubishiElectric.co.jp>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-06 14:11:45 +09:00
Joe Perches
e08ed90147 exfat: Use a more common logging style
Remove the direct use of KERN_<LEVEL> in functions by creating
separate exfat_<level> macros.

Miscellanea:

o Remove several unnecessary terminating newlines in formats
o Realign arguments and fit to 80 columns where appropriate

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-06 12:50:48 +09:00
Thomas Backlund
fb5c212fe0 exfat: add missing MODULE_ALIAS_FS()
This adds the necessary MODULE_ALIAS_FS() to exfat so the module gets
automatically loaded when an exfat filesystem is mounted.

Signed-off-by: Thomas Backlund <tmb@mageia.org>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-06 12:32:06 +09:00
Pali Rohár
ff09ff7549 exfat: Fix discard support
Discard support was always unconditionally disabled. Now it is disabled
only in the case when blk_queue_discard() returns false.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
2020-04-06 12:32:03 +09:00