From patchwork Tue Jul 23 14:47:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Zaborowski X-Patchwork-Id: 13740153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77A84C3DA49 for ; Tue, 23 Jul 2024 14:48:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F18766B00AD; Tue, 23 Jul 2024 10:48:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA1476B00AE; Tue, 23 Jul 2024 10:48:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D44046B00B0; Tue, 23 Jul 2024 10:48:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B719B6B00AD for ; Tue, 23 Jul 2024 10:48:07 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4D60FA019F for ; Tue, 23 Jul 2024 14:48:07 +0000 (UTC) X-FDA: 82371297414.22.F97D594 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by imf17.hostedemail.com (Postfix) with ESMTP id 625E24001B for ; Tue, 23 Jul 2024 14:48:05 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of balrogg@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=balrogg@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=intel.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721746023; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uk7q0YZEAexRwDC7TlJ8MY8yGZV+7BAd5qc9ovT0Rfs=; b=2Q8CTX2vbDwgCXJ1rSWlrYjqwxvT+vppMrTg+thqLFhOhiRMQVKGjeOeceLI5E/ZYhzfRD pOzZiCqn0KKvq2jE8kVEgMUbo5EacANa9y3ZSSpu2HGPjVXRTDOJijnGoxywXxtZheBlx9 SfoEz7M1YC2UImKbQ/pTDSv/7nW89Qo= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of balrogg@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=balrogg@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=intel.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721746023; a=rsa-sha256; cv=none; b=A55JmmpmM5cYZA/SzvYS9ZZYcS/B8wbXuIgsVvoatE6kKqsUq4gZcCdN4ZPSM+rxZITD32 WpaSJgT7VksCLaN/MrQ8TZdgi4mbXfD10+3Q5yCRfZM7ObvUcs+JdiK9cfe5B614TPdvqw 46vinwHzrcMc573J9sBLrLly5y1bI1Y= Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5a3b866ebc9so3710714a12.3 for ; Tue, 23 Jul 2024 07:48:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721746084; x=1722350884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Uk7q0YZEAexRwDC7TlJ8MY8yGZV+7BAd5qc9ovT0Rfs=; b=chYRtJtTGoz4fAV9yF+F+OTllBu5zju80soM9ExBPdMxYbDZHrWFW/GTv+8eMaOJEs JLC/32bTfki/eyP9j4fi+LDf0FA1wNkQGhaQlUnFdXKk8TEfVfnnNG20ukZ/9jjdpEee BDJUDfDH3leqw5lFUICI1qRokJyQdgUyzO7w/vODHFGbGKcn3EgQHz6jnvZ+mu+2ubgH DR3hj4OtcPY02p8kqJ7M4OSKMt6UDp7xkMJHa8yz1cJbaZZFz7fiArJ1l+SEmOUaIOlh tP+XvcCbUXe3dQUJ2ynFEU7PKv64LrBbp7Gwc4MCoO5OuggB3xXnDJ/c1h15utmUyr3d OVSw== X-Forwarded-Encrypted: i=1; AJvYcCWyWDJDMn+4Y5VFavZKw2BVd35dprO2awCHsyDaG6GiQ191nXB/1rYfPyX5EcHYcL88n2aqWddo99vWRNmZTNchfEk= X-Gm-Message-State: AOJu0YxetO43cHZSwH6NYWesKEBzGRfGInDh/jrdQIfPJ4Ly439xLiqo LW7yQ7TGTQgyI2yjuYXSl7u0xglJDUs5MGbkNz1116LsC/gIEraj X-Google-Smtp-Source: AGHT+IFha2h6a6MvQHTcjWMHo++g83oEpo5lFlYgf69Px3ng8ztnl88jC5Ynwb7213r/pEK/4abM0g== X-Received: by 2002:a50:9b4a:0:b0:5a3:b866:eae0 with SMTP id 4fb4d7f45d1cf-5aaa596d039mr76881a12.32.1721746083530; Tue, 23 Jul 2024 07:48:03 -0700 (PDT) Received: from localhost.localdomain ([2a01:110f:4a11:8500:e7a:15ff:fe95:b9d8]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5a30c7d36f3sm7555071a12.91.2024.07.23.07.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 07:48:02 -0700 (PDT) From: Andrew Zaborowski To: linux-edac@vger.kernel.org, linux-mm@kvack.org Cc: Kees Cook , Tony Luck , Eric Biederman , Borislav Petkov Subject: [RESEND][PATCH 2/3] execve: Ensure SIGBUS delivered on memory failure Date: Tue, 23 Jul 2024 16:47:51 +0200 Message-ID: <20240723144752.1478226-2-andrew.zaborowski@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240723144752.1478226-1-andrew.zaborowski@intel.com> References: <20240723144752.1478226-1-andrew.zaborowski@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 625E24001B X-Stat-Signature: zaor8p36t7p9njpg1q3gp9gfmbhhctgz X-Rspam-User: X-HE-Tag: 1721746085-626553 X-HE-Meta: U2FsdGVkX18AJkckUB42ZrdwV7VFxGDVYNkgSYMh3cuAQmUCs6HyGHKkIZkLQoiI8B0s7fLa/W8lnb66zRhosTIhINgvNBT40amryEuFi6Sc50lwYsVu6PYoB5ue6ccaafWx9ybzVeTL3fUJI+XZfVMWdqqDjx1fVfoPVZAlAOqTIxAwsrO2ubdukxggAy6ojXW0c3ggyiRZc+g2yPUP/rSUVm+3Y9K/rKkU4oTtpXQfvnEy1o69JQtYLWBrZBpoXZ/aCyeV0qRUX+/pgmLH2iBN14xXPt1F5Gln8ayT0pN5HM2VCmho/CelWsyMGV/c9/VxwT4waJqyJuxUi819zwplVkEqR2LB+Vi0Xa999c2WIUS5O0jOLUwwMKCrHECvRRNXKB6RTJ+wHjvn+QmBWrNmCEgI4wq3DssUd0QZtIvwYMfsEbYNuExwA9/6TCOZOtrMqrmmaZT8ehxzJWF87jr8nxE8CK+x99FmER+OVk5iMHdXJOAaPEF4Y7E6H4qXD62TifrfC0/VNkV7BCluAwY/MOZz/8f6ijNQYJg5P/7BLw3hvcv2zgM5J6JMp7cbu4bkE45nEBKrnI4mugy8qAnvFvoeIhX+SbTU98HS0gfmesJUBxuAZ6BKMmVuvHzeDDWzBeWa+b2ebc7EjXaSRHGii3PQV79u6IOCZRWTn2lSbG5UynpE5u99GD/aZ/TmbLdZgThSMaf9g2UAfe8zhkrt3JlSVPMMslaRnk87CjJqobPrqCWSCeQSifR3md5gruN+Q+OWPbG6cueo+7iV0OjXHla+GPa5Xv4UnRXF2rWb1we6liRjLkv17n0TtyVug9YvzjFe67cib6+Y0hBQkmvnywbkbMhXkuZtbbyl+IvbR60wTyFulIeyW0Hv98raON/Zd8E+XURuLugkIYCi3iya8yLlsj/dq6zWzOC/1ZWp0mZSKa6ayuTSkmwT0misTuquJcnt0ToLL3+ZhNt 6thk/gah Qq2YzfmI+vxmrQIHQqFKpPWOxqe2agFfn/AUQg5GXUhoYAtSRvO/cxShWUDIvxSTE3ooAX6SVju35P6Ti6SKzxwKlK6RQjh869+R0ANsBai8dWuNxnTxE9qAh2PTOcANS+rlwvi/9g8D9nfATkHmgp33Uhlm75AAoU3uW/sHT8zfF86mAsJsl2q91aK/doPhzDMViUgJ3UAyN9u+wpP6zDGcOFHIiApkzkkRowFJGcMz8OvW48f92aO9uYACCB+oWAXUk++642fQoaUdZKix8VupFeUJQPKqi1kGW0MOCP8+eotd8582UlIJYHilA7F3KcT6EiUsNlWryWnOfqlf91blqssLpFx2ZNRSUnhKqrINYt6x6gyv/mKC3I2FInAXs1Kp9sJt1S641P2SBZiDay+/tPxc1hhvYfkFTV5LXMxb3P85kiF7e4pthqMO250IeZ6Xo X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- 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 #include #include +#include #include #include @@ -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; }