linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org, Jann Horn <jannh@google.com>,
	Matthew Wilcox <willy@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ben Hutchings <ben.hutchings@codethink.co.uk>
Subject: Re: [PATCH 4.9 57/83] mm: prevent get_user_pages() from overflowing page refcount
Date: Wed, 31 Jul 2019 17:14:16 +0200	[thread overview]
Message-ID: <6650323f-dbc9-f069-000b-f6b0f941a065@suse.cz> (raw)
In-Reply-To: <20190609164132.774263938@linuxfoundation.org>

On 6/9/19 6:42 PM, Greg Kroah-Hartman wrote:
> From: Linus Torvalds <torvalds@linux-foundation.org>
> 
> 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 <jannh@google.com>
> Acked-by: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> [bwh: Backported to 4.9:
>  - Add the "err" variable in follow_hugetlb_page()
>  - Adjust context]
> Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  mm/gup.c     |   45 ++++++++++++++++++++++++++++++++++-----------
>  mm/hugetlb.c |   16 +++++++++++++++-
>  2 files changed, 49 insertions(+), 12 deletions(-)
> 

...

> @@ -1231,6 +1240,20 @@ struct page *get_dump_page(unsigned long
>   */
>  #ifdef CONFIG_HAVE_GENERIC_RCU_GUP
>  
> +/*
> + * Return the compund head page with ref appropriately incremented,
> + * or NULL if that failed.
> + */
> +static inline struct page *try_get_compound_head(struct page *page, int refs)
> +{
> +	struct page *head = compound_head(page);
> +	if (WARN_ON_ONCE(page_ref_count(head) < 0))
> +		return NULL;
> +	if (unlikely(!page_cache_add_speculative(head, refs)))
> +		return NULL;
> +	return head;
> +}
> +
>  #ifdef __HAVE_ARCH_PTE_SPECIAL
>  static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
>  			 int write, struct page **pages, int *nr)
> @@ -1263,9 +1286,9 @@ static int gup_pte_range(pmd_t pmd, unsi
>  
>  		VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
>  		page = pte_page(pte);
> -		head = compound_head(page);
>  
> -		if (!page_cache_get_speculative(head))
> +		head = try_get_compound_head(page, 1);

BTW, several arches in 4.9, including x86, have arch-specific fast gup
implementation, which is not touched by this backport. Didn't check if
Jann's exploit ends up using the fast on non-fast one, though.

  reply	other threads:[~2019-07-31 15:33 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-09 16:41 [PATCH 4.9 00/83] 4.9.181-stable review Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 01/83] ipv6: Consider sk_bound_dev_if when binding a raw socket to an address Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 02/83] llc: fix skb leak in llc_build_and_send_ui_pkt() Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 03/83] net: fec: fix the clk mismatch in failed_reset path Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 04/83] net-gro: fix use-after-free read in napi_gro_frags() Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 05/83] net: stmmac: fix reset gpio free missing Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 06/83] usbnet: fix kernel crash after disconnect Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 07/83] tipc: Avoid copying bytes beyond the supplied data Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 08/83] bnxt_en: Fix aggregation buffer leak under OOM condition Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 09/83] ipv4/igmp: fix another memory leak in igmpv3_del_delrec() Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 10/83] ipv4/igmp: fix build error if !CONFIG_IP_MULTICAST Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 11/83] net: dsa: mv88e6xxx: fix handling of upper half of STATS_TYPE_PORT Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 12/83] net: mvneta: Fix err code path of probe Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 13/83] net: mvpp2: fix bad MVPP2_TXQ_SCHED_TOKEN_CNTR_REG queue value Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 14/83] crypto: vmx - ghash: do nosimd fallback manually Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 15/83] xen/pciback: Dont disable PCI_COMMAND on PCI device reset Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 16/83] Revert "tipc: fix modprobe tipc failed after switch order of device registration" Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 17/83] tipc: fix modprobe tipc failed after switch order of device registration Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 18/83] sparc64: Fix regression in non-hypervisor TLB flush xcall Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 19/83] include/linux/bitops.h: sanitize rotate primitives Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 20/83] xhci: update bounce buffer with correct sg num Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 21/83] xhci: Use %zu for printing size_t type Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 22/83] xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic() Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 23/83] usb: xhci: avoid null pointer deref when bos field is NULL Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 24/83] usbip: usbip_host: fix BUG: sleeping function called from invalid context Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 25/83] usbip: usbip_host: fix stub_dev lock context imbalance regression Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 26/83] USB: Fix slab-out-of-bounds write in usb_get_bos_descriptor Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 27/83] USB: sisusbvga: fix oops in error path of sisusb_probe Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 28/83] USB: Add LPM quirk for Surface Dock GigE adapter Greg Kroah-Hartman
