android_kernel_oneplus_msm8998/fs/gfs2
Bob Peterson d61e517e39 GFS2: don't set rgrp gl_object until it's inserted into rgrp tree
commit 36e4ad0316c017d5b271378ed9a1c9a4b77fab5f upstream.

Before this patch, function read_rindex_entry would set a rgrp
glock's gl_object pointer to itself before inserting the rgrp into
the rgrp rbtree. The problem is: if another process was also reading
the rgrp in, and had already inserted its newly created rgrp, then
the second call to read_rindex_entry would overwrite that value,
then return a bad return code to the caller. Later, other functions
would reference the now-freed rgrp memory by way of gl_object.
In some cases, that could result in gfs2_rgrp_brelse being called
twice for the same rgrp: once for the failed attempt and once for
the "real" rgrp release. Eventually the kernel would panic.
There are also a number of other things that could go wrong when
a kernel module is accessing freed storage. For example, this could
result in rgrp corruption because the fake rgrp would point to a
fake bitmap in memory too, causing gfs2_inplace_reserve to search
some random memory for free blocks, and find some, since we were
never setting rgd->rd_bits to NULL before freeing it.

This patch fixes the problem by not setting gl_object until we
have successfully inserted the rgrp into the rbtree. Also, it sets
rd_bits to NULL as it frees them, which will ensure any accidental
access to the wrong rgrp will result in a kernel panic rather than
file system corruption, which is preferred.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>
[bwh: Backported to 4.4: adjust context]
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-09-06 10:18:11 +02:00
..
acl.c
acl.h
aops.c
bmap.c gfs2: Special-case rindex for gfs2_grow 2018-09-26 08:35:05 +02:00
bmap.h
dentry.c
dir.c gfs2: avoid uninitialized variable warning 2017-04-30 05:49:28 +02:00
dir.h
export.c
file.c gfs2: Fix fallocate chunk size 2018-05-30 07:49:13 +02:00
gfs2.h
glock.c gfs2: Fix lru_count going negative 2019-06-11 12:23:53 +02:00
glock.h
glops.c
glops.h
incore.h gfs2: Fix glock rhashtable rcu bug 2017-07-15 11:57:46 +02:00
inode.c
inode.h
Kconfig
lock_dlm.c gfs2: Fix sign extension bug in gfs2_update_stats 2019-06-11 12:23:51 +02:00
log.c
log.h
lops.c
lops.h
main.c
Makefile
meta_io.c
meta_io.h
ops_fstype.c gfs2: Don't leave s_fs_info pointing to freed memory in init_sbd 2018-12-01 09:46:33 +01:00
quota.c
quota.h gfs2: Fix fallocate chunk size 2018-05-30 07:49:13 +02:00
recovery.c
recovery.h
rgrp.c GFS2: don't set rgrp gl_object until it's inserted into rgrp tree 2019-09-06 10:18:11 +02:00
rgrp.h
super.c
super.h
sys.c
sys.h
trace_gfs2.h
trans.c
trans.h
util.c
util.h
xattr.c
xattr.h