mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Guenter Roeck <linux@roeck-us.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/urgent] x86/mm: Fix pti_clone_pgtable() alignment assumption
Date: Thu, 01 Aug 2024 10:55:32 -0000	[thread overview]
Message-ID: <172250973229.2215.8425940959520979454.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20240731163105.GG33588@noisy.programming.kicks-ass.net>

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     36e2dcf9840019de70e517a9df890fff316dd522
Gitweb:        https://git.kernel.org/tip/36e2dcf9840019de70e517a9df890fff316dd522
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Wed, 31 Jul 2024 18:31:05 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Thu, 01 Aug 2024 12:48:22 +02:00

x86/mm: Fix pti_clone_pgtable() alignment assumption

Guenter reported dodgy crashes on an i386-nosmp build using GCC-11
that had the form of endless traps until entry stack exhaust and then
#DF from the stack guard.

It turned out that pti_clone_pgtable() had alignment assumptions on
the start address, notably it hard assumes start is PMD aligned. This
is true on x86_64, but very much not true on i386.

These assumptions can cause the end condition to malfunction, leading
to a 'short' clone. Guess what happens when the user mapping has a
short copy of the entry text?

Use the correct increment form for addr to avoid alignment
assumptions.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20240731163105.GG33588@noisy.programming.kicks-ass.net
---
 arch/x86/mm/pti.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 2e69abf..48c5032 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -374,14 +374,14 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
 			 */
 			*target_pmd = *pmd;
 
-			addr += PMD_SIZE;
+			addr = round_up(addr + 1, PMD_SIZE);
 
 		} else if (level == PTI_CLONE_PTE) {
 
 			/* Walk the page-table down to the pte level */
 			pte = pte_offset_kernel(pmd, addr);
 			if (pte_none(*pte)) {
-				addr += PAGE_SIZE;
+				addr = round_up(addr + 1, PAGE_SIZE);
 				continue;
 			}
 
@@ -401,7 +401,7 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
 			/* Clone the PTE */
 			*target_pte = *pte;
 
-			addr += PAGE_SIZE;
+			addr = round_up(addr + 1, PAGE_SIZE);
 
 		} else {
 			BUG();

  parent reply	other threads:[~2024-08-01 10:55 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-28 21:40 Linux 6.11-rc1 Linus Torvalds
2024-07-29  9:28 ` Build regressions/improvements in v6.11-rc1 Geert Uytterhoeven
2024-07-29  9:35   ` Geert Uytterhoeven
2024-07-29  9:54     ` Arnd Bergmann
2024-07-29 10:07       ` Geert Uytterhoeven
2024-07-29 15:29 ` Linux 6.11-rc1 Guenter Roeck
2024-07-29 19:23   ` Linus Torvalds
2024-07-29 19:50     ` Linus Torvalds
2024-07-29 21:34       ` Arnd Bergmann
2024-07-29 23:47         ` Linus Torvalds
2024-07-30 15:47           ` Arnd Bergmann
2024-07-30  7:54     ` Peter Zijlstra
2024-07-31 15:45     ` Guenter Roeck
2024-07-30 17:04   ` Guenter Roeck
2024-07-30 17:20     ` Jens Axboe
2024-07-30 18:22       ` Guenter Roeck
2024-07-30 18:35         ` Jens Axboe
2024-07-30 18:54           ` Jens Axboe
2024-07-30 18:53     ` Linus Torvalds
2024-07-30 19:22       ` Peter Zijlstra
2024-07-30 19:31         ` Jens Axboe
2024-07-30 19:34           ` Jens Axboe
2024-07-30 19:38           ` Peter Zijlstra
2024-07-30 19:41             ` Linus Torvalds
2024-07-30 20:04             ` Guenter Roeck
2024-07-30 20:09               ` Peter Zijlstra
2024-07-30 21:12                 ` Peter Zijlstra
2024-07-30 23:29                 ` Guenter Roeck
2024-07-30 23:54                   ` Linus Torvalds
2024-07-31  8:21                     ` Borislav Petkov
2024-07-31  9:11                       ` Peter Zijlstra
2024-07-31 10:02                         ` Borislav Petkov
2024-07-31 14:37                       ` Guenter Roeck
2024-07-31 13:24                     ` Jens Axboe
2024-07-30 20:13               ` Linus Torvalds
2024-07-30 20:24             ` Guenter Roeck
2024-07-31 12:20               ` Peter Zijlstra
2024-07-31 13:03                 ` Thomas Gleixner
2024-07-31 15:55                   ` Peter Zijlstra
2024-07-31 16:17                     ` Linus Torvalds
2024-07-31 16:31                       ` Peter Zijlstra
2024-07-31 16:50                         ` Guenter Roeck
2024-07-31 16:51                         ` Peter Zijlstra
2024-07-31 17:26                           ` Thomas Gleixner
2024-07-31 21:20                             ` Peter Zijlstra
2024-07-31 21:23                               ` Linus Torvalds
2024-07-31 21:26                                 ` Peter Zijlstra
2024-07-31 21:41                                   ` Linus Torvalds
2024-07-31 21:47                                     ` Thomas Gleixner
2024-07-31 22:22                               ` Guenter Roeck
2024-08-01  8:54                                 ` Peter Zijlstra
2024-08-01 10:55                         ` tip-bot2 for Peter Zijlstra [this message]
2024-08-01 13:03                         ` [tip: x86/urgent] x86/mm: Fix pti_clone_pgtable() alignment assumption tip-bot2 for Peter Zijlstra
2024-07-31 16:49                       ` Linux 6.11-rc1 Guenter Roeck
2024-07-31 17:19                         ` Thomas Gleixner
2024-07-31 10:33       ` Peter Zijlstra
2024-07-31 14:15         ` Peter Zijlstra
2024-08-02 17:35   ` Linus Walleij
2024-08-02 19:40     ` Guenter Roeck

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=172250973229.2215.8425940959520979454.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®