Commit Graph

487 Commits

Author SHA1 Message Date
Dr. David Alan Gilbert
bdd6baf740
fs/ntfs3: Remove unused al_delete_le
'al_delete_le' was added by:
Commit be71b5cba2 ("fs/ntfs3: Add attrib operations")

but has remained unused; there is an al_remove_le which seems
to be being used instead.

Remove 'al_delete_le'.

Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
2024-10-01 12:19:05 +03:00
Konstantin Komarov
689ecd06ef
fs/ntfs3: Rename ntfs3_setattr into ntfs_setattr
Aligning names to a single naming convention.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:45 +03:00
Konstantin Komarov
568f1140b9
fs/ntfs3: Replace fsparam_flag_no -> fsparam_flag
Based on the experience with an error related to incorrect parsing of the
'nocase' option, I decided to simplify the list and type of parameters.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:45 +03:00
Konstantin Komarov
6b39bfaeec
fs/ntfs3: Add support for the compression attribute
Support added for empty files and directories only.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:44 +03:00
Konstantin Komarov
9a2d6a40b8
fs/ntfs3: Implement fallocate for compressed files
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:44 +03:00
Konstantin Komarov
70dd48ca3a
fs/ntfs3: Make checks in run_unpack more clear
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:43 +03:00
Konstantin Komarov
c4a8ba3342
fs/ntfs3: Add rough attr alloc_size check
Reported-by: syzbot+c6d94bedd910a8216d25@syzkaller.appspotmail.com
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:43 +03:00
Konstantin Komarov
1fd21919de
fs/ntfs3: Stale inode instead of bad
Fixed the logic of processing inode with wrong sequence number.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:42 +03:00
Konstantin Komarov
56c16d5459
fs/ntfs3: Refactor enum_rstbl to suppress static checker
Comments and brief description of function enum_rstbl added.

Fixes: b46acd6a6a ("fs/ntfs3: Add NTFS journal")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:42 +03:00
Konstantin Komarov
62fea783f9
fs/ntfs3: Fix sparse warning in ni_fiemap
The interface of fiemap_fill_next_extent_k() was modified
to eliminate the sparse warning.

Fixes: d57431c6f5 ("fs/ntfs3: Do copy_to_user out of run_lock")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202406271920.hndE8N6D-lkp@intel.com/
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:41 +03:00
Konstantin Komarov
5b2db72345
fs/ntfs3: Fix warning possible deadlock in ntfs_set_state
Use non-zero subkey to skip analyzer warnings.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Reported-by: syzbot+c2ada45c23d98d646118@syzkaller.appspotmail.com
2024-09-03 16:58:41 +03:00
Konstantin Komarov
ffe718c992
fs/ntfs3: Fix sparse warning for bigendian
Fixes: 220cf0498b ("fs/ntfs3: Simplify initialization of $AttrDef and $UpCase")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202404181111.Wz8a1qX6-lkp@intel.com/
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:40 +03:00
Konstantin Komarov
e4a7d60a89
fs/ntfs3: Separete common code for file_read/write iter/splice
The common code for handling encrypted, dedup, and compressed files
has been moved to check_read_restriction() and check_write_restriction().

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:40 +03:00
Konstantin Komarov
acdbd67bf9
fs/ntfs3: Optimize large writes into sparse file
Optimized cluster allocation by allocating a large chunk in advance
before writing, instead of allocating during the writing process
by clusters.
Essentially replicates the logic of fallocate.

Fixes: 4342306f0f ("fs/ntfs3: Add file operations and implementation")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:39 +03:00
Konstantin Komarov
2db86f7995
fs/ntfs3: Do not call file_modified if collapse range failed
Fixes: 4342306f0f ("fs/ntfs3: Add file operations and implementation")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:39 +03:00
Andrew Ballance
9931122d04
fs/ntfs3: Check if more than chunk-size bytes are written
A incorrectly formatted chunk may decompress into
more than LZNT_CHUNK_SIZE bytes and a index out of bounds
will occur in s_max_off.

Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:39 +03:00
lei lu
556bdf27c2
ntfs3: Add bounds checking to mi_enum_attr()
Added bounds checking to make sure that every attr don't stray beyond
valid memory region.

Signed-off-by: lei lu <llfamsec@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:38 +03:00
Thorsten Blum
a4f2b9a787
fs/ntfs3: Use swap() to improve code
Use the swap() macro to simplify the code and improve its readability.

