Skip to content

Commit

Permalink
Merge tag 'ntfs3_for_6.5' of https://github.com/Paragon-Software-Grou…
Browse files Browse the repository at this point in the history
…p/linux-ntfs3

Pull ntfs3 updates from Konstantin Komarov:
 "Updates:
   - support /proc/fs/ntfs3/<dev>/volinfo and label
   - alternative boot if primary boot is corrupted
   - small optimizations

  Fixes:
   - fix endian problems
   - fix logic errors
   - code refactoring and reformatting"

* tag 'ntfs3_for_6.5' of https://github.com/Paragon-Software-Group/linux-ntfs3:
  fs/ntfs3: Correct mode for label entry inside /proc/fs/ntfs3/
  fs/ntfs3: Add support /proc/fs/ntfs3/<dev>/volinfo and /proc/fs/ntfs3/<dev>/label
  fs/ntfs3: Fix endian problem
  fs/ntfs3: Add ability to format new mft records with bigger/smaller header
  fs/ntfs3: Code refactoring
  fs/ntfs3: Code formatting
  fs/ntfs3: Do not update primary boot in ntfs_init_from_boot()
  fs/ntfs3: Alternative boot if primary boot is corrupted
  fs/ntfs3: Mark ntfs dirty when on-disk struct is corrupted
  fs/ntfs3: Fix ntfs_atomic_open
  fs/ntfs3: Correct checking while generating attr_list
  fs/ntfs3: Use __GFP_NOWARN allocation at ntfs_load_attr_list()
  fs: ntfs3: Fix possible null-pointer dereferences in mi_read()
  fs/ntfs3: Return error for inconsistent extended attributes
  fs/ntfs3: Enhance sanity check while generating attr_list
  fs/ntfs3: Use wrapper i_blocksize() in ntfs_zero_range()
  ntfs: Fix panic about slab-out-of-bounds caused by ntfs_listxattr()
  • Loading branch information
torvalds committed Jul 7, 2023
2 parents 986ffe6 + 44b4494 commit 36b93ae
Show file tree
Hide file tree
Showing 17 changed files with 531 additions and 237 deletions.
2 changes: 1 addition & 1 deletion fs/ntfs3/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
sbi, run, vcn, lcn, to_allocate, &pre_alloc,
is_mft ? ALLOCATE_MFT : ALLOCATE_DEF, &alen,
is_mft ? 0 :
(sbi->record_size -
(sbi->record_size -
le32_to_cpu(rec->used) + 8) /
3 +
1,
Expand Down
7 changes: 3 additions & 4 deletions fs/ntfs3/attrlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)

