ext2: fix potential use after free

The function ext2_xattr_set calls brelse(bh) to drop the reference count
of bh. After that, bh may be freed. However, following brelse(bh),
it reads bh->b_data via macro HDR(bh). This may result in a
use-after-free bug. This patch moves brelse(bh) after reading field.

CC: [email protected]
Signed-off-by: Pan Bian <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
This commit is contained in:
Pan Bian 2018-11-25 08:58:02 +08:00 • committed by Jan Kara
commit ecebf55d27

View file

@ -612,9 +612,9 @@ skip_replace:
}
cleanup:
brelse(bh);
if (!(bh && header == HDR(bh)))
kfree(header);
brelse(bh);
up_write(&EXT2_I(inode)->xattr_sem);
return error;