Skip to content

Commit cc082e5

Browse files
aalexandrovichgregkh
authored andcommitted
fs/ntfs3: Sequential field availability check in mi_enum_attr()
commit 090f612 upstream. The code is slightly reformatted to consistently check field availability without duplication. Fixes: 556bdf2 ("ntfs3: Add bounds checking to mi_enum_attr()") Signed-off-by: Konstantin Komarov <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 10c20d7 commit cc082e5

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

fs/ntfs3/record.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
237237
}
238238

239239
/* Can we use the first field (attr->type). */
240+
/* NOTE: this code also checks attr->size availability. */
240241
if (off + 8 > used) {
241242
static_assert(ALIGN(sizeof(enum ATTR_TYPE), 8) == 8);
242243
return NULL;
@@ -257,10 +258,6 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
257258
return NULL;
258259

259260
asize = le32_to_cpu(attr->size);
260-
if (asize < SIZEOF_RESIDENT) {
261-
/* Impossible 'cause we should not return such attribute. */
262-
return NULL;
263-
}
264261

265262
/* Check overflow and boundary. */
266263
if (off + asize < off || off + asize > used)
@@ -290,6 +287,10 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
290287
if (attr->non_res != 1)
291288
return NULL;
292289

290+
/* Can we use memory including attr->nres.valid_size? */
291+
if (asize < SIZEOF_NONRESIDENT)
292+
return NULL;
293+
293294
t16 = le16_to_cpu(attr->nres.run_off);
294295
if (t16 > asize)
295296
return NULL;
@@ -316,7 +317,8 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
316317

317318
if (!attr->nres.svcn && is_attr_ext(attr)) {
318319
/* First segment of sparse/compressed attribute */
319-
if (asize + 8 < SIZEOF_NONRESIDENT_EX)
320+
/* Can we use memory including attr->nres.total_size? */
321+
if (asize < SIZEOF_NONRESIDENT_EX)
320322
return NULL;
321323

322324
tot_size = le64_to_cpu(attr->nres.total_size);
@@ -326,9 +328,6 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
326328
if (tot_size > alloc_size)
327329
return NULL;
328330
} else {
329-
if (asize + 8 < SIZEOF_NONRESIDENT)
330-
return NULL;
331-
332331
if (attr->nres.c_unit)
333332
return NULL;
334333

0 commit comments

Comments
 (0)