Skip to content

Commit af77c4f

Browse files
jdmfrakpm00
authored andcommitted
ocfs2: strict bound check before memcmp in ocfs2_xattr_find_entry()
xattr in ocfs2 maybe 'non-indexed', which saved with additional space requested. It's better to check if the memory is out of bound before memcmp, although this possibility mainly comes from crafted poisonous images. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ferry Meng <[email protected]> Signed-off-by: Joseph Qi <[email protected]> Reported-by: lei lu <[email protected]> Reviewed-by: Joseph Qi <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Gang He <[email protected]> Cc: Joel Becker <[email protected]> Cc: Jun Piao <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Mark Fasheh <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 9e3041f commit af77c4f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

fs/ocfs2/xattr.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ static int ocfs2_xattr_find_entry(struct inode *inode, int name_index,
10681068
{
10691069
struct ocfs2_xattr_entry *entry;
10701070
size_t name_len;
1071-
int i, cmp = 1;
1071+
int i, name_offset, cmp = 1;
10721072

10731073
if (name == NULL)
10741074
return -EINVAL;
@@ -1083,10 +1083,15 @@ static int ocfs2_xattr_find_entry(struct inode *inode, int name_index,
10831083
cmp = name_index - ocfs2_xattr_get_type(entry);
10841084
if (!cmp)
10851085
cmp = name_len - entry->xe_name_len;
1086-
if (!cmp)
1087-
cmp = memcmp(name, (xs->base +
1088-
le16_to_cpu(entry->xe_name_offset)),
1089-
name_len);
1086+
if (!cmp) {
1087+
name_offset = le16_to_cpu(entry->xe_name_offset);
1088+
if ((xs->base + name_offset + name_len) > xs->end) {
1089+
ocfs2_error(inode->i_sb,
1090+
"corrupted xattr entries");
1091+
return -EFSCORRUPTED;
1092+
}
1093+
cmp = memcmp(name, (xs->base + name_offset), name_len);
1094+
}
10901095
if (cmp == 0)
10911096
break;
10921097
entry += 1;

0 commit comments

Comments
 (0)