if (!attr->non_res) {
lsize = le32_to_cpu(attr->res.data_size);
le = kmalloc(al_aligned(lsize), GFP_NOFS);
le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
if (!le) {
err = -ENOMEM;
goto out;
Expand Down Expand Up @@ -80,7 +80,7 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
if (err < 0)
goto out;

le = kmalloc(al_aligned(lsize), GFP_NOFS);
le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
if (!le) {
err = -ENOMEM;
goto out;
Expand Down Expand Up @@ -375,8 +375,7 @@ bool al_remove_le(struct ntfs_inode *ni, struct ATTR_LIST_ENTRY *le)
* al_delete_le - Delete first le from the list which matches its parameters.
*/
bool al_delete_le(struct ntfs_inode *ni, enum ATTR_TYPE type, CLST vcn,
const __le16 *name, size_t name_len,
const struct MFT_REF *ref)
const __le16 *name, u8 name_len, const struct MFT_REF *ref)
{
u16 size;
struct ATTR_LIST_ENTRY *le;
Expand Down
10 changes: 5 additions & 5 deletions fs/ntfs3/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
/* Check bits before 'bit'. */
ib = wnd->zone_bit == wnd->zone_end ||
bit < wnd->zone_end ?
0 :
wnd->zone_end;
0 :
wnd->zone_end;

while (bit > ib && wnd_is_free_hlp(wnd, bit - 1, 1)) {
bit -= 1;
Expand All @@ -298,8 +298,8 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
/* Check bits after 'end_in'. */
ib = wnd->zone_bit == wnd->zone_end ||
end_in > wnd->zone_bit ?
wnd->nbits :
wnd->zone_bit;
wnd->nbits :
wnd->zone_bit;

while (end_in < ib && wnd_is_free_hlp(wnd, end_in, 1)) {
end_in += 1;
Expand Down Expand Up @@ -418,7 +418,7 @@ static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)
n3 = rb_first(&wnd->count_tree);
wnd->extent_max =
n3 ? rb_entry(n3, struct e_node, count.node)->count.key :
0;
0;
return;
}

Expand Down
6 changes: 3 additions & 3 deletions fs/ntfs3/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
{
int err = 0;
struct address_space *mapping = inode->i_mapping;
u32 blocksize = 1 << inode->i_blkbits;
u32 blocksize = i_blocksize(inode);
pgoff_t idx = vbo >> PAGE_SHIFT;
u32 from = vbo & (PAGE_SIZE - 1);
pgoff_t idx_end = (vbo_to + PAGE_SIZE - 1) >> PAGE_SHIFT;
Expand All @@ -192,7 +192,7 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
for (; idx < idx_end; idx += 1, from = 0) {
page_off = (loff_t)idx << PAGE_SHIFT;
to = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off) :
PAGE_SIZE;
PAGE_SIZE;
iblock = page_off >> inode->i_blkbits;

page = find_or_create_page(mapping, idx,
Expand Down Expand Up @@ -1078,7 +1078,7 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
goto out;

ret = is_compressed(ni) ? ntfs_compress_write(iocb, from) :
__generic_file_write_iter(iocb, from);
__generic_file_write_iter(iocb, from);

out:
inode_unlock(inode);
Expand Down
58 changes: 31 additions & 27 deletions fs/ntfs3/frecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct ATTR_STD_INFO *ni_std(struct ntfs_inode *ni)

attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO)) :
NULL;
NULL;
}

/*
Expand All @@ -92,7 +92,7 @@ struct ATTR_STD_INFO5 *ni_std5(struct ntfs_inode *ni)
attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL);

return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO5)) :
NULL;
NULL;
}

/*
Expand Down Expand Up @@ -236,6 +236,7 @@ struct ATTRIB *ni_find_attr(struct ntfs_inode *ni, struct ATTRIB *attr,
return attr;

out:
ntfs_inode_err(&ni->vfs_inode, "failed to parse mft record");
ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
return NULL;
}
Expand Down Expand Up @@ -384,7 +385,7 @@ bool ni_add_subrecord(struct ntfs_inode *ni, CLST rno, struct mft_inode **mi)
* ni_remove_attr - Remove all attributes for the given type/name/id.
*/
int ni_remove_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
const __le16 *name, size_t name_len, bool base_only,
const __le16 *name, u8 name_len, bool base_only,
const __le16 *id)
{
int err;
Expand Down Expand Up @@ -517,6 +518,9 @@ ni_ins_new_attr(struct ntfs_inode *ni, struct mft_inode *mi,
*/
static int ni_repack(struct ntfs_inode *ni)
{
#if 1
return 0;
#else
int err = 0;
struct ntfs_sb_info *sbi = ni->mi.sbi;
struct mft_inode *mi, *mi_p = NULL;
Expand Down Expand Up @@ -639,6 +643,7 @@ static int ni_repack(struct ntfs_inode *ni)

run_close(&run);
return err;
#endif
}

/*
Expand Down Expand Up @@ -813,10 +818,8 @@ int ni_create_attr_list(struct ntfs_inode *ni)
* Looks like one record_size is always enough.
*/
le = kmalloc(al_aligned(rs), GFP_NOFS);
if (!le) {
err = -ENOMEM;
goto out;
}
if (!le)
return -ENOMEM;

mi_get_ref(&ni->mi, &le->ref);
ni->attr_list.le = le;
Expand Down Expand Up @@ -865,15 +868,16 @@ int ni_create_attr_list(struct ntfs_inode *ni)

if (to_free > free_b) {
err = -EINVAL;
goto out1;
goto out;
}
}

/* Allocate child MFT. */
err = ntfs_look_free_mft(sbi, &rno, is_mft, ni, &mi);
if (err)
goto out1;
goto out;

err = -EINVAL;
/* Call mi_remove_attr() in reverse order to keep pointers 'arr_move' valid. */
while (to_free > 0) {
struct ATTRIB *b = arr_move[--nb];
Expand All @@ -882,7 +886,8 @@ int ni_create_attr_list(struct ntfs_inode *ni)

attr = mi_insert_attr(mi, b->type, Add2Ptr(b, name_off),
b->name_len, asize, name_off);
WARN_ON(!attr);
if (!attr)
goto out;

mi_get_ref(mi, &le_b[nb]->ref);
le_b[nb]->id = attr->id;
Expand All @@ -892,17 +897,20 @@ int ni_create_attr_list(struct ntfs_inode *ni)
attr->id = le_b[nb]->id;

/* Remove from primary record. */
WARN_ON(!mi_remove_attr(NULL, &ni->mi, b));
if (!mi_remove_attr(NULL, &ni->mi, b))
goto out;

if (to_free <= asize)
break;
to_free -= asize;
WARN_ON(!nb);
if (!nb)
goto out;
}

attr = mi_insert_attr(&ni->mi, ATTR_LIST, NULL, 0,
lsize + SIZEOF_RESIDENT, SIZEOF_RESIDENT);
WARN_ON(!attr);
if (!attr)
goto out;

attr->non_res = 0;
attr->flags = 0;
Expand All @@ -916,14 +924,12 @@ int ni_create_attr_list(struct ntfs_inode *ni)
ni->attr_list.dirty = false;

mark_inode_dirty(&ni->vfs_inode);
goto out;
return 0;

out1:
out:
kfree(ni->attr_list.le);
ni->attr_list.le = NULL;
ni->attr_list.size = 0;

out:
return err;
}

Expand Down Expand Up @@ -1638,14 +1644,13 @@ int ni_delete_all(struct ntfs_inode *ni)
* Return: File name attribute by its value.
*/
struct ATTR_FILE_NAME *ni_fname_name(struct ntfs_inode *ni,
const struct cpu_str *uni,
const struct le_str *uni,
const struct MFT_REF *home_dir,
struct mft_inode **mi,
struct ATTR_LIST_ENTRY **le)
{
struct ATTRIB *attr = NULL;
struct ATTR_FILE_NAME *fname;
struct le_str *fns;

if (le)
*le = NULL;
Expand All @@ -1669,10 +1674,9 @@ struct ATTR_FILE_NAME *ni_fname_name(struct ntfs_inode *ni,
if (uni->len != fname->name_len)
goto next;

fns = (struct le_str *)&fname->name_len;
if (ntfs_cmp_names_cpu(uni, fns, NULL, false))
if (ntfs_cmp_names(uni->name, uni->len, fname->name, uni->len, NULL,
false))
goto next;

return fname;
}

Expand Down Expand Up @@ -1757,8 +1761,8 @@ int ni_new_attr_flags(struct ntfs_inode *ni, enum FILE_ATTRIBUTE new_fa)

/* Resize nonresident empty attribute in-place only. */
new_asize = (new_aflags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) ?
(SIZEOF_NONRESIDENT_EX + 8) :
(SIZEOF_NONRESIDENT + 8);
(SIZEOF_NONRESIDENT_EX + 8) :
(SIZEOF_NONRESIDENT + 8);

if (!mi_resize_attr(mi, attr, new_asize - le32_to_cpu(attr->size)))
return -EOPNOTSUPP;
Expand Down Expand Up @@ -2910,7 +2914,7 @@ int ni_remove_name(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
/* Find name in record. */
mi_get_ref(&dir_ni->mi, &de_name->home);

fname = ni_fname_name(ni, (struct cpu_str *)&de_name->name_len,
fname = ni_fname_name(ni, (struct le_str *)&de_name->name_len,
&de_name->home, &mi, &le);
if (!fname)
return -ENOENT;
Expand Down Expand Up @@ -3160,8 +3164,8 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup,
__le64 valid_le;

dup->alloc_size = is_attr_ext(attr) ?
attr->nres.total_size :
attr->nres.alloc_size;
attr->nres.total_size :
attr->nres.alloc_size;
dup->data_size = attr->nres.data_size;

if (new_valid > data_size)
Expand Down
Loading

0 comments on commit 36b93ae

Please sign in to comment.