FROMGIT: mm: prevent get_user_pages() from overflowing page refcount

commit 8fde12ca79aff9b5ba951fce1a2641901b8d8e64 upstream.

If the page refcount wraps around past zero, it will be freed while
there are still four billion references to it.  One of the possible
avenues for an attacker to try to make this happen is by doing direct IO
on a page multiple times.  This patch makes get_user_pages() refuse to
take a new page reference if there are already more than two billion
references to the page.

Reported-by: Jann Horn <[email protected]>
Acked-by: Matthew Wilcox <[email protected]>
Cc: [email protected]
Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
(cherry picked from commit 04198de24771f6aaf6374979db64403101d809df
 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux-4.14.y)

BUG=chromium:958318
TEST=trybots

Change-Id: Ie358cdcd735d62934857eb80e9528ceeffd4f311
Signed-off-by: Guenter Roeck <[email protected]>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1599254
Reviewed-by: Sean Paul <[email protected]>
2 files changed