[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7c62d837-d205-4924-8839-644d8981eabe@lucifer.local>
Date: Wed, 7 Aug 2024 14:13:15 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Pedro Falcato <pedro.falcato@...il.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
"Liam R. Howlett" <Liam.Howlett@...cle.com>,
Vlastimil Babka <vbabka@...e.cz>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, oliver.sang@...el.com,
torvalds@...ux-foundation.org, jeffxu@...gle.com,
Michael Ellerman <mpe@...erman.id.au>
Subject: Re: [PATCH 5/7] mseal: Fix is_madv_discard()
On Tue, Aug 06, 2024 at 10:28:06PM GMT, Pedro Falcato wrote:
> 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. This is obviously incorrect, so use
> a switch statement instead.
>
> Signed-off-by: Pedro Falcato <pedro.falcato@...il.com>
> ---
> mm/mseal.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/mm/mseal.c b/mm/mseal.c
> index 4591ae8d29c..2170e2139ca 100644
> --- a/mm/mseal.c
> +++ b/mm/mseal.c
> @@ -23,9 +23,17 @@ static inline void set_vma_sealed(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)
> --
> 2.46.0
>
Wow. Great spot, and what an oversight. Agree with Jeff, we really sould
pull this out separately as this is something that urgently needs fixing.
Ideally we'd add a test of some kind, but since it's so obviously wrong I
think it'd be fine without at least as a quick fixup.
This will need to be hotfixed/cc-d to stable too since it's in a released
kernel version.
Powered by blists - more mailing lists