linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Randy Dunlap <rdunlap@infradead.org>,
	Matthew Wilcox <willy@infradead.org>,
	Kees Cook <keescook@chromium.org>
Subject: [PATCH 4.19 031/114] usercopy: Avoid HIGHMEM pfn warning
Date: Thu, 10 Oct 2019 10:35:38 +0200	[thread overview]
Message-ID: <20191010083600.106313568@linuxfoundation.org> (raw)
In-Reply-To: <20191010083544.711104709@linuxfoundation.org>

From: Kees Cook <keescook@chromium.org>

commit 314eed30ede02fa925990f535652254b5bad6b65 upstream.

When running on a system with >512MB RAM with a 32-bit kernel built with:

	CONFIG_DEBUG_VIRTUAL=y
	CONFIG_HIGHMEM=y
	CONFIG_HARDENED_USERCOPY=y

all execve()s will fail due to argv copying into kmap()ed pages, and on
usercopy checking the calls ultimately of virt_to_page() will be looking
for "bad" kmap (highmem) pointers due to CONFIG_DEBUG_VIRTUAL=y:

 ------------[ cut here ]------------
 kernel BUG at ../arch/x86/mm/physaddr.c:83!
 invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
 CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.3.0-rc8 #6
 Hardware name: Dell Inc. Inspiron 1318/0C236D, BIOS A04 01/15/2009
 EIP: __phys_addr+0xaf/0x100
 ...
 Call Trace:
  __check_object_size+0xaf/0x3c0
  ? __might_sleep+0x80/0xa0
  copy_strings+0x1c2/0x370
  copy_strings_kernel+0x2b/0x40
  __do_execve_file+0x4ca/0x810
  ? kmem_cache_alloc+0x1c7/0x370
  do_execve+0x1b/0x20
  ...

The check is from arch/x86/mm/physaddr.c:

	VIRTUAL_BUG_ON((phys_addr >> PAGE_SHIFT) > max_low_pfn);

Due to the kmap() in fs/exec.c:

		kaddr = kmap(kmapped_page);
	...
	if (copy_from_user(kaddr+offset, str, bytes_to_copy)) ...

Now we can fetch the correct page to avoid the pfn check. In both cases,
hardened usercopy will need to walk the page-span checker (if enabled)
to do sanity checking.

Reported-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Fixes: f5509cc18daa ("mm: Hardened usercopy")
Cc: Matthew Wilcox <willy@infradead.org>
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Link: https://lore.kernel.org/r/201909171056.7F2FFD17@keescook
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 mm/usercopy.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -15,6 +15,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/mm.h>
+#include <linux/highmem.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
 #include <linux/sched/task.h>
@@ -231,7 +232,12 @@ static inline void check_heap_object(con
 	if (!virt_addr_valid(ptr))
 		return;
 
-	page = virt_to_head_page(ptr);
+	/*
+	 * When CONFIG_HIGHMEM=y, kmap_to_page() will give either the
+	 * highmem page or fallback to virt_to_page(). The following
+	 * is effectively a highmem-aware virt_to_head_page().
+	 */
+	page = compound_head(kmap_to_page((void *)ptr));
 
 	if (PageSlab(page)) {
 		/* Check slab allocator for flags and size. */



  parent reply	other threads:[~2019-10-10  8:45 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10  8:35 [PATCH 4.19 000/114] 4.19.79-stable review Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 001/114] s390/process: avoid potential reading of freed stack Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 002/114] KVM: s390: Test for bad access register and size at the start of S390_MEM_OP Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 003/114] s390/topology: avoid firing events before kobjs are created Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 004/114] s390/cio: exclude subchannels with no parent from pseudo check Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 005/114] KVM: PPC: Book3S HV: Fix race in re-enabling XIVE escalation interrupts Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 006/114] KVM: PPC: Book3S HV: Check for MMU ready on piggybacked virtual cores Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 007/114] KVM: PPC: Book3S HV: Dont lose pending doorbell request on migration on P9 Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 008/114] KVM: X86: Fix userspace set invalid CR4 Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 009/114] KVM: nVMX: handle page fault in vmread fix Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 010/114] nbd: fix max number of supported devs Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 011/114] PM / devfreq: tegra: Fix kHz to Hz conversion Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 012/114] ASoC: Define a set of DAPM pre/post-up events Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 013/114] ASoC: sgtl5000: Improve VAG power and mute control Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 014/114] powerpc/mce: Fix MCE handling for huge pages Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 015/114] powerpc/mce: Schedule work from irq_work Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 016/114] powerpc/powernv: Restrict OPAL symbol map to only be readable by root Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 017/114] powerpc/powernv/ioda: Fix race in TCE level allocation Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 018/114] powerpc/book3s64/mm: Dont do tlbie fixup for some hardware revisions Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 019/114] can: mcp251x: mcp251x_hw_reset(): allow more time after a reset Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 020/114] tools lib traceevent: Fix "robust" test of do_generate_dynamic_list_file Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 021/114] crypto: qat - Silence smp_processor_id() warning Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 022/114] crypto: skcipher - Unmap pages after an external error Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 023/114] crypto: cavium/zip - Add missing single_release() Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 024/114] crypto: caam - fix concurrency issue in givencrypt descriptor Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 025/114] crypto: ccree - account for TEE not ready to report Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 026/114] crypto: ccree - use the full crypt length value Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 027/114] MIPS: Treat Loongson Extensions as ASEs Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 028/114] power: supply: sbs-battery: use correct flags field Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 029/114] power: supply: sbs-battery: only return health when battery present Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 030/114] tracing: Make sure variable reference alias has correct var_ref_idx Greg Kroah-Hartman
