mm/mincore.c: make mincore() more conservative

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

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

[ v2]
[ restructure can_do_mincore() conditions]
Signed-off-by: Jiri Kosina <>
Signed-off-by: Vlastimil Babka <>
Acked-by: Josh Snyder <>
Acked-by: Michal Hocko <>
Originally-by: Linus Torvalds <>
Originally-by: Dominique Martinet <>
Cc: Andy Lutomirski <>
Cc: Dave Chinner <>
Cc: Kevin Easton <>
Cc: Matthew Wilcox <>
Cc: Cyril Hrubis <>
Cc: Tejun Heo <>
Cc: Kirill A. Shutemov <>
Cc: Daniel Gruss <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
1 file changed