2019-06-09 16:41 ` [PATCH 4.9 29/83] USB: rio500: refuse more than one device at a time Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 30/83] USB: rio500: fix memory leak in close after disconnect Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 31/83] media: usb: siano: Fix general protection fault in smsusb Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 32/83] media: usb: siano: Fix false-positive "uninitialized variable" warning Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 33/83] media: smsusb: better handle optional alignment Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 34/83] scsi: zfcp: fix missing zfcp_port reference put on -EBUSY from port_remove Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 35/83] scsi: zfcp: fix to prevent port_remove with pure auto scan LUNs (only sdevs) Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 36/83] Btrfs: fix race updating log root item during fsync Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 37/83] powerpc/perf: Fix MMCRA corruption by bhrb_filter Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 38/83] ALSA: hda/realtek - Set default power save node to 0 Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 39/83] drm/nouveau/i2c: Disable i2c bus access after ->fini() Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 40/83] tty: serial: msm_serial: Fix XON/XOFF Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 41/83] tty: max310x: Fix external crystal register setup Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 42/83] memcg: make it work on sparse non-0-node systems Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 43/83] kernel/signal.c: trace_signal_deliver when signal_group_exit Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 44/83] docs: Fix conf.py for Sphinx 2.0 Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 45/83] staging: vc04_services: prevent integer overflow in create_pagelist() Greg Kroah-Hartman
2019-06-19 16:02   ` Martin Weinelt
2019-06-19 17:13     ` Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 46/83] CIFS: cifs_read_allocate_pages: dont iterate through whole page array on ENOMEM Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 47/83] gcc-plugins: Fix build failures under Darwin host Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 48/83] drm/vmwgfx: Dont send drm sysfs hotplug events on initial master set Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 49/83] brcmfmac: add length checks in scheduled scan result handler Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 50/83] brcmfmac: assure SSID length from firmware is limited Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 51/83] brcmfmac: add subtype check for event handling in data path Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 52/83] binder: Replace "%p" with "%pK" for stable Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 53/83] binder: replace "%p" with "%pK" Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 54/83] fs: prevent page refcount overflow in pipe_buf_get Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 55/83] mm, gup: remove broken VM_BUG_ON_PAGE compound check for hugepages Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 56/83] mm, gup: ensure real head page is ref-counted when using hugepages Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 57/83] mm: prevent get_user_pages() from overflowing page refcount Greg Kroah-Hartman
2019-07-31 15:14   ` Vlastimil Babka [this message]
2019-06-09 16:42 ` [PATCH 4.9 58/83] mm: make page ref count overflow check tighter and more explicit Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 59/83] Revert "x86/build: Move _etext to actual end of .text" Greg Kroah-Hartman
2019-06-10 11:57   ` Willy Tarreau
2019-06-09 16:42 ` [PATCH 4.9 60/83] efi/libstub: Unify command line param parsing Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 61/83] media: uvcvideo: Fix uvc_alloc_entity() allocation alignment Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 62/83] ethtool: fix potential userspace buffer overflow Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 63/83] neighbor: Call __ipv4_neigh_lookup_noref in neigh_xmit Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 64/83] net/mlx4_en: ethtool, Remove unsupported SFP EEPROM high pages query Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 65/83] net: rds: fix memory leak in rds_ib_flush_mr_pool Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 66/83] pktgen: do not sleep with the thread lock held Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 67/83] ipv6: fix EFAULT on sendto with icmpv6 and hdrincl Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 68/83] ipv6: use READ_ONCE() for inet->hdrincl as in ipv4 Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 69/83] Revert "fib_rules: fix error in backport of e9919a24d302 ("fib_rules: return 0...")" Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 70/83] Revert "fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied" Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 71/83] rcu: locking and unlocking need to always be at least barriers Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 72/83] parisc: Use implicit space register selection for loading the coherence index of I/O pdirs Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 73/83] fuse: fallocate: fix return with locked inode Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 74/83] x86/power: Fix nosmt vs hibernation triple fault during resume Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 75/83] MIPS: pistachio: Build uImage.gz by default Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 76/83] Revert "MIPS: perf: ath79: Fix perfcount IRQ assignment" Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 77/83] genwqe: Prevent an integer overflow in the ioctl Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 78/83] drm/gma500/cdv: Check vbt config bits when detecting lvds panels Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 79/83] drm/radeon: prefer lower reference dividers Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 80/83] drm/i915: Fix I915_EXEC_RING_MASK Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 81/83] TTY: serial_core, add ->install Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 82/83] fs: stream_open - opener for stream-like files so that read and write can run simultaneously without deadlock Greg Kroah-Hartman
2019-06-09 16:42 ` [PATCH 4.9 83/83] fuse: Add FOPEN_STREAM to use stream_open() Greg Kroah-Hartman
2019-06-09 22:10 ` [PATCH 4.9 00/83] 4.9.181-stable review kernelci.org bot
2019-06-10  6:38 ` Naresh Kamboju
2019-06-10  8:50 ` Jon Hunter
2019-06-10 14:42 ` Guenter Roeck
2019-06-10 21:49 ` shuah

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=6650323f-dbc9-f069-000b-f6b0f941a065@suse.cz \
    --to=vbabka@suse.cz \
    --cc=ben.hutchings@codethink.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --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;
as well as URLs for NNTP newsgroup(s).