]> www.infradead.org Git - users/jedix/linux-maple.git/commit
mseal: fix is_madv_discard()
authorPedro Falcato <pedro.falcato@gmail.com>
Wed, 7 Aug 2024 17:33:35 +0000 (18:33 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 16 Aug 2024 05:16:13 +0000 (22:16 -0700)
commite46bc2e7eb90a370bc27fa2fd98cb8251e7da1ec
tree52b1322b4b246211b918524ac7ed61c6e6f8168c
parent7c626ce4bae1ac14f60076d00eafe71af30450ba
mseal: fix is_madv_discard()

is_madv_discard did its check wrong. MADV_ flags are not bitwise,
they're normal sequential numbers. So, for instance:
behavior & (/* ... */ | MADV_REMOVE)

tagged both MADV_REMOVE and MADV_RANDOM (bit 0 set) as discard
operations.

As a result the kernel could erroneously block certain madvises (e.g
MADV_RANDOM or MADV_HUGEPAGE) on sealed VMAs due to them sharing bits
with blocked MADV operations (e.g REMOVE or WIPEONFORK).

This is obviously incorrect, so use a switch statement instead.

Link: https://lkml.kernel.org/r/20240807173336.2523757-1-pedro.falcato@gmail.com
Link: https://lkml.kernel.org/r/20240807173336.2523757-2-pedro.falcato@gmail.com
Fixes: 8be7258aad44 ("mseal: add mseal syscall")
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
Tested-by: Jeff Xu <jeffxu@chromium.org>
Reviewed-by: Jeff Xu <jeffxu@chromium.org>
Cc: Kees Cook <kees@kernel.org>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mseal.c