From: Andrew Zaborowski <andrew.zaborowski@intel.com>
To: linux-edac@vger.kernel.org, linux-mm@kvack.org
Cc: Kees Cook <keescook@chromium.org>,
Tony Luck <tony.luck@intel.com>,
Eric Biederman <ebiederm@xmission.com>,
Borislav Petkov <bp@alien8.de>
Subject: [RESEND][PATCH 2/3] execve: Ensure SIGBUS delivered on memory failure
Date: Tue, 23 Jul 2024 16:47:51 +0200 [thread overview]
Message-ID: <20240723144752.1478226-2-andrew.zaborowski@intel.com> (raw)
In-Reply-To: <20240723144752.1478226-1-andrew.zaborowski@intel.com>
Uncorrected memory errors for user pages are signaled to processes
using SIGBUS or, if the error happens in a syscall, an error retval
from the syscall. The SIGBUS is documented in
Documentation/mm/hwpoison.rst#failure-recovery-modes
In execve() there is a point of no return
(bprm->point_of_no_return) after which the syscall... cannot return.
The binary loading happens after this point so if the loader triggers
a memory error reading user pages, and after control returns to
bprm_execve(), that function reacts by sending a SIGSEGV.
Set the new current->kill_on_efault flag and run pending task work to
ensure that a SIGBUS is queued in memory_failure()
Signed-off-by: Andrew Zaborowski <andrew.zaborowski@intel.com>
---
fs/exec.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index 400731422..26c4efe1a 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -68,6 +68,7 @@
#include <linux/user_events.h>
#include <linux/rseq.h>
#include <linux/ksm.h>
+#include <linux/task_work.h>
#include <linux/uaccess.h>
#include <asm/mmu_context.h>
@@ -1290,6 +1291,7 @@ int begin_new_exec(struct linux_binprm * bprm)
* Ensure all future errors are fatal.
*/
bprm->point_of_no_return = true;
+ me->kill_on_efault = true;
/*
* Make this the only thread in the thread group.
@@ -1896,6 +1898,7 @@ static int bprm_execve(struct linux_binprm *bprm)
/* execve succeeded */
current->fs->in_exec = 0;
current->in_execve = 0;
+ current->kill_on_efault = false;
rseq_execve(current);
user_events_execve(current);
acct_update_integrals(current);
@@ -1907,14 +1910,20 @@ static int bprm_execve(struct linux_binprm *bprm)
* If past the point of no return ensure the code never
* returns to the userspace process. Use an existing fatal
* signal if present otherwise terminate the process with
- * SIGSEGV.
+ * SIGSEGV. Run pending work before that in case it is
+ * terminating the process with a different signal.
*/
- if (bprm->point_of_no_return && !fatal_signal_pending(current))
- force_fatal_sig(SIGSEGV);
+ if (bprm->point_of_no_return) {
+ task_work_run();
+
+ if (!fatal_signal_pending(current))
+ force_fatal_sig(SIGSEGV);
+ }
sched_mm_cid_after_execve(current);
current->fs->in_exec = 0;
current->in_execve = 0;
+ current->kill_on_efault = false;
return retval;
}
--
2.43.0
next prev parent reply other threads:[~2024-07-23 14:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-23 14:47 [RESEND][PATCH 1/3] x86: Add task_struct flag to force SIGBUS on MCE Andrew Zaborowski
2024-07-23 14:47 ` Andrew Zaborowski [this message]
2024-07-23 14:47 ` [RESEND][PATCH 3/3] rseq: Ensure SIGBUS delivered on memory failure Andrew Zaborowski
2024-08-06 4:37 ` Kees Cook
2024-08-06 7:51 ` Peter Zijlstra
2024-08-06 14:19 ` Mathieu Desnoyers
2024-08-06 4:36 ` [RESEND][PATCH 1/3] x86: Add task_struct flag to force SIGBUS on MCE Kees Cook
2024-08-06 8:35 ` Borislav Petkov
[not found] ` <SA1PR11MB69926BFE8EFDA7B3C3D84560E7B82@SA1PR11MB6992.namprd11.prod.outlook.com>
[not found] ` <CAOq732KXwsKdht55E-Z18choiAYn6dMpXc-TD15B7MOUH1fpxQ@mail.gmail.com>
[not found] ` <20240808145331.GAZrTb60FX_I3p0Ukx@fat_crate.local>
2024-08-09 1:22 ` Andrew Zaborowski
2024-08-09 8:34 ` Borislav Petkov
[not found] ` <SA1PR11MB69927AE28B46583DCB5C97DEE7BA2@SA1PR11MB6992.namprd11.prod.outlook.com>
2024-08-10 1:20 ` Andrew Zaborowski
2024-08-10 3:21 ` Borislav Petkov
2024-08-10 3:55 ` Andrew Zaborowski
2024-08-10 9:25 ` Borislav Petkov
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=20240723144752.1478226-2-andrew.zaborowski@intel.com \
--to=andrew.zaborowski@intel.com \
--cc=bp@alien8.de \
--cc=ebiederm@xmission.com \
--cc=keescook@chromium.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tony.luck@intel.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