[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211115165458.931413602@linuxfoundation.org>
Date: Mon, 15 Nov 2021 18:06:16 +0100
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: linux-kernel@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
stable@...r.kernel.org,
Rongwei Wang <rongwei.wang@...ux.alibaba.com>,
Xu Yu <xuyu@...ux.alibaba.com>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
Song Liu <song@...nel.org>,
William Kucharski <william.kucharski@...cle.com>,
Hugh Dickins <hughd@...gle.com>,
Yang Shi <shy828301@...il.com>,
Mike Kravetz <mike.kravetz@...cle.com>,
Collin Fijalkovich <cfijalkovich@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Linus Torvalds <torvalds@...ux-foundation.org>
Subject: [PATCH 5.15 881/917] mm, thp: fix incorrect unmap behavior for private pages
From: Rongwei Wang <rongwei.wang@...ux.alibaba.com>
commit 8468e937df1f31411d1e127fa38db064af051fe5 upstream.
When truncating pagecache on file THP, the private pages of a process
should not be unmapped mapping. This incorrect behavior on a dynamic
shared libraries which will cause related processes to happen core dump.
A simple test for a DSO (Prerequisite is the DSO mapped in file THP):
int main(int argc, char *argv[])
{
int fd;
fd = open(argv[1], O_WRONLY);
if (fd < 0) {
perror("open");
}
close(fd);
return 0;
}
The test only to open a target DSO, and do nothing. But this operation
will lead one or more process to happen core dump. This patch mainly to
fix this bug.
Link: https://lkml.kernel.org/r/20211025092134.18562-3-rongwei.wang@linux.alibaba.com
Fixes: eb6ecbed0aa2 ("mm, thp: relax the VM_DENYWRITE constraint on file-backed THPs")
Signed-off-by: Rongwei Wang <rongwei.wang@...ux.alibaba.com>
Tested-by: Xu Yu <xuyu@...ux.alibaba.com>
Cc: Matthew Wilcox (Oracle) <willy@...radead.org>
Cc: Song Liu <song@...nel.org>
Cc: William Kucharski <william.kucharski@...cle.com>
Cc: Hugh Dickins <hughd@...gle.com>
Cc: Yang Shi <shy828301@...il.com>
Cc: Mike Kravetz <mike.kravetz@...cle.com>
Cc: Collin Fijalkovich <cfijalkovich@...gle.com>
Cc: <stable@...r.kernel.org>
Signed-off-by: Andrew Morton <akpm@...ux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@...ux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
fs/open.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
--- a/fs/open.c
+++ b/fs/open.c
@@ -857,8 +857,17 @@ static int do_dentry_open(struct file *f
*/
smp_mb();
if (filemap_nr_thps(inode->i_mapping)) {
+ struct address_space *mapping = inode->i_mapping;
+
filemap_invalidate_lock(inode->i_mapping);
- truncate_pagecache(inode, 0);
+ /*
+ * unmap_mapping_range just need to be called once
+ * here, because the private pages is not need to be
+ * unmapped mapping (e.g. data segment of dynamic
+ * shared libraries here).
+ */
+ unmap_mapping_range(mapping, 0, 0, 0);
+ truncate_inode_pages(mapping, 0);
filemap_invalidate_unlock(inode->i_mapping);
}
}
Powered by blists - more mailing lists