Fixes the following Coccinelle/coccicheck warning reported by
swap.cocci:

  WARNING opportunity for swap()

Compile-tested only.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-09-03 16:58:38 +03:00
Linus Torvalds
5ea6d72489 ntfs3 changes for 6.11-rc1
Added:
     simple fileattr has been implement.
 Fixed:
     transform resident to nonresident for compressed files;
     the format of the "nocase" mount option;
     getting file type;
     many other internal bugs.
 Refactored:
     unused function and macros have been removed;
     partial transition from page to folio (suggested by Matthew Wilcox);
     legacy ntfs support.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEh0DEKNP0I9IjwfWEqbAzH4MkB7YFAmaeJa0ACgkQqbAzH4Mk
 B7b0AQ/7BboEmiLXjgstyF6ZQcjT3NamN09OLOTu2SMlGhqcOjIn1xNNMCJPRdVR
 KJ+/LG1jYMqdyjsR7n5jt8Bxn4njLInPD3+X89NcKPVJxWFYQvg/5pzZw5YF3XGA
 G9f0ky1nvSrTLCTWuGktfkFJ5xBg9J7qkvnjiUsXUtPrf6SS2hH5z2uVbKMOfua9
 xSoe76hrxVxfpYTfk2ERtS8b1gcQUnT/JrAO88yboNQ8i4IVqdxYUklhHoXZnUHr
 YZHcg04SD9+oqrK5eR2xx2belBEVPVoD0BJZkLQyNNqBfVwNzPXc9fkkpyc9Co5R
 duRyXPzc9qYkFVCsGY9N73F+2lPmruGcz5TYgn1EOZUb00dOdZd2LF/J96lRmwpC
 hICtwbNgMWp2a9jAC1G0lNhmvHHiFZgR5o7N3YmkMUaCCcT1Z3jeCCQ2JGE0cNCf
 lwaMda6jxl1f7QLUP53qlgTb+RlVbVpPFD0JQ7mEeZyRuZepgsk6xkHQ2G18nicQ
 hmui6t+tQYMgoosjOAy8rlTtcK5A3gKUbYyeStCUNVANEM6XPUpjF0lRQuwN2bae
 p/nTjLBESp6ulq1MIFZ2h6G3OlX+vkezHULo80QWfoIEuMtkZ+MyypmNUDqlBE5n
 pDyE8bcqCVI4ODGzIj8aoZSDggQYM49SqDzmoNc7n2hhFkS8Drk=
 =sA5e
 -----END PGP SIGNATURE-----

Merge tag 'ntfs3_for_6.11' of https://github.com/Paragon-Software-Group/linux-ntfs3

Pull ntfs3 updates from Konstantin Komarov:
 "New code:
   - simple fileattr support

  Fixes:
   - transform resident to nonresident for compressed files
   - the format of the "nocase" mount option
   - getting file type
   - many other internal bugs

  Refactoring:
   - remove unused functions and macros
   - partial transition from page to folio (suggested by Matthew Wilcox)
   - legacy ntfs support"

* tag 'ntfs3_for_6.11' of https://github.com/Paragon-Software-Group/linux-ntfs3: (42 commits)
  fs/ntfs3: Fix formatting, change comments, renaming
  fs/ntfs3: Update log->page_{mask,bits} if log->page_size changed
  fs/ntfs3: Implement simple fileattr
  fs/ntfs3: Redesign legacy ntfs support
  fs/ntfs3: Use function file_inode to get inode from file
  fs/ntfs3: Minor ntfs_list_ea refactoring
  fs/ntfs3: Check more cases when directory is corrupted
  fs/ntfs3: Do copy_to_user out of run_lock
  fs/ntfs3: Keep runs for $MFT::$ATTR_DATA and $MFT::$ATTR_BITMAP
  fs/ntfs3: Missed error return
  fs/ntfs3: Fix the format of the "nocase" mount option
  fs/ntfs3: Fix field-spanning write in INDEX_HDR
  ntfs3: Convert attr_wof_frame_info() to use a folio
  ntfs3: Convert ni_readpage_cmpr() to take a folio
  ntfs3: Convert ntfs_get_frame_pages() to use a folio
  ntfs3: Remove calls to set/clear the error flag
  ntfs3: Convert attr_make_nonresident to use a folio
  ntfs3: Convert attr_data_write_resident to use a folio
  ntfs3: Convert ntfs_write_end() to work on a folio
  ntfs3: Convert attr_data_read_resident() to take a folio
  ...
