From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, Denis Kirjanov <kda@linux-powerpc.org>,
"Matthew Wilcox" <willy@infradead.org>,
"Michal Hocko" <mhocko@suse.com>,
"Dave Chinner" <david@fromorbit.com>,
"Kevin Easton" <kevin@guarana.org>,
"Josh Snyder" <joshs@netflix.com>,
"Andy Lutomirski" <luto@amacapital.net>,
"Tejun Heo" <tj@kernel.org>,
"Kirill A. Shutemov" <kirill@shutemov.name>,
"Linus Torvalds" <torvalds@linux-foundation.org>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Daniel Gruss" <daniel@gruss.cc>,
"Cyril Hrubis" <chrubis@suse.cz>, "Jiri Kosina" <jkosina@suse.cz>
Subject: [PATCH 3.16 02/10] mm/mincore.c: make mincore() more conservative
Date: Tue, 18 Jun 2019 15:28:02 +0100 [thread overview]
Message-ID: <lsq.1560868082.552948978@decadent.org.uk> (raw)
In-Reply-To: <lsq.1560868079.359853905@decadent.org.uk>
3.16.69-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Kosina <jkosina@suse.cz>
commit 134fca9063ad4851de767d1768180e5dede9a881 upstream.
The semantics of what mincore() considers to be resident is not
completely clear, but Linux has always (since 2.3.52, which is when
mincore() was initially done) treated it as "page is available in page
cache".
That's potentially a problem, as that [in]directly exposes
meta-information about pagecache / memory mapping state even about
memory not strictly belonging to the process executing the syscall,
opening possibilities for sidechannel attacks.
Change the semantics of mincore() so that it only reveals pagecache
information for non-anonymous mappings that belog to files that the
calling process could (if it tried to) successfully open for writing;
otherwise we'd be including shared non-exclusive mappings, which
- is the sidechannel
- is not the usecase for mincore(), as that's primarily used for data,
not (shared) text
[jkosina@suse.cz: v2]
Link: http://lkml.kernel.org/r/20190312141708.6652-2-vbabka@suse.cz
[mhocko@suse.com: restructure can_do_mincore() conditions]
Link: http://lkml.kernel.org/r/nycvar.YFH.7.76.1903062342020.19912@cbobk.fhfr.pm
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Josh Snyder <joshs@netflix.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Originally-by: Linus Torvalds <torvalds@linux-foundation.org>
Originally-by: Dominique Martinet <asmadeus@codewreck.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Kevin Easton <kevin@guarana.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Cyril Hrubis <chrubis@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Daniel Gruss <daniel@gruss.cc>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
--- a/mm/mincore.c
+++ b/mm/mincore.c
@@ -212,6 +212,22 @@ static void mincore_page_range(struct vm
} while (pgd++, addr = next, addr != end);
}
+static inline bool can_do_mincore(struct vm_area_struct *vma)
+{
+ if (vma_is_anonymous(vma))
+ return true;
+ if (!vma->vm_file)
+ return false;
+ /*
+ * Reveal pagecache information only for non-anonymous mappings that
+ * correspond to the files the calling process could (if tried) open
+ * for writing; otherwise we'd be including shared non-exclusive
+ * mappings, which opens a side channel.
+ */
+ return inode_owner_or_capable(file_inode(vma->vm_file)) ||
+ inode_permission(file_inode(vma->vm_file), MAY_WRITE) == 0;
+}
+
/*
* Do a chunk of "sys_mincore()". We've already checked
* all the arguments, we hold the mmap semaphore: we should
@@ -227,6 +243,11 @@ static long do_mincore(unsigned long add
return -ENOMEM;
end = min(vma->vm_end, addr + (pages << PAGE_SHIFT));
+ if (!can_do_mincore(vma)) {
+ unsigned long pages = DIV_ROUND_UP(end - addr, PAGE_SIZE);
+ memset(vec, 1, pages);
+ return pages;
+ }
if (is_vm_hugetlb_page(vma))
mincore_hugetlb_page_range(vma, addr, end, vec);
next prev parent reply other threads:[~2019-06-18 14:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-18 14:27 [PATCH 3.16 00/10] 3.16.69-rc1 review Ben Hutchings
2019-06-18 14:28 ` [PATCH 3.16 05/10] ext4: zero out the unused memory region in the extent tree block Ben Hutchings
2019-06-18 14:28 ` [PATCH 3.16 07/10] tcp: limit payload size of sacked skbs Ben Hutchings
2019-06-18 14:28 ` [PATCH 3.16 10/10] tcp: enforce tcp_min_snd_mss in tcp_mtu_probing() Ben Hutchings
2019-06-18 14:28 ` [PATCH 3.16 09/10] tcp: add tcp_min_snd_mss sysctl Ben Hutchings
2019-06-18 14:28 ` [PATCH 3.16 01/10] mm: introduce vma_is_anonymous(vma) helper Ben Hutchings
2019-06-18 14:28 ` [PATCH 3.16 06/10] Bluetooth: hidp: fix buffer overflow Ben Hutchings
2019-06-18 14:28 ` [PATCH 3.16 03/10] drivers/virt/fsl_hypervisor.c: prevent integer overflow in ioctl Ben Hutchings
2019-06-18 14:28 ` Ben Hutchings [this message]
2019-06-18 14:28 ` [PATCH 3.16 04/10] scsi: megaraid_sas: return error when create DMA pool failed Ben Hutchings
2019-06-18 14:28 ` [PATCH 3.16 08/10] tcp: tcp_fragment() should apply sane memory limits Ben Hutchings
2019-07-02 2:51 ` Florian Fainelli
2019-07-05 14:54 ` Ben Hutchings
2019-06-19 21:58 ` [PATCH 3.16 00/10] 3.16.69-rc1 review Guenter Roeck
2019-06-19 22:02 ` Ben Hutchings
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=lsq.1560868082.552948978@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=akpm@linux-foundation.org \
--cc=chrubis@suse.cz \
--cc=daniel@gruss.cc \
--cc=david@fromorbit.com \
--cc=jkosina@suse.cz \
--cc=joshs@netflix.com \
--cc=kda@linux-powerpc.org \
--cc=kevin@guarana.org \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mhocko@suse.com \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
--cc=willy@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