ubifs: do_rename: Fix wrong space budget when target inode's nlink > 1
authorZhihao Cheng <chengzhihao1@huawei.com>
Tue, 11 Oct 2022 03:47:31 +0000 (11:47 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 11 Mar 2023 12:57:24 +0000 (13:57 +0100)
commit2b6d85db0e074c6c6e30d2480ffbc28756afb1c4
tree2271cd84002a234a8f0484e2f38c12ec9c81afd4
parent8e30559876d8f61296135ce2c92d3fdb90128ddf
ubifs: do_rename: Fix wrong space budget when target inode's nlink > 1

[ Upstream commit 25fce616a61fc2f1821e4a9ce212d0e064707093 ]

If target inode is a special file (eg. block/char device) with nlink
count greater than 1, the inode with ui->data will be re-written on
disk. However, UBIFS losts target inode's data_len while doing space
budget. Bad space budget may let make_reservation() return with -ENOSPC,
which could turn ubifs to read-only mode in do_writepage() process.

Fetch a reproducer in [Link].

Link: https://bugzilla.kernel.org/show_bug.cgi?id=216494
Fixes: 1e51764a3c2ac0 ("UBIFS: add new flash file system")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ubifs/dir.c