2024-07-22 10:50:18 -07:00
Konstantin Komarov
911daf695a
fs/ntfs3: Fix formatting, change comments, renaming
Huacai Chen:
	The label end_reply is obviously a typo. It should be "replay" in this
	context. So rename end_reply to end_replay.

Suggested-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:46 +03:00
Huacai Chen
2fef55d8f7
fs/ntfs3: Update log->page_{mask,bits} if log->page_size changed
If an NTFS file system is mounted to another system with different
PAGE_SIZE from the original system, log->page_size will change in
log_replay(), but log->page_{mask,bits} don't change correspondingly.
This will cause a panic because "u32 bytes = log->page_size - page_off"
will get a negative value in the later read_log_page().

Cc: stable@vger.kernel.org
Fixes: b46acd6a6a ("fs/ntfs3: Add NTFS journal")
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:46 +03:00
Konstantin Komarov
5bfb91c712
fs/ntfs3: Implement simple fileattr
fileattr added to support chattr.
Supported attributes:  compressed and immutable.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:45 +03:00
Konstantin Komarov
1ff2e95660
fs/ntfs3: Redesign legacy ntfs support
1) Make is_legacy_ntfs static inline.
2) Put legacy file_operations under #if IS_ENABLED(CONFIG_NTFS_FS).

Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Christian Brauner <brauner@kernel.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:45 +03:00
Konstantin Komarov
b9906f8162
fs/ntfs3: Use function file_inode to get inode from file
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:45 +03:00
Konstantin Komarov
791e5620c1
fs/ntfs3: Minor ntfs_list_ea refactoring
For easy internal debugging.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:44 +03:00
Konstantin Komarov
7443753436
fs/ntfs3: Check more cases when directory is corrupted
Mark ntfs dirty in this case.
Rename ntfs_filldir to ntfs_dir_emit.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:44 +03:00
Konstantin Komarov
d57431c6f5
fs/ntfs3: Do copy_to_user out of run_lock
In order not to call copy_to_user (from fiemap_fill_next_extent)
we allocate memory in the kernel, fill it and copy it to user memory
after up_read(run_lock).

Reported-by: syzbot+36bb70085ef6edc2ebb9@syzkaller.appspotmail.com
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:43 +03:00
Konstantin Komarov
eb95678ee9
fs/ntfs3: Keep runs for $MFT::$ATTR_DATA and $MFT::$ATTR_BITMAP
We skip the run_truncate_head call also for $MFT::$ATTR_BITMAP.
Otherwise wnd_map()/run_lookup_entry will not find the disk position for the bitmap parts.

Fixes: 0e5b044cbf ("fs/ntfs3: Refactoring attr_set_size to restore after errors")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:43 +03:00
Konstantin Komarov
2cbbd96820
fs/ntfs3: Missed error return
Fixes: 3f3b442b5a ("fs/ntfs3: Add bitmap")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:42 +03:00
Konstantin Komarov
d392e85fd1
fs/ntfs3: Fix the format of the "nocase" mount option
The 'nocase' option was mistakenly added as fsparam_flag_no
with the 'no' prefix, causing the case-insensitive mode to require
the 'nonocase' option to be enabled.

Fixes: a3a956c78e ("fs/ntfs3: Add option "nocase"")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-07-11 12:19:42 +03:00
Eric Sandeen
c449cb5d1b
ntfs3: Convert to new uid/gid option parsing helpers
Convert to new uid/gid option parsing helpers

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Link: https://lore.kernel.org/r/04bf30db-8542-48dc-9060-7f7dc08eda22@redhat.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-07-02 06:21:19 +02:00
Konstantin Komarov
2f3e176fee
fs/ntfs3: Fix field-spanning write in INDEX_HDR
Fields flags and res[3] replaced with one 4 byte flags.

