From: David Hildenbrand <david@redhat.com>
To: Chengming Zhou <chengming.zhou@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Hugh Dickins <hughd@google.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Stefan Roesch <shr@devkernel.io>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
zhouchengming@bytedance.com
Subject: Re: [PATCH] mm/ksm: fix possible UAF of stable_node
Date: Tue, 14 May 2024 22:46:44 +0200 [thread overview]
Message-ID: <74a72eeb-122f-453e-baa7-63504e7c4bd8@redhat.com> (raw)
In-Reply-To: <20240513-b4-ksm-stable-node-uaf-v1-1-f687de76f452@linux.dev>
On 13.05.24 05:07, Chengming Zhou wrote:
> The commit 2c653d0ee2ae ("ksm: introduce ksm_max_page_sharing per page
> deduplication limit") introduced a possible failure case in the
> stable_tree_insert(), where we may free the new allocated stable_node_dup
> if we fail to prepare the missing chain node.
>
> Then that kfolio return and unlock with a freed stable_node set... And
> any MM activities can come in to access kfolio->mapping, so UAF.
>
> Fix it by moving folio_set_stable_node() to the end after stable_node
> is inserted successfully.
>
> Fixes: 2c653d0ee2ae ("ksm: introduce ksm_max_page_sharing per page deduplication limit")
> Signed-off-by: Chengming Zhou <chengming.zhou@linux.dev>
> ---
> mm/ksm.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/ksm.c b/mm/ksm.c
> index e1034bf1c937..a8b76af5cf64 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -2153,7 +2153,6 @@ static struct ksm_stable_node *stable_tree_insert(struct folio *kfolio)
>
> INIT_HLIST_HEAD(&stable_node_dup->hlist);
> stable_node_dup->kpfn = kpfn;
> - folio_set_stable_node(kfolio, stable_node_dup);
> stable_node_dup->rmap_hlist_len = 0;
> DO_NUMA(stable_node_dup->nid = nid);
> if (!need_chain) {
> @@ -2172,6 +2171,8 @@ static struct ksm_stable_node *stable_tree_insert(struct folio *kfolio)
> stable_node_chain_add_dup(stable_node_dup, stable_node);
> }
>
> + folio_set_stable_node(kfolio, stable_node_dup);
> +
> return stable_node_dup;
Looks correct to me.
We might now link the node before the folio->mapping is set up. Do we
care? Don't think so.
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-05-14 20:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-13 3:07 Chengming Zhou
2024-05-14 20:46 ` David Hildenbrand [this message]
2024-05-15 3:10 ` Chengming Zhou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=74a72eeb-122f-453e-baa7-63504e7c4bd8@redhat.com \
--to=david@redhat.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shr@devkernel.io \
--cc=zhouchengming@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox