ocfs2: Fix the update of name_offset when removing xattrs

When replacing a xattr's value, in some case we wipe its name/value
first and then re-add it. The wipe is done by
ocfs2_xa_block_wipe_namevalue() when the xattr is in the inode or
block. We currently adjust name_offset for all the entries which have
(offset < name_offset). This does not adjust the entrie we're replacing.
Since we are replacing the entry, we don't adjust the total entry count.
When we calculate a new namevalue location, we trust the entries
now-wrong offset in ocfs2_xa_get_free_start(). The solution is to
also adjust the name_offset for the replaced entry, allowing
ocfs2_xa_get_free_start() to calculate the new namevalue location
correctly.

The following script can trigger a kernel panic easily.

echo 'y'|mkfs.ocfs2 --fs-features=local,xattr -b 4K $DEVICE
mount -t ocfs2 $DEVICE $MNT_DIR
FILE=$MNT_DIR/$RANDOM
for((i=0;i<76;i++))
do
string_76="a$string_76"
done
string_78="aa$string_76"
string_82="aaaa$string_78"

touch $FILE
setfattr -n 'user.test1234567890' -v $string_76 $FILE
setfattr -n 'user.test1234567890' -v $string_78 $FILE
setfattr -n 'user.test1234567890' -v $string_82 $FILE

Signed-off-by: Tao Ma <tao.ma@oracle.com>
Signed-off-by: Joel Becker <joel.becker@oracle.com>

authored by Tao Ma and committed by Joel Becker dfe4d3d6 b22b63eb

+1 -1
+1 -1
fs/ocfs2/xattr.c
··· 1622 1622 /* Now tell xh->xh_entries about it */ 1623 1623 for (i = 0; i < count; i++) { 1624 1624 offset = le16_to_cpu(xh->xh_entries[i].xe_name_offset); 1625 - if (offset < namevalue_offset) 1625 + if (offset <= namevalue_offset) 1626 1626 le16_add_cpu(&xh->xh_entries[i].xe_name_offset, 1627 1627 namevalue_size); 1628 1628 }