Skip to content

Commit 36b93ae

Browse files
committed
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()
2 parents 986ffe6 + 44b4494 commit 36b93ae

File tree

17 files changed

+531
-237
lines changed

17 files changed

+531
-237
lines changed

fs/ntfs3/attrib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
573573
sbi, run, vcn, lcn, to_allocate, &pre_alloc,
574574
is_mft ? ALLOCATE_MFT : ALLOCATE_DEF, &alen,
575575
is_mft ? 0 :
576-
(sbi->record_size -
576+
(sbi->record_size -
577577
le32_to_cpu(rec->used) + 8) /
578578
3 +
579579
1,

fs/ntfs3/attrlist.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
5252

5353
if (!attr->non_res) {
5454
lsize = le32_to_cpu(attr->res.data_size);
55-
le = kmalloc(al_aligned(lsize), GFP_NOFS);
55+
le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
5656
if (!le) {
5757
err = -ENOMEM;
5858
goto out;
@@ -80,7 +80,7 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
8080
if (err < 0)
8181
goto out;
8282

83-
le = kmalloc(al_aligned(lsize), GFP_NOFS);
83+
le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
8484
if (!le) {
8585
err = -ENOMEM;
8686
goto out;
@@ -375,8 +375,7 @@ bool al_remove_le(struct ntfs_inode *ni, struct ATTR_LIST_ENTRY *le)
375375
* al_delete_le - Delete first le from the list which matches its parameters.
376376
*/
377377
bool al_delete_le(struct ntfs_inode *ni, enum ATTR_TYPE type, CLST vcn,
378-
const __le16 *name, size_t name_len,
379-
const struct MFT_REF *ref)
378+
const __le16 *name, u8 name_len, const struct MFT_REF *ref)
380379
{
381380
u16 size;
382381
struct ATTR_LIST_ENTRY *le;

fs/ntfs3/bitmap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
287287
/* Check bits before 'bit'. */
288288
ib = wnd->zone_bit == wnd->zone_end ||
289289
bit < wnd->zone_end ?
290-
0 :
291-
wnd->zone_end;
290+
0 :
291+
wnd->zone_end;
292292

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

304304
while (end_in < ib && wnd_is_free_hlp(wnd, end_in, 1)) {
305305
end_in += 1;
@@ -418,7 +418,7 @@ static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)
418418
n3 = rb_first(&wnd->count_tree);
419419
wnd->extent_max =
420420
n3 ? rb_entry(n3, struct e_node, count.node)->count.key :
421-
0;
421+
0;
422422
return;
423423
}
424424

fs/ntfs3/file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
179179
{
180180
int err = 0;
181181
struct address_space *mapping = inode->i_mapping;
182-
u32 blocksize = 1 << inode->i_blkbits;
182+
u32 blocksize = i_blocksize(inode);
183183
pgoff_t idx = vbo >> PAGE_SHIFT;
184184
u32 from = vbo & (PAGE_SIZE - 1);
185185
pgoff_t idx_end = (vbo_to + PAGE_SIZE - 1) >> PAGE_SHIFT;
@@ -192,7 +192,7 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
192192
for (; idx < idx_end; idx += 1, from = 0) {
193193
page_off = (loff_t)idx << PAGE_SHIFT;
194194
to = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off) :
195-
PAGE_SIZE;
195+
PAGE_SIZE;
196196
iblock = page_off >> inode->i_blkbits;
197197

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

10801080
ret = is_compressed(ni) ? ntfs_compress_write(iocb, from) :
1081-
__generic_file_write_iter(iocb, from);
1081+
__generic_file_write_iter(iocb, from);
10821082

10831083
out:
10841084
inode_unlock(inode);

fs/ntfs3/frecord.c

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct ATTR_STD_INFO *ni_std(struct ntfs_inode *ni)
7777

7878
attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
7979
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO)) :
80-
NULL;
80+
NULL;
8181
}
8282

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

9494
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO5)) :
95-
NULL;
95+
NULL;
9696
}
9797

