提交 afea1700 编写于 作者: B Brian Foster 提交者: Yongqiang Liu

xfs: fix use after free in buf log item unlock assert

mainline inclusion
from mainline-v5.1-rc5
commit 4d09807f
category: bugfix
bugzilla: 186464, https://gitee.com/openeuler/kernel/issues/I4YYIZ

--------------------------------

The xfs_buf_log_item ->iop_unlock() callback asserts that the buffer
is unlocked when either non-stale or aborted. This assert occurs
after the bli refcount has been dropped and the log item potentially
freed. The aborted check is thus a potential use after free. This
problem has been reproduced with KASAN enabled via generic/475.

Fix up xfs_buf_item_unlock() to query aborted state before the bli
reference is dropped to prevent a potential use after free.
Signed-off-by: NBrian Foster <bfoster@redhat.com>
Reviewed-by: NDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: NDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: NGuo Xuenan <guoxuenan@huawei.com>
Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 1b70444c
...@@ -605,6 +605,8 @@ xfs_buf_item_unlock( ...@@ -605,6 +605,8 @@ xfs_buf_item_unlock(
#if defined(DEBUG) || defined(XFS_WARN) #if defined(DEBUG) || defined(XFS_WARN)
bool ordered = bip->bli_flags & XFS_BLI_ORDERED; bool ordered = bip->bli_flags & XFS_BLI_ORDERED;
bool dirty = bip->bli_flags & XFS_BLI_DIRTY; bool dirty = bip->bli_flags & XFS_BLI_DIRTY;
bool aborted = test_bit(XFS_LI_ABORTED,
&lip->li_flags);
#endif #endif
trace_xfs_buf_item_unlock(bip); trace_xfs_buf_item_unlock(bip);
...@@ -633,7 +635,7 @@ xfs_buf_item_unlock( ...@@ -633,7 +635,7 @@ xfs_buf_item_unlock(
released = xfs_buf_item_put(bip); released = xfs_buf_item_put(bip);
if (hold || (stale && !released)) if (hold || (stale && !released))
return; return;
ASSERT(!stale || test_bit(XFS_LI_ABORTED, &lip->li_flags)); ASSERT(!stale || aborted);
xfs_buf_relse(bp); xfs_buf_relse(bp);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册