From: Benjamin Berg <benjamin@sipsolutions.net>
To: linux-um@lists.infradead.org
Cc: Benjamin Berg <benjamin.berg@intel.com>
Subject: [PATCH v4 09/12] um: Do not flush MM in flush_thread
Date: Wed, 3 Jul 2024 15:45:33 +0200 [thread overview]
Message-ID: <20240703134536.1161108-10-benjamin@sipsolutions.net> (raw)
In-Reply-To: <20240703134536.1161108-1-benjamin@sipsolutions.net>
From: Benjamin Berg <benjamin.berg@intel.com>
There should be no need to flush the memory in flush_thread. Doing this
likely worked around some issue where memory was still incorrectly
mapped when creating or cloning an MM.
With the removal of the special clone path, that isn't relevant anymore.
However, add the flush into MM initialization so that any new userspace
MM is guaranteed to be clean.
Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
---
v4: Only clear memory up to TASK_SIZE
---
arch/um/kernel/exec.c | 5 -----
arch/um/kernel/skas/mmu.c | 24 ++++++++++++++++++++++++
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/arch/um/kernel/exec.c b/arch/um/kernel/exec.c
index 5c8836b012e9..2c15bb2c104c 100644
--- a/arch/um/kernel/exec.c
+++ b/arch/um/kernel/exec.c
@@ -24,11 +24,6 @@ void flush_thread(void)
{
arch_flush_thread(¤t->thread.arch);
- unmap(¤t->mm->context.id, 0, TASK_SIZE);
- if (syscall_stub_flush(¤t->mm->context.id) < 0) {
- printk(KERN_ERR "%s - clearing address space failed", __func__);
- force_sig(SIGKILL);
- }
get_safe_registers(current_pt_regs()->regs.gp,
current_pt_regs()->regs.fp);
diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c
index 697dad49c36b..47f98d87ea3c 100644
--- a/arch/um/kernel/skas/mmu.c
+++ b/arch/um/kernel/skas/mmu.c
@@ -40,6 +40,30 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
goto out_free;
}
+ /*
+ * Ensure the new MM is clean and nothing unwanted is mapped.
+ *
+ * TODO: We should clear the memory up to STUB_START to ensure there is
+ * nothing mapped there, i.e. we (currently) have:
+ *
+ * |- user memory -|- unused -|- stub -|- unused -|
+ * ^ TASK_SIZE ^ STUB_START
+ *
+ * Meaning we have two unused areas where we may still have valid
+ * mappings from our internal clone(). That isn't really a problem as
+ * userspace is not going to access them, but it is definitely not
+ * correct.
+ *
+ * However, we are "lucky" and if rseq is configured, then on 32 bit
+ * it will fall into the first empty range while on 64 bit it is going
+ * to use an anonymous mapping in the second range. As such, things
+ * continue to work for now as long as we don't start unmapping these
+ * areas.
+ *
+ * Change this to STUB_START once we have a clean userspace.
+ */
+ unmap(new_id, 0, TASK_SIZE);
+
return 0;
out_free:
--
2.45.2
next prev parent reply other threads:[~2024-07-03 15:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-03 13:45 [PATCH v4 00/12] Rework stub syscall and page table handling Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 01/12] um: Remove stub-data.h include from common-offsets.h Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 02/12] um: Create signal stack memory assignment in stub_data Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 03/12] um: Add generic stub_syscall6 function Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 04/12] um: Rework syscall handling Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 05/12] um: compress memory related stub syscalls while adding them Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 06/12] um: remove LDT support Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 07/12] um: remove copy_context_skas0 Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 08/12] um: Delay flushing syscalls until the thread is restarted Benjamin Berg
2024-07-03 13:45 ` Benjamin Berg [this message]
2024-07-03 13:45 ` [PATCH v4 10/12] um: remove force_flush_all from fork_handler Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 11/12] um: simplify and consolidate TLB updates Benjamin Berg
2024-07-03 13:45 ` [PATCH v4 12/12] um: refactor TLB update handling Benjamin Berg
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=20240703134536.1161108-10-benjamin@sipsolutions.net \
--to=benjamin@sipsolutions.net \
--cc=benjamin.berg@intel.com \
--cc=linux-um@lists.infradead.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