linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mietek N <namiltd@yahoo.com>
To: "linux-mips@vger.kernel.org" <linux-mips@vger.kernel.org>
Subject: [PATCH] ramips/mt7620: IRQ-protect stack ASLR randomization  in arch_align_stack
Date: Thu, 9 Oct 2025 00:11:46 +0000 (UTC)	[thread overview]
Message-ID: <825527059.1016043.1759968706607@mail.yahoo.com> (raw)
In-Reply-To: 825527059.1016043.1759968706607.ref@mail.yahoo.com

On MT7620 (MIPS 24KEc), sporadic Oopses were observed during execve while
randomizing the new process stack in arch_align_stack(), which calls
get_random_u32_below(PAGE_SIZE).

On MIPS32, even the "<=16-bit" multiply path used by get_random_u32_below()
emits a 32-bit multiply and reads HI/LO via mfhi/mflo. If a hard IRQ fires
between multu and mfhi/mflo and its handler also executes mul/div, HI/LO can
be clobbered, leading to corrupted intermediates and bogus addresses.

Make the random stack offset computation IRQ-safe on MT7620 by wrapping the
get_random_u32_below(PAGE_SIZE) call with local_irq_save/restore(), ensuring
the multu/mfhi/mflo sequence is not interrupted by hard IRQs. This preserves
stack ASLR while eliminating the crash on this platform.

Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>

--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -715,8 +715,16 @@ unsigned long mips_stack_top(void)
  */
 unsigned long arch_align_stack(unsigned long sp)
 {
-    if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
+    if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) {
#if defined(CONFIG_MIPS) && !defined(CONFIG_CPU_MIPSR6)
+        unsigned long flags;
+        local_irq_save(flags);
         sp -= get_random_u32_below(PAGE_SIZE);
+        local_irq_restore(flags);
+#else
+        sp -= get_random_u32_below(PAGE_SIZE);
+#endif
+    }

     return sp & ALMASK;
 }

       reply	other threads:[~2025-10-09  0:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <825527059.1016043.1759968706607.ref@mail.yahoo.com>
2025-10-09  0:11 ` Mietek N [this message]
     [not found] <93986679.1000024.1759965445400.ref@mail.yahoo.com>
2025-10-08 23:17 ` [PATCH] ramips/mt7620: IRQ-protect stack ASLR randomization in arch_align_stack Mietek N

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=825527059.1016043.1759968706607@mail.yahoo.com \
    --to=namiltd@yahoo.com \
    --cc=linux-mips@vger.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;
as well as URLs for NNTP newsgroup(s).