linux-stable/fs/gfs2
Andreas Gruenbacher c4b51dbccc gfs2: Fix occasional glock use-after-free
[ Upstream commit 9287c6452d ]

This patch has to do with the life cycle of glocks and buffers.  When
gfs2 metadata or journaled data is queued to be written, a gfs2_bufdata
object is assigned to track the buffer, and that is queued to various
lists, including the glock's gl_ail_list to indicate it's on the active
items list.  Once the page associated with the buffer has been written,
it is removed from the ail list, but its life isn't over until a revoke
has been successfully written.

So after the block is written, its bufdata object is moved from the
glock's gl_ail_list to a file-system-wide list of pending revokes,
sd_log_le_revoke.  At that point the glock still needs to track how many
revokes it contributed to that list (in gl_revokes) so that things like
glock go_sync can ensure all the metadata has been not only written, but
also revoked before the glock is granted to a different node.  This is
to guarantee journal replay doesn't replay the block once the glock has
been granted to another node.

Ross Lagerwall recently discovered a race in which an inode could be
evicted, and its glock freed after its ail list had been synced, but
while it still had unwritten revokes on the sd_log_le_revoke list.  The
evict decremented the glock reference count to zero, which allowed the
glock to be freed.  After the revoke was written, function
revoke_lo_after_commit tried to adjust the glock's gl_revokes counter
and clear its GLF_LFLUSH flag, at which time it referenced the freed
glock.

This patch fixes the problem by incrementing the glock reference count
in gfs2_add_revoke when the glock's first bufdata object is moved from
the glock to the global revokes list. Later, when the glock's last such
bufdata object is freed, the reference count is decremented. This
guarantees that whichever process finishes last (the revoke writing or
the evict) will properly free the glock, and neither will reference the
glock after it has been freed.

Reported-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-05-31 06:46:07 -07:00
..
acl.c gfs2: using posix_acl_xattr_size instead of posix_acl_to_xattr 2018-07-24 20:02:11 +02:00
acl.h gfs2: Switch to generic xattr handlers 2016-05-12 22:28:05 -04:00
aops.c gfs2: use iomap_readpage for blocksize == PAGE_SIZE 2018-07-25 00:08:49 +02:00
aops.h gfs2: iomap buffered write support 2018-07-02 16:27:17 +01:00
bmap.c gfs2: Fix iomap buffer head reference counting bug 2018-12-01 09:37:34 +01:00
bmap.h gfs2: Iomap cleanups and improvements 2018-06-04 07:56:51 -05:00
dentry.c gfs2: Lock holder cleanup 2016-06-27 09:47:09 -05:00
dir.c gfs2: remove redundant variable 'moved' 2018-07-25 00:08:59 +02:00
dir.h
export.c gfs2: Get rid of gfs2_ilookup 2016-06-27 09:47:08 -05:00
file.c gfs2: Use iomap for stuffed direct I/O reads 2018-07-25 00:08:40 +02:00
gfs2.h
glock.c gfs2: Fix occasional glock use-after-free 2019-05-31 06:46:07 -07:00
glock.h gfs2: gfs2_evict_inode: Put glocks asynchronously 2017-08-10 10:45:21 -05:00
glops.c vfs: change inode times to use struct timespec64 2018-06-05 16:57:31 -07:00
glops.h
incore.h gfs2: Fix gfs2_testbit to use clone bitmaps 2018-08-07 10:07:00 -05:00
inode.c gfs2: Get rid of potential double-freeing in gfs2_create_inode 2019-01-13 09:51:07 +01:00
inode.h gfs2: Implement SEEK_HOLE / SEEK_DATA via iomap 2017-10-31 14:26:35 +01:00
Kconfig gfs2: Fix the crc32c dependency 2018-02-01 11:25:31 -07:00
lock_dlm.c gfs2: Fix sign extension bug in gfs2_update_stats 2019-05-31 06:46:02 -07:00
log.c gfs2: Fix occasional glock use-after-free 2019-05-31 06:46:07 -07:00
log.h gfs2: Remove ordered write mode handling from gfs2_trans_add_data 2018-06-04 07:50:16 -05:00
lops.c gfs2: Fix occasional glock use-after-free 2019-05-31 06:46:07 -07:00
lops.h GFS2: Introduce new gfs2_log_header_v2 2018-01-23 07:38:53 -07:00
main.c gfs2: Fix wrong error handling in init_gfs2_fs() 2017-11-27 10:47:22 -06:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
meta_io.c gfs2: Don't withdraw under a spin lock 2018-06-21 07:39:44 -05:00
meta_io.h GFS2: Refactor gfs2_remove_from_journal 2016-05-06 11:27:27 -05:00
ops_fstype.c gfs2: Don't leave s_fs_info pointing to freed memory in init_sbd 2018-12-01 09:37:27 +01:00
quota.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
quota.h gfs2: Fix fallocate chunk size 2018-03-08 09:26:20 -07:00
recovery.c GFS2: Fix recovery issues for spectators 2018-07-25 00:06:24 +02:00
recovery.h GFS2: Fix gfs2_replay_incr_blk for multiple journal sizes 2016-07-21 13:02:44 -05:00
rgrp.c gfs2: Revert "Fix loop in gfs2_rbm_find" 2019-02-06 17:30:13 +01:00
rgrp.h GFS2: Non-recursive delete 2017-04-19 08:25:43 -04:00
super.c Merge branch 'iomap-write' into linux-gfs2/for-next 2018-07-24 20:02:40 +02:00
super.h
sys.c GFS2: Fix recovery issues for spectators 2018-07-25 00:06:24 +02:00
sys.h
trace_gfs2.h gfs2: eliminate rs_inum and reduce the size of gfs2 inodes 2018-06-21 07:39:31 -05:00
trans.c gfs2: Remove ordered write mode handling from gfs2_trans_add_data 2018-06-04 07:50:16 -05:00
trans.h gfs2: Eliminate redundant ip->i_rgd 2018-07-05 17:47:16 +02:00
util.c gfs2: Don't withdraw under a spin lock 2018-06-21 07:39:44 -05:00
util.h gfs2: Don't withdraw under a spin lock 2018-06-21 07:39:44 -05:00
xattr.c gfs2: Get rid of gfs2_ea_strlen 2018-08-03 13:20:02 +01:00
xattr.h gfs2: Remove gfs2_xattr_acl_chmod 2015-12-06 21:25:17 -05:00