linux-brain/fs/ubifs
Richard Weinberger ed0d232df9 ubifs: Handle re-linking of inodes correctly while recovery
commit e58725d51f upstream.

UBIFS's recovery code strictly assumes that a deleted inode will never
come back, therefore it removes all data which belongs to that inode
as soon it faces an inode with link count 0 in the replay list.
Before O_TMPFILE this assumption was perfectly fine. With O_TMPFILE
it can lead to data loss upon a power-cut.

Consider a journal with entries like:
0: inode X (nlink = 0) /* O_TMPFILE was created */
1: data for inode X /* Someone writes to the temp file */
2: inode X (nlink = 0) /* inode was changed, xattr, chmod, … */
3: inode X (nlink = 1) /* inode was re-linked via linkat() */

Upon replay of entry #2 UBIFS will drop all data that belongs to inode X,
this will lead to an empty file after mounting.

As solution for this problem, scan the replay list for a re-link entry
before dropping data.

Fixes: 474b93704f ("ubifs: Implement O_TMPFILE")
Cc: stable@vger.kernel.org # 4.9-4.18
Cc: Russell Senior <russell@personaltelco.net>
Cc: Rafał Miłecki <zajec5@gmail.com>
Reported-by: Russell Senior <russell@personaltelco.net>
Reported-by: Rafał Miłecki <zajec5@gmail.com>
Tested-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Richard Weinberger <richard@nod.at>
[rmilecki: update ubifs_assert() calls to compile with 4.18 and older]
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
(cherry picked from commit e58725d51f)
Signed-off-by: Sasha Levin <sashal@kernel.org>
2018-12-29 13:39:11 +01:00
..
budget.c UBIFS: extend debug/message capabilities 2015-03-25 11:08:41 +02:00
commit.c UBIFS: extend debug/message capabilities 2015-03-25 11:08:41 +02:00
compress.c UBIFS: extend debug/message capabilities 2015-03-25 11:08:41 +02:00
crypto.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
debug.c ubifs: Fix cut and paste error on sb type comparisons 2017-05-08 20:48:41 +02:00
debug.h UBIFS: print less 2012-08-31 17:32:58 +03:00
dir.c ubifs: Fix directory size calculation for symlinks 2018-12-29 13:39:07 +01:00
file.c mm/migrate: new migrate mode MIGRATE_SYNC_NO_COPY 2017-09-08 18:26:46 -07:00
find.c UBIFS: fix mounting problems after power cuts 2012-10-26 16:26:44 +03:00
gc.c ubifs: Remove some dead code 2016-12-12 23:06:28 +01:00
io.c ubifs: Use dirty_writeback_interval value for wbuf timer 2016-12-12 23:06:24 +01:00
ioctl.c This pull request contains updates for both UBI and UBIFS: 2017-05-13 10:23:12 -07:00
journal.c ubifs: Fix synced_i_size calculation for xattr inodes 2018-09-09 19:56:00 +02:00
Kconfig ubifs: Add CONFIG_UBIFS_FS_SECURITY to disable/enable security labels 2017-05-08 20:48:23 +02:00
key.h ubifs: Add assert to dent_key_init() 2017-07-14 22:49:06 +02:00
log.c UBIFS: extend debug/message capabilities 2015-03-25 11:08:41 +02:00
lprops.c ubifs: Fix memory leak in lprobs self-check 2018-09-09 19:56:00 +02:00
lpt_commit.c UBIFS: improve function-level documentation 2016-10-02 22:55:02 +02:00
lpt.c UBIFS: use kmemdup rather than duplicating its implementation 2015-10-03 20:03:14 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
master.c UBIFS: extend debug/message capabilities 2015-03-25 11:08:41 +02:00
misc.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
misc.h fs: ubifs: replace CURRENT_TIME_SEC with current_time 2017-05-08 17:15:15 -07:00
orphan.c UBIFS: extend debug/message capabilities 2015-03-25 11:08:41 +02:00
recovery.c ubifs: Remove unnecessary assignment 2017-05-08 20:48:47 +02:00
replay.c ubifs: Handle re-linking of inodes correctly while recovery 2018-12-29 13:39:11 +01:00
sb.c fs: ubifs: replace CURRENT_TIME_SEC with current_time 2017-05-08 17:15:15 -07:00
scan.c UBIFS: extend debug/message capabilities 2015-03-25 11:08:41 +02:00
shrinker.c UBIFS: Remove incorrect assertion in shrink_tnc() 2014-06-02 11:28:24 +03:00
super.c ubifs: Check for name being NULL while mounting 2018-10-13 09:27:29 +02:00
tnc_commit.c ubifs: Fail commit if TNC is obviously inconsistent 2017-07-14 22:49:07 +02:00
tnc_misc.c UBIFS: extend debug/message capabilities 2015-03-25 11:08:41 +02:00
tnc.c ubifs: Fix uninitialized variable in search_dh_cookie() 2018-04-26 11:02:07 +02:00
ubifs-media.h ubifs: Raise write version to 5 2016-12-12 23:07:38 +01:00
ubifs.h ubifs: Massage assert in ubifs_xattr_set() wrt. init_xattrs 2017-07-14 22:50:54 +02:00
xattr.c Revert "ubifs: xattr: Don't operate on deleted inodes" 2018-09-29 03:06:04 -07:00