]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
xfs: correct null checks and error processing in xfs_initialize_perag
authorBill O'Donnell <billodo@redhat.com>
Tue, 7 Feb 2017 20:59:33 +0000 (12:59 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 8 Apr 2017 07:35:04 +0000 (09:35 +0200)
commite8eb2c060902c723cab90e649f03ad7210c0a140
treed0e661f9f2b5a9edcbc681624c4b4f394ebfaf31
parent304ec448ee8bcd9256c244a310a2e88fc824302b
xfs: correct null checks and error processing in xfs_initialize_perag

commit b20fe4730ea5c037c16631fb0df659c7b6d4b3b1 upstream.

If pag cannot be allocated, the current error exit path will trip
a null pointer deference error when calling xfs_buf_hash_destroy
with a null pag.  Fix this by adding a new error exit labels and
jumping to those accordingly, avoiding the hash destroy and
unnecessary kmem_free on pag.

Up to three things need to be properly unwound:

1) pag memory allocation
2) xfs_buf_hash_init
3) radix_tree_insert

For any given iteration through the loop, any of the above which
succeed must be unwound for /this/ pag, and then all prior
initialized pags must be unwound.

Addresses-Coverity-Id: 1397628 ("Dereference after null check")

Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Bill O'Donnell <billodo@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/xfs/xfs_mount.c