Fixes: 4534a70b70 ("fs/ntfs3: Add headers and misc files")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:58 +03:00
Matthew Wilcox (Oracle)
c091354d6b
ntfs3: Convert attr_wof_frame_info() to use a folio
This involves converting all users of offs_page to offs_folio, but
it's worth it because we get rid of a lot of hidden calls to
compound_head().  We continue to use order-0 folios here, and convert
back to a struct page to call ntfs_bio_pages().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:58 +03:00
Matthew Wilcox (Oracle)
4d89b6716b
ntfs3: Convert ni_readpage_cmpr() to take a folio
We still use an array of pages for the decompression, but this removes
a few calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:57 +03:00
Matthew Wilcox (Oracle)
584f60ba22
ntfs3: Convert ntfs_get_frame_pages() to use a folio
The function still takes an array of pages, but use a folio internally.
This function would deadlock against itself if used with large folios
(as it locks each page), so we can be a little sloppy with the conversion
back from folio to page for now.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:57 +03:00
Matthew Wilcox (Oracle)
326a6fd960
ntfs3: Remove calls to set/clear the error flag
Nobody checks the error flag on ntfs3 folios, so stop setting and
clearing it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:56 +03:00
Matthew Wilcox (Oracle)
562d060bed
ntfs3: Convert attr_make_nonresident to use a folio
Fetch a folio from the page cache instead of a page and operate on it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
[almaz.alexandrovich@paragon-software.com: skip using folio_end_read]
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:56 +03:00
Matthew Wilcox (Oracle)
d0c3df6277
ntfs3: Convert attr_data_write_resident to use a folio
Now that both callers of attr_data_write_resident() have a folio, pass
it in and use memcpy_from_folio() to handle all the gnarly highmem
multi-page problems.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:55 +03:00
Matthew Wilcox (Oracle)
0c1a156644
ntfs3: Convert ntfs_write_end() to work on a folio
Convert the passed page back into a folio and use the folio APIs, saving
a few hidden calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:55 +03:00
Matthew Wilcox (Oracle)
ab055cf9db
ntfs3: Convert attr_data_read_resident() to take a folio
Now that all three callers have a folio, pass it in and use
folio_fill_tail() to do the hard work of filling the folio.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:55 +03:00
Matthew Wilcox (Oracle)
00c91073a3
ntfs3: Convert ntfs_write_begin to use a folio
Retrieve a folio from the page cache instead of a precise page.
This function is now large folio safe, but its called function is not.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:54 +03:00
Matthew Wilcox (Oracle)
f27a8e2d3d
ntfs3: Convert ntfs_read_folio to use a folio
Remove the struct page conversion, and use a folio throughout.  We still
convert back to a struct page for calling some internal functions,
but those will change soon.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:54 +03:00
Andy Shevchenko
b366809dd1
fs/ntfs3: Drop stray '\' (backslash) in formatting string
CHECK   /home/andy/prj/linux-topic-uart/fs/ntfs3/super.c
fs/ntfs3/super.c:471:23: warning: unknown escape sequence: '\%'

Drop stray '\' (backslash) in formatting string.

Fixes: d27e202b9a ("fs/ntfs3: Add more info into /proc/fs/ntfs3/<dev>/volinfo")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:53 +03:00
Konstantin Komarov
ea7376783a
fs/ntfs3: Add some comments
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:53 +03:00
Konstantin Komarov
83cf2cf18c
fs/ntfs3: Rename variables
New names make it easier to read code.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:52 +03:00
Konstantin Komarov
702d4930eb
fs/ntfs3: Add a check for attr_names and oatbl
Added out-of-bound checking for *ane (ATTR_NAME_ENTRY).

Reported-by: lei lu <llfamsec@gmail.com>
Fixes: 865e7a7700 ("fs/ntfs3: Reduce stack usage")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:52 +03:00
lei lu
50c4787965
fs/ntfs3: Validate ff offset
This adds sanity checks for ff offset. There is a check
on rt->first_free at first, but walking through by ff
without any check. If the second ff is a large offset.
We may encounter an out-of-bound read.

Signed-off-by: lei lu <llfamsec@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:51 +03:00
Konstantin Komarov
f28d0866d8
fs/ntfs3: Correct undo if ntfs_create_inode failed
Clusters allocated for Extended Attributes, must be freed
when rolling back inode creation.

Fixes: 82cae269cf ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:51 +03:00
Konstantin Komarov
a0dde5d7a5
fs/ntfs3: One more reason to mark inode bad
In addition to returning an error, mark the node as bad.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:51 +03:00
Konstantin Komarov
69505fe98f
fs/ntfs3: Replace inode_trylock with inode_lock
The issue was detected due to xfstest 465 failing.

Fixes: 4342306f0f ("fs/ntfs3: Add file operations and implementation")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2024-06-26 15:48:50 +03:00