9898
/*
@@ -236,6 +236,7 @@ struct ATTRIB *ni_find_attr(struct ntfs_inode *ni, struct ATTRIB *attr,
236236
return attr;
237237

238238
out:
239+
ntfs_inode_err(&ni->vfs_inode, "failed to parse mft record");
239240
ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
240241
return NULL;
241242
}
@@ -384,7 +385,7 @@ bool ni_add_subrecord(struct ntfs_inode *ni, CLST rno, struct mft_inode **mi)
384385
* ni_remove_attr - Remove all attributes for the given type/name/id.
385386
*/
386387
int ni_remove_attr(struct ntfs_inode *ni, enum ATTR_TYPE type,
387-
const __le16 *name, size_t name_len, bool base_only,
388+
const __le16 *name, u8 name_len, bool base_only,
388389
const __le16 *id)
389390
{
390391
int err;
@@ -517,6 +518,9 @@ ni_ins_new_attr(struct ntfs_inode *ni, struct mft_inode *mi,
517518
*/
518519
static int ni_repack(struct ntfs_inode *ni)
519520
{
521+
#if 1
522+
return 0;
523+
#else
520524
int err = 0;
521525
struct ntfs_sb_info *sbi = ni->mi.sbi;
522526
struct mft_inode *mi, *mi_p = NULL;
@@ -639,6 +643,7 @@ static int ni_repack(struct ntfs_inode *ni)
639643

640644
run_close(&run);
641645
return err;
646+
#endif
642647
}
643648

644649
/*
@@ -813,10 +818,8 @@ int ni_create_attr_list(struct ntfs_inode *ni)
813818
* Looks like one record_size is always enough.
814819
*/
815820
le = kmalloc(al_aligned(rs), GFP_NOFS);
816-
if (!le) {
817-
err = -ENOMEM;
818-
goto out;
819-
}
821+
if (!le)
822+
return -ENOMEM;
820823

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

866869
if (to_free > free_b) {
867870
err = -EINVAL;
868-
goto out1;
871+
goto out;
869872
}
870873
}
871874

872875
/* Allocate child MFT. */
873876
err = ntfs_look_free_mft(sbi, &rno, is_mft, ni, &mi);
874877
if (err)
875-
goto out1;
878+
goto out;
876879

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

883887
attr = mi_insert_attr(mi, b->type, Add2Ptr(b, name_off),
884888
b->name_len, asize, name_off);
885-
WARN_ON(!attr);
889+
if (!attr)
890+
goto out;
886891

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

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

897903
if (to_free <= asize)
898904
break;
899905
to_free -= asize;
900-
WARN_ON(!nb);
906+
if (!nb)
907+
goto out;
901908
}
902909

903910
attr = mi_insert_attr(&ni->mi, ATTR_LIST, NULL, 0,
904911
lsize + SIZEOF_RESIDENT, SIZEOF_RESIDENT);
905-
WARN_ON(!attr);
912+
if (!attr)
913+
goto out;
906914

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

918926
mark_inode_dirty(&ni->vfs_inode);
919-
goto out;
927+
return 0;
920928

921-
out1:
929+
out:
922930
kfree(ni->attr_list.le);
923931
ni->attr_list.le = NULL;
924932
ni->attr_list.size = 0;
925-
926-
out:
927933
return err;
928934
}
929935

@@ -1638,14 +1644,13 @@ int ni_delete_all(struct ntfs_inode *ni)
16381644
* Return: File name attribute by its value.
16391645
*/
16401646
struct ATTR_FILE_NAME *ni_fname_name(struct ntfs_inode *ni,
1641-
const struct cpu_str *uni,
1647+
const struct le_str *uni,
16421648
const struct MFT_REF *home_dir,
16431649
struct mft_inode **mi,
16441650
struct ATTR_LIST_ENTRY **le)
16451651
{
16461652
struct ATTRIB *attr = NULL;
16471653
struct ATTR_FILE_NAME *fname;
1648-
struct le_str *fns;
16491654

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

1672-
fns = (struct le_str *)&fname->name_len;
1673-
if (ntfs_cmp_names_cpu(uni, fns, NULL, false))
1677+
if (ntfs_cmp_names(uni->name, uni->len, fname->name, uni->len, NULL,
1678+
false))
16741679
goto next;
1675-
16761680
return fname;
16771681
}
16781682

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

17581762
/* Resize nonresident empty attribute in-place only. */
17591763
new_asize = (new_aflags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) ?
1760-
(SIZEOF_NONRESIDENT_EX + 8) :
1761-
(SIZEOF_NONRESIDENT + 8);
1764+
(SIZEOF_NONRESIDENT_EX + 8) :
1765+
(SIZEOF_NONRESIDENT + 8);
17621766

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

2913-
fname = ni_fname_name(ni, (struct cpu_str *)&de_name->name_len,
2917+
fname = ni_fname_name(ni, (struct le_str *)&de_name->name_len,
29142918
&de_name->home, &mi, &le);
29152919
if (!fname)
29162920
return -ENOENT;
@@ -3160,8 +3164,8 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup,
31603164
__le64 valid_le;
31613165

31623166
dup->alloc_size = is_attr_ext(attr) ?
3163-
attr->nres.total_size :
3164-
attr->nres.alloc_size;
3167+
attr->nres.total_size :
3168+
attr->nres.alloc_size;
31653169
dup->data_size = attr->nres.data_size;
31663170

31673171
if (new_valid > data_size)

0 commit comments

Comments
 (0)