2019-10-10  8:35 ` Greg Kroah-Hartman [this message]
2019-10-10  8:35 ` [PATCH 4.19 032/114] timer: Read jiffies once when forwarding base clk Greg Kroah-Hartman
2019-10-13 15:47   ` Pavel Machek
2019-10-10  8:35 ` [PATCH 4.19 033/114] PCI: vmd: Fix shadow offsets to reflect spec changes Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 034/114] PCI: Restore Resizable BAR size bits correctly for 1MB BARs Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 035/114] watchdog: imx2_wdt: fix min() calculation in imx2_wdt_set_timeout Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 036/114] perf stat: Fix a segmentation fault when using repeat forever Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 037/114] drm/omap: fix max fclk divider for omap36xx Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 038/114] drm/msm/dsi: Fix return value check for clk_get_parent Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 039/114] drm/nouveau/kms/nv50-: Dont create MSTMs for eDP connectors Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 040/114] drm/i915/gvt: update vgpu workload head pointer correctly Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 041/114] mmc: sdhci: improve ADMA error reporting Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 042/114] mmc: sdhci-of-esdhc: set DMA snooping based on DMA coherence Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 043/114] Revert "locking/pvqspinlock: Dont wait if vCPU is preempted" Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 044/114] xen/xenbus: fix self-deadlock after killing user process Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 045/114] ieee802154: atusb: fix use-after-free at disconnect Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 046/114] s390/cio: avoid calling strlen on null pointer Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 047/114] cfg80211: initialize on-stack chandefs Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 048/114] arm64: cpufeature: Detect SSBS and advertise to userspace Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 049/114] ima: always return negative code for error Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 050/114] ima: fix freeing ongoing ahash_request Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 051/114] fs: nfs: Fix possible null-pointer dereferences in encode_attrs() Greg Kroah-Hartman
2019-10-10  8:35 ` [PATCH 4.19 052/114] 9p: Transport error uninitialized Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 053/114] 9p: avoid attaching writeback_fid on mmap with type PRIVATE Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 054/114] xen/pci: reserve MCFG areas earlier Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 055/114] ceph: fix directories inode i_blkbits initialization Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 056/114] ceph: reconnect connection if session hang in opening state Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 057/114] watchdog: aspeed: Add support for AST2600 Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 058/114] netfilter: nf_tables: allow lookups in dynamic sets Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 059/114] drm/amdgpu: Fix KFD-related kernel oops on Hawaii Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 060/114] drm/amdgpu: Check for valid number of registers to read Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 061/114] pNFS: Ensure we do clear the return-on-close layout stateid on fatal errors Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 062/114] pwm: stm32-lp: Add check in case requested period cannot be achieved Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 063/114] x86/purgatory: Disable the stackleak GCC plugin for the purgatory Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 064/114] ntb: point to right memory window index Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 065/114] thermal: Fix use-after-free when unregistering thermal zone device Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 066/114] thermal_hwmon: Sanitize thermal_zone type Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 067/114] libnvdimm/region: Initialize bad block for volatile namespaces Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 068/114] fuse: fix memleak in cuse_channel_open Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 069/114] libnvdimm/nfit_test: Fix acpi_handle redefinition Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 070/114] sched/membarrier: Call sync_core only before usermode for same mm Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 071/114] sched/membarrier: Fix private expedited registration check Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 072/114] sched/core: Fix migration to invalid CPU in __set_cpus_allowed_ptr() Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 073/114] perf build: Add detection of java-11-openjdk-devel package Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 074/114] kernel/elfcore.c: include proper prototypes Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 075/114] perf unwind: Fix libunwind build failure on i386 systems Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 076/114] nfp: flower: fix memory leak in nfp_flower_spawn_vnic_reprs Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 077/114] drm/radeon: Bail earlier when radeon.cik_/si_support=0 is passed Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 078/114] KVM: PPC: Book3S HV: XIVE: Free escalation interrupts before disabling the VP Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 079/114] KVM: nVMX: Fix consistency check on injected exception error code Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 080/114] nbd: fix crash when the blksize is zero Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 081/114] powerpc/pseries: Fix cpu_hotplug_lock acquisition in resize_hpt() Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 082/114] powerpc/book3s64/radix: Rename CPU_FTR_P9_TLBIE_BUG feature flag Greg Kroah-Hartman
2019-10-11 11:21   ` Pavel Machek
2019-10-11 12:58     ` Greg Kroah-Hartman
2019-10-11 16:05       ` Sasha Levin
2019-10-10  8:36 ` [PATCH 4.19 083/114] tools lib traceevent: Do not free tep->cmdlines in add_new_comm() on failure Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 084/114] tick: broadcast-hrtimer: Fix a race in bc_set_next Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 086/114] perf stat: Reset previous counts on repeat with interval Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 087/114] drm/i915/userptr: Acquire the page lock around set_page_dirty() Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 088/114] riscv: Avoid interrupts being erroneously enabled in handle_exception() Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 089/114] arm64: ssbd: Add support for PSTATE.SSBS rather than trapping to EL3 Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 090/114] KVM: arm64: Set SCTLR_EL2.DSSBS if SSBD is forcefully disabled and !vhe Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 091/114] arm64: docs: Document SSBS HWCAP Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 092/114] arm64: fix SSBS sanitization Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 093/114] arm64: Add sysfs vulnerability show for spectre-v1 Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 094/114] arm64: add sysfs vulnerability show for meltdown Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 095/114] arm64: enable generic CPU vulnerabilites support Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 096/114] arm64: Always enable ssb vulnerability detection Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 097/114] arm64: Provide a command line to disable spectre_v2 mitigation Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 098/114] arm64: Advertise mitigation of Spectre-v2, or lack thereof Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 099/114] arm64: Always enable spectre-v2 vulnerability detection Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 100/114] arm64: add sysfs vulnerability show for spectre-v2 Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 101/114] arm64: add sysfs vulnerability show for speculative store bypass Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 102/114] arm64: ssbs: Dont treat CPUs with SSBS as unaffected by SSB Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 103/114] arm64: Force SSBS on context switch Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 104/114] arm64: Use firmware to detect CPUs that are not affected by Spectre-v2 Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 105/114] arm64/speculation: Support mitigations= cmdline option Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 106/114] vfs: Fix EOVERFLOW testing in put_compat_statfs64 Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 107/114] coresight: etm4x: Use explicit barriers on enable/disable Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 108/114] staging: erofs: fix an error handling in erofs_readdir() Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 109/114] staging: erofs: some compressed cluster should be submitted for corrupted images Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 110/114] staging: erofs: add two missing erofs_workgroup_put " Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 111/114] staging: erofs: detect potential multiref due to " Greg Kroah-Hartman
2019-10-10  8:36 ` [PATCH 4.19 112/114] cfg80211: add and use strongly typed element iteration macros Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.19 113/114] cfg80211: Use const more consistently in for_each_element macros Greg Kroah-Hartman
2019-10-10  8:37 ` [PATCH 4.19 114/114] nl80211: validate beacon head Greg Kroah-Hartman
2019-10-10 14:41 ` [PATCH 4.19 000/114] 4.19.79-stable review kernelci.org bot
2019-10-10 17:04 ` Naresh Kamboju
2019-10-10 22:19 ` Guenter Roeck
2019-10-10 23:03 ` Didik Setiawan
2019-10-11  3:05 ` shuah
2019-10-11  8:33 ` Jon Hunter

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=20191010083600.106313568@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=stable@vger.kernel.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).