From: Pan Bian Date: Sun, 25 Nov 2018 00:58:02 +0000 (+0800) Subject: ext2: fix potential use after free X-Git-Tag: v3.18.129~46 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4dde2f5f7bcd80920193cb624e977d6cb30a52b8;p=profile%2Fwearable%2Fplatform%2Fkernel%2Flinux-3.18-exynos7270.git ext2: fix potential use after free commit ecebf55d27a11538ea84aee0be643dd953f830d5 upstream. 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: stable@vger.kernel.org Signed-off-by: Pan Bian Signed-off-by: Jan Kara Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c index 9142614..d5d6ec1 100644 --- a/fs/ext2/xattr.c +++ b/fs/ext2/xattr.c @@ -606,9 +606,9 @@ skip_replace: } cleanup: - brelse(bh); if (!(bh && header == HDR(bh))) kfree(header); + brelse(bh); up_write(&EXT2_I(inode)->xattr_sem); return error;