mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org,
	mike.kravetz@oracle.com, mm-commits@vger.kernel.org,
	naoya.horiguchi@nec.com, osalvador@suse.de,
	torvalds@linux-foundation.org, willy@infradead.org,
	yaoaili@kingsoft.com
Subject: [patch 07/16] mm/gup: check page posion status for coredump.
Date: Fri, 09 Apr 2021 13:27:19 -0700	[thread overview]
Message-ID: <20210409202719.tI0cmqT6l%akpm@linux-foundation.org> (raw)
In-Reply-To: <20210409132633.6855fc8fea1b3905ea1bb4be@linux-foundation.org>

From: Aili Yao <yaoaili@kingsoft.com>
Subject: mm/gup: check page posion status for coredump.

When we do coredump for user process signal, this may be an SIGBUS signal
with BUS_MCEERR_AR or BUS_MCEERR_AO code, which means this signal is
resulted from ECC memory fail like SRAR or SRAO, we expect the memory
recovery work is finished correctly, then the get_dump_page() will not
return the error page as its process pte is set invalid by
memory_failure().

But memory_failure() may fail, and the process's related pte may not be
correctly set invalid, for current code, we will return the poison page,
get it dumped, and then lead to system panic as its in kernel code.

So check the poison status in get_dump_page(), and if TRUE, return NULL.

There maybe other scenario that is also better to check the posion status
and not to panic, so make a wrapper for this check, Thanks to David's
suggestion(<david@redhat.com>).

[akpm@linux-foundation.org: s/0/false/]
[yaoaili@kingsoft.com: is_page_poisoned() arg cannot be null, per Matthew]
  Link: https://lkml.kernel.org/r/20210319104437.6f30e80d@alex-virtual-machine
  Link: https://lkml.kernel.org/r/20210322115233.05e4e82a@alex-virtual-machine
Link: https://lkml.kernel.org/r/20210319104437.6f30e80d@alex-virtual-machine
Signed-off-by: Aili Yao <yaoaili@kingsoft.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Aili Yao <yaoaili@kingsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/gup.c      |    4 ++++
 mm/internal.h |   20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

--- a/mm/gup.c~mm-gup-check-page-posion-status-for-coredump
+++ a/mm/gup.c
@@ -1535,6 +1535,10 @@ struct page *get_dump_page(unsigned long
 				      FOLL_FORCE | FOLL_DUMP | FOLL_GET);
 	if (locked)
 		mmap_read_unlock(mm);
+
+	if (ret == 1 && is_page_poisoned(page))
+		return NULL;
+
 	return (ret == 1) ? page : NULL;
 }
 #endif /* CONFIG_ELF_CORE */
--- a/mm/internal.h~mm-gup-check-page-posion-status-for-coredump
+++ a/mm/internal.h
@@ -97,6 +97,26 @@ static inline void set_page_refcounted(s
 	set_page_count(page, 1);
 }
 
+/*
+ * When kernel touch the user page, the user page may be have been marked
+ * poison but still mapped in user space, if without this page, the kernel
+ * can guarantee the data integrity and operation success, the kernel is
+ * better to check the posion status and avoid touching it, be good not to
+ * panic, coredump for process fatal signal is a sample case matching this
+ * scenario. Or if kernel can't guarantee the data integrity, it's better
+ * not to call this function, let kernel touch the poison page and get to
+ * panic.
+ */
+static inline bool is_page_poisoned(struct page *page)
+{
+	if (PageHWPoison(page))
+		return true;
+	else if (PageHuge(page) && PageHWPoison(compound_head(page)))
+		return true;
+
+	return false;
+}
+
 extern unsigned long highest_memmap_pfn;
 
 /*
_

  parent reply	other threads:[~2021-04-09 20:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-09 20:26 incoming Andrew Morton
2021-04-09 20:27 ` [patch 01/16] MAINTAINERS: update CZ.NIC's Turris information Andrew Morton
2021-04-09 20:27 ` [patch 02/16] treewide: change my e-mail address, fix my name Andrew Morton
2021-04-09 20:27 ` [patch 03/16] mailmap: update email address for Jordan Crouse Andrew Morton
2021-04-09 20:27 ` [patch 04/16] .mailmap: fix old email addresses Andrew Morton
2021-04-09 20:27 ` [patch 05/16] kasan: fix hwasan build for gcc Andrew Morton
2021-04-09 20:39   ` Andrey Konovalov
2021-04-09 20:58     ` Andrew Morton
2021-04-12  9:56       ` Marco Elver
2021-04-12 12:54         ` Andrey Konovalov
2021-04-09 21:55     ` Linus Torvalds
2021-04-09 20:27 ` [patch 06/16] kasan: remove redundant config option Andrew Morton
2021-04-09 20:27 ` Andrew Morton [this message]
2021-04-09 20:27 ` [patch 08/16] nds32: flush_dcache_page: use page_mapping_file to avoid races with swapoff Andrew Morton
2021-04-09 20:27 ` [patch 09/16] gcov: re-fix clang-11+ support Andrew Morton
2021-04-09 20:27 ` [patch 10/16] ocfs2: fix deadlock between setattr and dio_end_io_write Andrew Morton
2021-04-09 20:27 ` [patch 11/16] ia64: fix user_stack_pointer() for ptrace() Andrew Morton
2021-04-09 20:27 ` [patch 12/16] fs: direct-io: fix missing sdio->boundary Andrew Morton
2021-04-09 20:27 ` [patch 13/16] kasan: fix conflict with page poisoning Andrew Morton
2021-04-09 20:27 ` [patch 14/16] lib/test_kasan_module.c: suppress unused var warning Andrew Morton
2021-04-09 20:27 ` [patch 15/16] kfence, x86: fix preemptible warning on KPTI-enabled systems Andrew Morton
2021-04-09 20:27 ` [patch 16/16] lib: fix kconfig dependency on ARCH_WANT_FRAME_POINTERS Andrew Morton

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=20210409202719.tI0cmqT6l%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=mm-commits@vger.kernel.org \
    --cc=naoya.horiguchi@nec.com \
    --cc=osalvador@suse.de \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.org \
    --cc=yaoaili@kingsoft.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;
as well as URLs for NNTP newsgroup(s).