Commit 071d0e62 authored by Linux Patches Robot's avatar Linux Patches Robot Committed by Treehugger Robot
Browse files

UPSTREAM: 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: 8be7258a ("mseal: add mseal syscall")
Signed-off-by: default avatarPedro Falcato <pedro.falcato@gmail.com>
Tested-by: default avatarJeff Xu <jeffxu@chromium.org>
Reviewed-by: default avatarJeff 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: default avatarAndrew Morton <akpm@linux-foundation.org>
(cherry picked from commit e46bc2e7)

Signed-off-by: default avatarJeff Xu <jeffxu@google.com>
Change-Id: Ia74688deb004790c81aabd6a17d4b0af139bbd41
parent 1e298487
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment