UPSTREAM: ext4: fix potential race between s_flex_groups online resizing and access

During an online resize an array of s_flex_groups structures gets replaced
so it can get enlarged. If there is a concurrent access to the array and
this memory has been reused then this can lead to an invalid memory access.

The s_flex_group array has been converted into an array of pointers rather
than an array of structures. This is to ensure that the information
contained in the structures cannot get out of sync during a resize due to
an accessor updating the value in the old structure after it has been
copied but before the array pointer is updated. Since the structures them-
selves are no longer copied but only the pointers to them this case is
mitigated.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=206443
Link: https://lore.kernel.org/r/20200221053458.730016-4-tytso@mit.edu
Signed-off-by: Suraj Jitindar Singh <surajjs@amazon.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
(cherry picked from commit 7c990728b99ed6fbe9c75fc202fce1172d9916da)
Signed-off-by: Vaibhav Rustagi <vaibhavrustagi@google.com>

BUG=b:140189539
TEST=tryjob
RELEASE_NOTE=None

Change-Id: I16cc0e485b18bdf365da51d146c486fe428f17f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2090847
Commit-Queue: Vaibhav Rustagi <vaibhavrustagi@google.com>
Tested-by: Vaibhav Rustagi <vaibhavrustagi@google.com>
Auto-Submit: Vaibhav Rustagi <vaibhavrustagi@google.com>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Roy Yang <royyang@google.com>
Reviewed-by: Theodore Tso <tytso@google.com>
5 files changed