linux-stable/fs/ocfs2
Jan Kara f7b30ae8ed ocfs2: fix data corruption on truncate
commit 839b63860e upstream.

Patch series "ocfs2: Truncate data corruption fix".

As further testing has shown, commit 5314454ea3 ("ocfs2: fix data
corruption after conversion from inline format") didn't fix all the data
corruption issues the customer started observing after 6dbf7bb555
("fs: Don't invalidate page buffers in block_write_full_page()") This
time I have tracked them down to two bugs in ocfs2 truncation code.

One bug (truncating page cache before clearing tail cluster and setting
i_size) could cause data corruption even before 6dbf7bb555, but before
that commit it needed a race with page fault, after 6dbf7bb555 it
started to be pretty deterministic.

Another bug (zeroing pages beyond old i_size) used to be harmless
inefficiency before commit 6dbf7bb555.  But after commit 6dbf7bb555
in combination with the first bug it resulted in deterministic data
corruption.

Although fixing only the first problem is needed to stop data
corruption, I've fixed both issues to make the code more robust.

This patch (of 2):

ocfs2_truncate_file() did unmap invalidate page cache pages before
zeroing partial tail cluster and setting i_size.  Thus some pages could
be left (and likely have left if the cluster zeroing happened) in the
page cache beyond i_size after truncate finished letting user possibly
see stale data once the file was extended again.  Also the tail cluster
zeroing was not guaranteed to finish before truncate finished causing
possible stale data exposure.  The problem started to be particularly
easy to hit after commit 6dbf7bb555 "fs: Don't invalidate page buffers
in block_write_full_page()" stopped invalidation of pages beyond i_size
from page writeback path.

Fix these problems by unmapping and invalidating pages in the page cache
after the i_size is reduced and tail cluster is zeroed out.

Link: https://lkml.kernel.org/r/20211025150008.29002-1-jack@suse.cz
Link: https://lkml.kernel.org/r/20211025151332.11301-1-jack@suse.cz
Fixes: ccd979bdbc ("[PATCH] OCFS2: The Second Oracle Cluster Filesystem")
Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Gang He <ghe@suse.com>
Cc: Jun Piao <piaojun@huawei.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-26 11:40:20 +01:00
..
cluster ocfs2: fix a use after free on error 2021-03-03 18:22:49 +01:00
dlm fs/ocfs2/dlm/dlmdebug.c: fix a sleep-in-atomic-context bug in dlm_print_one_mle() 2019-12-01 09:13:48 +01:00
dlmfs ocfs2: improve ocfs2 Makefile 2019-02-12 19:46:09 +01:00
acl.c ocfs2: fix passing zero to 'PTR_ERR' warning 2020-01-04 13:59:56 +01:00
acl.h ocfs2: make ocfs2_set_acl() static 2017-09-06 17:27:24 -07:00
alloc.c ocfs2: fix data corruption after conversion from inline format 2021-10-27 09:51:40 +02:00
alloc.h ocfs2: clean up some dead code 2017-09-06 17:27:24 -07:00
aops.c ocfs2: fix deadlock between setattr and dio_end_io_write 2021-04-16 11:57:48 +02:00
aops.h
blockcheck.c
blockcheck.h
buffer_head_io.c ocfs2: don't put and assigning null to bh allocated outside 2019-12-01 09:14:00 +01:00
buffer_head_io.h
dcache.c fs/ocfs2: fix race in ocfs2_dentry_attach_lock() 2019-06-19 08:20:54 +02:00
dcache.h
dir.c ocfs2: fix a misuse a of brelse after failing ocfs2_check_dir_entry 2018-11-21 09:24:09 +01:00
dir.h
dlmglue.c ocfs2: drop acl cache for directories too 2021-10-06 15:05:04 +02:00
dlmglue.h
export.c ocfs2: fix ocfs2 read inode data panic in ocfs2_iget 2019-05-21 18:50:17 +02:00
export.h
extent_map.c
extent_map.h
file.c ocfs2: fix data corruption on truncate 2021-11-26 11:40:20 +01:00
file.h statx: Add a system call to make enhanced file info available 2017-03-02 20:51:15 -05:00
filecheck.c ocfs2: fix snprintf() checking 2021-07-20 16:17:36 +02:00
filecheck.h
heartbeat.c
heartbeat.h
inode.c ocfs2: fix a static checker warning 2017-07-06 16:24:30 -07:00
inode.h
ioctl.c fs: ocfs2: fix a possible null-pointer dereference in ocfs2_info_scan_inode_alloc() 2019-11-06 12:43:15 +01:00
ioctl.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
journal.c ocfs2: call journal flush to mark journal as empty after journal recovery when mount 2020-01-17 19:45:55 +01:00
journal.h ocfs2: fix a NULL pointer dereference when call ocfs2_update_inode_fsync_trans() 2020-02-28 16:36:08 +01:00
Kconfig
localalloc.c ocfs2: fix panic due to ocfs2_wq is null 2019-10-29 09:17:00 +01:00
localalloc.h
locks.c
locks.h
Makefile ocfs2: improve ocfs2 Makefile 2019-02-12 19:46:09 +01:00
mmap.c
mmap.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
move_extents.c ocfs2: fix clusters leak in ocfs2_defrag_extent() 2019-12-01 09:14:00 +01:00
move_extents.h
namei.c
namei.h
ocfs1_fs_compat.h
ocfs2.h ocfs2: change slot number type s16 to u16 2020-08-21 09:48:19 +02:00
ocfs2_fs.h ocfs2: fix value of OCFS2_INVALID_SLOT 2020-06-30 15:38:08 -04:00
ocfs2_ioctl.h
ocfs2_lockid.h
ocfs2_lockingver.h
ocfs2_trace.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
quota.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
quota_global.c quota: Check that quota is not dirty before release 2019-12-17 20:39:43 +01:00
quota_local.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
refcounttree.c ocfs2: fix inode bh swapping mixup in ocfs2_reflink_inodes_lock 2019-04-03 06:25:17 +02:00
refcounttree.h
reservations.c
reservations.h
resize.c
resize.h
slot_map.c
slot_map.h
stack_o2cb.c
stack_user.c
stackglue.c ocfs2: fix snprintf() checking 2021-07-20 16:17:36 +02:00
stackglue.h ocfs2: remove ocfs2_is_o2cb_active() 2019-12-01 09:14:20 +01:00
suballoc.c ocfs2: change slot number type s16 to u16 2020-08-21 09:48:19 +02:00
suballoc.h
super.c ocfs2: mount fails with buffer overflow in strlen 2021-10-27 09:51:40 +02:00
super.h
symlink.c
symlink.h
sysfile.c
sysfile.h
uptodate.c
uptodate.h
xattr.c Revert "fs: ocfs2: fix possible null-pointer dereferences in ocfs2_xa_prepare_entry()" 2019-12-01 09:13:14 +01:00
xattr.h