From: Jann Horn <jannh@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Pavel Emelyanov <xemul@parallels.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Hugh Dickins <hughd@google.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Jann Horn <jannh@google.com>,
stable@vger.kernel.org
Subject: [PATCH 0/2] userfaultfd: fix races around pmd_trans_huge() check
Date: Mon, 12 Aug 2024 18:42:15 +0200 [thread overview]
Message-ID: <20240812-uffd-thp-flip-fix-v1-0-4fc1db7ccdd0@google.com> (raw)
The pmd_trans_huge() code in mfill_atomic() is wrong in two different
ways depending on kernel version:
1. The pmd_trans_huge() check is racy and can lead to a BUG_ON() (if you hit
the right two race windows) - I've tested this in a kernel build with
some extra mdelay() calls. See the commit message for a description
of the race scenario.
On older kernels (before 6.5), I think the same bug can even
theoretically lead to accessing transhuge page contents as a page table
if you hit the right 5 narrow race windows (I haven't tested this case).
2. On newer kernels (>=6.5), for shmem mappings, khugepaged is allowed
to yank page tables out from under us (though I haven't tested that),
so I think the BUG_ON() checks in mfill_atomic() are just wrong.
I decided to write two separate fixes for these, so that the first fix
can be backported to kernels affected by the first bug.
Signed-off-by: Jann Horn <jannh@google.com>
---
Jann Horn (2):
userfaultfd: Fix pmd_trans_huge() recheck race
userfaultfd: Don't BUG_ON() if khugepaged yanks our page table
mm/userfaultfd.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
---
base-commit: d4560686726f7a357922f300fc81f5964be8df04
change-id: 20240812-uffd-thp-flip-fix-20f91f1151b9
--
Jann Horn <jannh@google.com>
next reply other threads:[~2024-08-12 16:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-12 16:42 Jann Horn [this message]
2024-08-12 16:42 ` [PATCH 1/2] userfaultfd: Fix pmd_trans_huge() recheck race Jann Horn
2024-08-13 6:19 ` Qi Zheng
2024-08-13 14:57 ` Jann Horn
2024-08-13 9:28 ` David Hildenbrand
2024-08-12 16:42 ` [PATCH 2/2] userfaultfd: Don't BUG_ON() if khugepaged yanks our page table Jann Horn
2024-08-13 6:24 ` Qi Zheng
2024-08-13 9:27 ` David Hildenbrand
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=20240812-uffd-thp-flip-fix-v1-0-4fc1db7ccdd0@google.com \
--to=jannh@google.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.kernel.org \
--cc=xemul@parallels.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