summaryrefslogtreecommitdiff
path: root/mm
diff options
context:
space:
mode:
authorPedro Falcato <pedro.falcato@gmail.com>2024-08-07 18:33:35 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-08-29 17:35:39 +0200
commit5fc922bef4efba7708635149cc9f8b2d864f9abe (patch)
tree864e48bceb64c6cf0cd143e83c11f8baca80fb9a /mm
parent6b980b0ab5c82fd255a0d56522f813d490e0767c (diff)
downloadlinux-5fc922bef4efba7708635149cc9f8b2d864f9abe.tar.gz
linux-5fc922bef4efba7708635149cc9f8b2d864f9abe.tar.bz2
linux-5fc922bef4efba7708635149cc9f8b2d864f9abe.zip
mseal: fix is_madv_discard()
commit e46bc2e7eb90a370bc27fa2fd98cb8251e7da1ec upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/mseal.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/mm/mseal.c b/mm/mseal.c
index bf783bba8ed0..15bba28acc00 100644
--- a/mm/mseal.c
+++ b/mm/mseal.c
@@ -40,9 +40,17 @@ static bool can_modify_vma(struct vm_area_struct *vma)
static bool is_madv_discard(int behavior)
{
- return behavior &
- (MADV_FREE | MADV_DONTNEED | MADV_DONTNEED_LOCKED |
- MADV_REMOVE | MADV_DONTFORK | MADV_WIPEONFORK);
+ switch (behavior) {
+ case MADV_FREE:
+ case MADV_DONTNEED:
+ case MADV_DONTNEED_LOCKED:
+ case MADV_REMOVE:
+ case MADV_DONTFORK:
+ case MADV_WIPEONFORK:
+ return true;
+ }
+
+ return false;
}
static bool is_ro_anon(struct vm_area_struct *vma)