Skip to content

Commit 94b07b6

Browse files
josephhztorvalds
authored andcommitted
Revert "fs: ocfs2: fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()"
This reverts commit 56e94ea. Commit 56e94ea ("fs: ocfs2: fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()") introduces a regression that fail to create directory with mount option user_xattr and acl. Actually the reported NULL pointer dereference case can be correctly handled by loc->xl_ops->xlo_add_entry(), so revert it. Link: http://lkml.kernel.org/r/[email protected] Fixes: 56e94ea ("fs: ocfs2: fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()") Signed-off-by: Joseph Qi <[email protected]> Reported-by: Thomas Voegtle <[email protected]> Acked-by: Changwei Ge <[email protected]> Cc: Jia-Ju Bai <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Gang He <[email protected]> Cc: Jun Piao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 81429eb commit 94b07b6

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

fs/ocfs2/xattr.c

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,18 @@ static int ocfs2_xa_check_space(struct ocfs2_xa_loc *loc,
14901490
return loc->xl_ops->xlo_check_space(loc, xi);
14911491
}
14921492

1493+
static void ocfs2_xa_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash)
1494+
{
1495+
loc->xl_ops->xlo_add_entry(loc, name_hash);
1496+
loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
1497+
/*
1498+
* We can't leave the new entry's xe_name_offset at zero or
1499+
* add_namevalue() will go nuts. We set it to the size of our
1500+
* storage so that it can never be less than any other entry.
1501+
*/
1502+
loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);
1503+
}
1504+
14931505
static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc,
14941506
struct ocfs2_xattr_info *xi)
14951507
{
@@ -2121,31 +2133,29 @@ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
21212133
if (rc)
21222134
goto out;
21232135

2124-
if (!loc->xl_entry) {
2125-
rc = -EINVAL;
2126-
goto out;
2127-
}
2128-
2129-
if (ocfs2_xa_can_reuse_entry(loc, xi)) {
2130-
orig_value_size = loc->xl_entry->xe_value_size;
2131-
rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
2132-
if (rc)
2133-
goto out;
2134-
goto alloc_value;
2135-
}
2136+
if (loc->xl_entry) {
2137+
if (ocfs2_xa_can_reuse_entry(loc, xi)) {
2138+
orig_value_size = loc->xl_entry->xe_value_size;
2139+
rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
2140+
if (rc)
2141+
goto out;
2142+
goto alloc_value;
2143+
}
21362144

2137-
if (!ocfs2_xattr_is_local(loc->xl_entry)) {
2138-
orig_clusters = ocfs2_xa_value_clusters(loc);
2139-
rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
2140-
if (rc) {
2141-
mlog_errno(rc);
2142-
ocfs2_xa_cleanup_value_truncate(loc,
2143-
"overwriting",
2144-
orig_clusters);
2145-
goto out;
2145+
if (!ocfs2_xattr_is_local(loc->xl_entry)) {
2146+
orig_clusters = ocfs2_xa_value_clusters(loc);
2147+
rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
2148+
if (rc) {
2149+
mlog_errno(rc);
2150+
ocfs2_xa_cleanup_value_truncate(loc,
2151+
"overwriting",
2152+
orig_clusters);
2153+
goto out;
2154+
}
21462155
}
2147-
}
2148-
ocfs2_xa_wipe_namevalue(loc);
2156+
ocfs2_xa_wipe_namevalue(loc);
2157+
} else
2158+
ocfs2_xa_add_entry(loc, name_hash);
21492159

21502160
/*
21512161
* If we get here, we have a blank entry. Fill it. We grow our

0 commit comments

Comments
 (0)