Skip to content

Commit 7e36985

Browse files
jdmfrmehmetb0
authored andcommitted
ocfs2: strict bound check before memcmp in ocfs2_xattr_find_entry()
BugLink: https://bugs.launchpad.net/bugs/2086242 [ Upstream commit af77c4f ] 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]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Koichiro Den <[email protected]> Signed-off-by: Roxana Nicolescu <[email protected]>
1 parent e5e330f commit 7e36985

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
@@ -1072,7 +1072,7 @@ static int ocfs2_xattr_find_entry(struct inode *inode, int name_index,
10721072
{
10731073
struct ocfs2_xattr_entry *entry;
10741074
size_t name_len;
1075-
int i, cmp = 1;
1075+
int i, name_offset, cmp = 1;
10761076

10771077
if (name == NULL)
10781078
return -EINVAL;
@@ -1087,10 +1087,15 @@ static int ocfs2_xattr_find_entry(struct inode *inode, int name_index,
10871087
cmp = name_index - ocfs2_xattr_get_type(entry);
10881088
if (!cmp)
10891089
cmp = name_len - entry->xe_name_len;
1090-
if (!cmp)
1091-
cmp = memcmp(name, (xs->base +
1092-
le16_to_cpu(entry->xe_name_offset)),
1093-
name_len);
1090+
if (!cmp) {
1091+
name_offset = le16_to_cpu(entry->xe_name_offset);
1092+
if ((xs->base + name_offset + name_len) > xs->end) {
1093+
ocfs2_error(inode->i_sb,
1094+
"corrupted xattr entries");
1095+
return -EFSCORRUPTED;
1096+
}
1097+
cmp = memcmp(name, (xs->base + name_offset), name_len);
1098+
}
10941099
if (cmp == 0)
10951100
break;
10961101
entry += 1;

0 commit comments

Comments
 (0)