Skip to content

Commit 68f2359

Browse files
hclee1Naim
authored andcommitted
ntfs: remove redundant out-of-bound checks
Remove redundant out-of-bounds validations. Since ntfs_attr_find and ntfs_external_attr_find now validate the attribute value offsets and lengths against the bounds of the MFT record block, performing subsequent bounds checking in caller functions like ntfs_attr_lookup is no longer necessary. Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 51cd9a1 commit 68f2359

3 files changed

Lines changed: 0 additions & 42 deletions

File tree

fs/ntfs/inode.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,6 @@ static int ntfs_read_locked_inode(struct inode *vi)
757757
}
758758
a = ctx->attr;
759759
/* Get the standard information attribute value. */
760-
if ((u8 *)a + le16_to_cpu(a->data.resident.value_offset)
761-
+ le32_to_cpu(a->data.resident.value_length) >
762-
(u8 *)ctx->mrec + vol->mft_record_size) {
763-
ntfs_error(vi->i_sb, "Corrupt standard information attribute in inode.");
764-
goto unm_err_out;
765-
}
766760
si = (struct standard_information *)((u8 *)a +
767761
le16_to_cpu(a->data.resident.value_offset));
768762

@@ -849,13 +843,6 @@ static int ntfs_read_locked_inode(struct inode *vi)
849843
goto unm_err_out;
850844
}
851845
} else /* if (!a->non_resident) */ {
852-
if ((u8 *)a + le16_to_cpu(a->data.resident.value_offset)
853-
+ le32_to_cpu(
854-
a->data.resident.value_length) >
855-
(u8 *)ctx->mrec + vol->mft_record_size) {
856-
ntfs_error(vi->i_sb, "Corrupt attribute list in inode.");
857-
goto unm_err_out;
858-
}
859846
/* Now copy the attribute list. */
860847
memcpy(ni->attr_list, (u8 *)a + le16_to_cpu(
861848
a->data.resident.value_offset),
@@ -954,10 +941,6 @@ static int ntfs_read_locked_inode(struct inode *vi)
954941
ir = (struct index_root *)((u8 *)a +
955942
le16_to_cpu(a->data.resident.value_offset));
956943
ir_end = (u8 *)ir + le32_to_cpu(a->data.resident.value_length);
957-
if (ir_end > (u8 *)ctx->mrec + vol->mft_record_size) {
958-
ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is corrupt.");
959-
goto unm_err_out;
960-
}
961944
index_end = (u8 *)&ir->index +
962945
le32_to_cpu(ir->index.index_length);
963946
if (index_end > ir_end) {
@@ -1552,10 +1535,6 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi)
15521535

15531536
ir = (struct index_root *)((u8 *)a + le16_to_cpu(a->data.resident.value_offset));
15541537
ir_end = (u8 *)ir + le32_to_cpu(a->data.resident.value_length);
1555-
if (ir_end > (u8 *)ctx->mrec + vol->mft_record_size) {
1556-
ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is corrupt.");
1557-
goto unm_err_out;
1558-
}
15591538
index_end = (u8 *)&ir->index + le32_to_cpu(ir->index.index_length);
15601539
if (index_end > ir_end) {
15611540
ntfs_error(vi->i_sb, "Index is corrupt.");
@@ -1999,13 +1978,6 @@ int ntfs_read_inode_mount(struct inode *vi)
19991978
goto put_err_out;
20001979
}
20011980
} else /* if (!ctx.attr->non_resident) */ {
2002-
if ((u8 *)a + le16_to_cpu(
2003-
a->data.resident.value_offset) +
2004-
le32_to_cpu(a->data.resident.value_length) >
2005-
(u8 *)ctx->mrec + vol->mft_record_size) {
2006-
ntfs_error(sb, "Corrupt attribute list attribute.");
2007-
goto put_err_out;
2008-
}
20091981
/* Now copy the attribute list. */
20101982
memcpy(ni->attr_list, (u8 *)a + le16_to_cpu(
20111983
a->data.resident.value_offset),

fs/ntfs/namei.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent,
274274
}
275275
do {
276276
struct attr_record *a;
277-
u32 val_len;
278277

279278
err = ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, 0, 0,
280279
NULL, 0, ctx);
@@ -289,15 +288,8 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent,
289288
a = ctx->attr;
290289
if (a->non_resident || a->flags)
291290
goto eio_err_out;
292-
val_len = le32_to_cpu(a->data.resident.value_length);
293-
if (le16_to_cpu(a->data.resident.value_offset) +
294-
val_len > le32_to_cpu(a->length))
295-
goto eio_err_out;
296291
fn = (struct file_name_attr *)((u8 *)ctx->attr + le16_to_cpu(
297292
ctx->attr->data.resident.value_offset));
298-
if ((u32)(fn->file_name_length * sizeof(__le16) +
299-
sizeof(struct file_name_attr)) > val_len)
300-
goto eio_err_out;
301293
} while (fn->file_name_type != FILE_NAME_WIN32);
302294

303295
/* Convert the found WIN32 name to current NLS code page. */

fs/ntfs/super.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,19 +1512,13 @@ static bool load_system_files(struct ntfs_volume *vol)
15121512

15131513
if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0,
15141514
ctx) || ctx->attr->non_resident || ctx->attr->flags) {
1515-
err_put_vol:
15161515
ntfs_attr_put_search_ctx(ctx);
15171516
get_ctx_vol_failed:
15181517
unmap_mft_record(NTFS_I(vol->vol_ino));
15191518
goto iput_volume_failed;
15201519
}
15211520
vi = (struct volume_information *)((char *)ctx->attr +
15221521
le16_to_cpu(ctx->attr->data.resident.value_offset));
1523-
/* Some bounds checks. */
1524-
if ((u8 *)vi < (u8 *)ctx->attr || (u8 *)vi +
1525-
le32_to_cpu(ctx->attr->data.resident.value_length) >
1526-
(u8 *)ctx->attr + le32_to_cpu(ctx->attr->length))
1527-
goto err_put_vol;
15281522
/* Copy the volume flags and version to the struct ntfs_volume structure. */
15291523
vol->vol_flags = vi->flags;
15301524
vol->major_ver = vi->major_ver;

0 commit comments

Comments
 (0)