mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	kernel-team@lists.ubuntu.com
Cc: Dan Aloni <alonid@stratoscale.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Denys Vlasenko <vda.linux@googlemail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Kamal Mostafa <kamal@canonical.com>
Subject: [PATCH 090/104] fs/binfmt_elf.c: prevent a coredump with a large vm_map_count from Oopsing
Date: Thu, 10 Oct 2013 08:42:18 -0700	[thread overview]
Message-ID: <1381419752-29733-91-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1381419752-29733-1-git-send-email-kamal@canonical.com>

3.8.13.11 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: Dan Aloni <alonid@stratoscale.com>

commit 72023656961b8c81a168a7a6762d589339d0d7ec upstream.

A high setting of max_map_count, and a process core-dumping with a large
enough vm_map_count could result in an NT_FILE note not being written,
and the kernel crashing immediately later because it has assumed
otherwise.

Reproduction of the oops-causing bug described here:

    https://lkml.org/lkml/2013/8/30/50

Rge ussue originated in commit 2aa362c49c31 ("coredump: extend core dump
note section to contain file names of mapped file") from Oct 4, 2012.

This patch make that section optional in that case.  fill_files_note()
should signify the error, and also let the info struct in
elf_core_dump() be zero-initialized so that we can check for the
optionally written note.

[akpm@linux-foundation.org: avoid abusing E2BIG, remove a couple of not-really-needed local variables]
[akpm@linux-foundation.org: fix sparse warning]
Signed-off-by: Dan Aloni <alonid@stratoscale.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Denys Vlasenko <vda.linux@googlemail.com>
Reported-by: Martin MOKREJS <mmokrejs@gmail.com>
Tested-by: Martin MOKREJS <mmokrejs@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 fs/binfmt_elf.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 5843a47..0950e59 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1403,7 +1403,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
  *   long file_ofs
  * followed by COUNT filenames in ASCII: "FILE1" NUL "FILE2" NUL...
  */
-static void fill_files_note(struct memelfnote *note)
+static int fill_files_note(struct memelfnote *note)
 {
 	struct vm_area_struct *vma;
 	unsigned count, size, names_ofs, remaining, n;
@@ -1418,11 +1418,11 @@ static void fill_files_note(struct memelfnote *note)
 	names_ofs = (2 + 3 * count) * sizeof(data[0]);
  alloc:
 	if (size >= MAX_FILE_NOTE_SIZE) /* paranoia check */
-		goto err;
+		return -EINVAL;
 	size = round_up(size, PAGE_SIZE);
 	data = vmalloc(size);
 	if (!data)
-		goto err;
+		return -ENOMEM;
 
 	start_end_ofs = data + 2;
 	name_base = name_curpos = ((char *)data) + names_ofs;
@@ -1475,7 +1475,7 @@ static void fill_files_note(struct memelfnote *note)
 
 	size = name_curpos - (char *)data;
 	fill_note(note, "CORE", NT_FILE, size, data);
- err: ;
+	return 0;
 }
 
 #ifdef CORE_DUMP_USE_REGSET
@@ -1676,8 +1676,8 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 	fill_auxv_note(&info->auxv, current->mm);
 	info->size += notesize(&info->auxv);
 
-	fill_files_note(&info->files);
-	info->size += notesize(&info->files);
+	if (fill_files_note(&info->files) == 0)
+		info->size += notesize(&info->files);
 
 	return 1;
 }
@@ -1709,7 +1709,8 @@ static int write_note_info(struct elf_note_info *info,
 			return 0;
 		if (first && !writenote(&info->auxv, file, foffset))
 			return 0;
-		if (first && !writenote(&info->files, file, foffset))
+		if (first && info->files.data &&
+				!writenote(&info->files, file, foffset))
 			return 0;
 
 		for (i = 1; i < info->thread_notes; ++i)
@@ -1796,6 +1797,7 @@ static int elf_dump_thread_status(long signr, struct elf_thread_status *t)
 
 struct elf_note_info {
 	struct memelfnote *notes;
+	struct memelfnote *notes_files;
 	struct elf_prstatus *prstatus;	/* NT_PRSTATUS */
 	struct elf_prpsinfo *psinfo;	/* NT_PRPSINFO */
 	struct list_head thread_list;
@@ -1886,9 +1888,12 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 
 	fill_siginfo_note(info->notes + 2, &info->csigdata, siginfo);
 	fill_auxv_note(info->notes + 3, current->mm);
-	fill_files_note(info->notes + 4);
+	info->numnote = 4;
 
-	info->numnote = 5;
+	if (fill_files_note(info->notes + info->numnote) == 0) {
+		info->notes_files = info->notes + info->numnote;
+		info->numnote++;
+	}
 
 	/* Try to dump the FPU. */
 	info->prstatus->pr_fpvalid = elf_core_copy_task_fpregs(current, regs,
@@ -1950,8 +1955,9 @@ static void free_note_info(struct elf_note_info *info)
 		kfree(list_entry(tmp, struct elf_thread_status, list));
 	}
 
-	/* Free data allocated by fill_files_note(): */
-	vfree(info->notes[4].data);
+	/* Free data possibly allocated by fill_files_note(): */
+	if (info->notes_files)
+		vfree(info->notes_files->data);
 
 	kfree(info->prstatus);
 	kfree(info->psinfo);
@@ -2034,7 +2040,7 @@ static int elf_core_dump(struct coredump_params *cprm)
 	struct vm_area_struct *vma, *gate_vma;
 	struct elfhdr *elf = NULL;
 	loff_t offset = 0, dataoff, foffset;
-	struct elf_note_info info;
+	struct elf_note_info info = { };
 	struct elf_phdr *phdr4note = NULL;
 	struct elf_shdr *shdr4extnum = NULL;
 	Elf_Half e_phnum;
-- 
1.8.1.2


  parent reply	other threads:[~2013-10-10 15:46 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-10 15:40 [ 3.8.y.z extended stable ] Linux 3.8.13.11 stable review Kamal Mostafa
2013-10-10 15:40 ` [PATCH 001/104] htb: fix sign extension bug Kamal Mostafa
2013-10-10 15:40 ` [PATCH 002/104] net: avoid to hang up on sending due to sysctl configuration overflow Kamal Mostafa
2013-10-10 15:40 ` [PATCH 003/104] net: check net.core.somaxconn sysctl values Kamal Mostafa
2013-10-10 15:40 ` [PATCH 004/104] macvlan: validate flags Kamal Mostafa
2013-10-10 15:40 ` [PATCH 005/104] neighbour: populate neigh_parms on alloc before calling ndo_neigh_setup Kamal Mostafa
2013-10-10 15:40 ` [PATCH 006/104] bonding: modify only neigh_parms owned by us Kamal Mostafa
2013-10-10 15:40 ` [PATCH 007/104] fib_trie: remove potential out of bound access Kamal Mostafa
2013-10-10 15:40 ` [PATCH 008/104] bridge: don't try to update timers in case of broken MLD queries Kamal Mostafa
2013-10-10 15:40 ` [PATCH 009/104] tcp: cubic: fix overflow error in bictcp_update() Kamal Mostafa
2013-10-10 15:40 ` [PATCH 010/104] tcp: cubic: fix bug in bictcp_acked() Kamal Mostafa
2013-10-10 15:40 ` [PATCH 011/104] ipv6: don't stop backtracking in fib6_lookup_1 if subtree does not match Kamal Mostafa
2013-10-10 15:41 ` [PATCH 012/104] 8139cp: Fix skb leak in rx_status_loop failure path Kamal Mostafa
2013-10-10 15:41 ` [PATCH 013/104] tun: signedness bug in tun_get_user() Kamal Mostafa
2013-10-10 15:41 ` [PATCH 014/104] ipv6: remove max_addresses check from ipv6_create_tempaddr Kamal Mostafa
2013-10-10 15:41 ` [PATCH 015/104] ipv6: Store Router Alert option in IP6CB directly Kamal Mostafa
2013-10-10 15:41 ` [PATCH 016/104] ipv6: drop packets with multiple fragmentation headers Kamal Mostafa
2013-10-10 15:41 ` [PATCH 017/104] tcp: set timestamps for restored skb-s Kamal Mostafa
2013-10-10 15:41 ` [PATCH 018/104] net: usb: Add HP hs2434 device to ZLP exception table Kamal Mostafa
2013-10-10 15:41 ` [PATCH 019/104] tcp: initialize rcv_tstamp for restored sockets Kamal Mostafa
2013-10-10 15:41 ` [PATCH 020/104] ipv4: sendto/hdrincl: don't use destination address found in header Kamal Mostafa
2013-10-10 15:41 ` [PATCH 021/104] tcp: tcp_make_synack() should use sock_wmalloc Kamal Mostafa
2013-10-10 15:41 ` [PATCH 022/104] tipc: set sk_err correctly when connection fails Kamal Mostafa
2013-10-10 15:41 ` [PATCH 023/104] net: bridge: convert MLDv2 Query MRC into msecs_to_jiffies for max_delay Kamal Mostafa
2013-10-10 15:41 ` [PATCH 024/104] ICMPv6: treat dest unreachable codes 5 and 6 as EACCES, not EPROTO Kamal Mostafa
2013-10-10 15:41 ` [PATCH 025/104] tg3: Don't turn off led on 5719 serdes port 0 Kamal Mostafa
2013-10-10 15:41 ` [PATCH 026/104] vhost_net: poll vhost queue after marking DMA is done Kamal Mostafa
2013-10-10 15:41 ` [PATCH 027/104] net: ipv6: tcp: fix potential use after free in tcp_v6_do_rcv Kamal Mostafa
2013-10-10 15:41 ` [PATCH 028/104] drm/radeon/si: Add support for CP DMA to CS checker for compute v2 Kamal Mostafa
2013-10-10 15:41 ` [PATCH 029/104] sfc: Fix efx_rx_buf_offset() for recycled pages Kamal Mostafa
2013-10-10 15:41 ` [PATCH 030/104] cfq: explicitly use 64bit divide operation for 64bit arguments Kamal Mostafa
2013-10-10 15:41 ` [PATCH 031/104] cpqarray: fix info leak in ida_locked_ioctl() Kamal Mostafa
2013-10-10 15:41 ` [PATCH 032/104] cciss: fix info leak in cciss_ioctl32_passthru() Kamal Mostafa
2013-10-10 15:41 ` [PATCH 033/104] drm/radeon/atom: workaround vbios bug in transmitter table on rs880 (v2) Kamal Mostafa
2013-10-10 15:41 ` [PATCH 034/104] drm/ast: fix the ast open key function Kamal Mostafa
2013-10-10 15:41 ` [PATCH 035/104] sched/fair: Fix small race where child->se.parent,cfs_rq might point to invalid ones Kamal Mostafa
2013-10-10 15:41 ` [PATCH 036/104] tg3: Expand led off fix to include 5720 Kamal Mostafa
2013-10-10 15:41 ` [PATCH 037/104] HID: provide a helper for validating hid reports Kamal Mostafa
2013-10-10 15:41 ` [PATCH 038/104] HID: zeroplus: validate output report details Kamal Mostafa
2013-10-10 15:41 ` [PATCH 039/104] HID: LG: validate HID " Kamal Mostafa
2013-10-10 15:41 ` [PATCH 040/104] HID: lenovo-tpkbd: validate " Kamal Mostafa
2013-10-10 15:41 ` [PATCH 041/104] HID: validate feature and input " Kamal Mostafa
2013-10-10 15:41 ` [PATCH 042/104] HID: logitech-dj: validate output " Kamal Mostafa
2013-10-10 15:41 ` [PATCH 043/104] HID: multitouch: validate indexes details Kamal Mostafa
2013-10-10 15:41 ` [PATCH 044/104] HID: lenovo-tpkbd: fix leak if tpkbd_probe_tp fails Kamal Mostafa
2013-10-10 15:41 ` [PATCH 045/104] drm/radeon: fix panel scaling with eDP and LVDS bridges Kamal Mostafa
2013-10-10 15:41 ` [PATCH 046/104] cifs: fix filp leak in cifs_atomic_open() Kamal Mostafa
2013-10-10 15:41 ` [PATCH 047/104] net: usb: cdc_ether: Use wwan interface for Telit modules Kamal Mostafa
2013-10-10 15:41 ` [PATCH 048/104] usb: gadget: fix a bug and a WARN_ON in dummy-hcd Kamal Mostafa
2013-10-10 15:41 ` [PATCH 049/104] drm/i915: do not update cursor in crtc mode set Kamal Mostafa
2013-10-10 15:41 ` [PATCH 050/104] drm/i915: Don't enable the cursor on a disable pipe Kamal Mostafa
2013-10-10 15:41 ` [PATCH 051/104] drm/ttm: fix the tt_populated check in ttm_tt_destroy() Kamal Mostafa
2013-10-10 15:41 ` [PATCH 052/104] PCI / ACPI / PM: Clear pme_poll for devices in D3cold on wakeup Kamal Mostafa
2013-10-10 15:41 ` [PATCH 053/104] Smack: Fix the bug smackcipso can't set CIPSO correctly Kamal Mostafa
2013-10-10 15:41 ` [PATCH 054/104] serial: pch_uart: fix tty-kref leak in dma-rx path Kamal Mostafa
2013-10-10 15:41 ` [PATCH 055/104] x86, efi: Don't map Boot Services on i386 Kamal Mostafa
2013-10-10 15:41 ` [PATCH 056/104] ALSA: compress: Fix compress device unregister Kamal Mostafa
2013-10-10 15:41 ` [PATCH 057/104] dm snapshot: workaround for a false positive lockdep warning Kamal Mostafa
2013-10-10 15:41 ` [PATCH 058/104] dm-snapshot: fix performance degradation due to small hash size Kamal Mostafa
2013-10-10 15:41 ` [PATCH 059/104] drm/radeon: Make r100_cp_ring_info() and radeon_ring_gfx() safe (v2) Kamal Mostafa
2013-10-10 15:41 ` [PATCH 060/104] ARM: 7837/3: fix Thumb-2 bug in AES assembler code Kamal Mostafa
2013-10-10 15:41 ` [PATCH 061/104] x86/reboot: Add quirk to make Dell C6100 use reboot=pci automatically Kamal Mostafa
2013-10-10 15:41 ` [PATCH 062/104] drm/radeon: disable tests/benchmarks if accel is disabled Kamal Mostafa
2013-10-10 15:41 ` [PATCH 063/104] xhci: Fix oops happening after address device timeout Kamal Mostafa
2013-10-10 15:41 ` [PATCH 064/104] xhci: Ensure a command structure points to the correct trb on the command ring Kamal Mostafa
2013-10-10 15:41 ` [PATCH 065/104] drm/i915/dp: increase i2c-over-aux retry interval on AUX DEFER Kamal Mostafa
2013-10-10 15:41 ` [PATCH 066/104] staging: vt6656: [BUG] main_usb.c oops on device_close move flag earlier Kamal Mostafa
2013-10-10 15:41 ` [PATCH 067/104] staging: vt6656: [BUG] iwctl_siwencodeext return if device not open Kamal Mostafa
2013-10-10 15:41 ` [PATCH 068/104] USB: UHCI: accept very late isochronous URBs Kamal Mostafa
2013-10-10 15:41 ` [PATCH 069/104] USB: OHCI: " Kamal Mostafa
2013-10-10 15:41 ` [PATCH 070/104] USB: fix PM config symbol in uhci-hcd, ehci-hcd, and xhci-hcd Kamal Mostafa
2013-10-10 15:41 ` [PATCH 071/104] usb/core/devio.c: Don't reject control message to endpoint with wrong direction bit Kamal Mostafa
2013-10-10 15:42 ` [PATCH 072/104] hwmon: (applesmc) Check key count before proceeding Kamal Mostafa
2013-10-10 15:42 ` [PATCH 073/104] fsl/usb: Resolve PHY_CLK_VLD instability issue for ULPI phy Kamal Mostafa
2013-10-10 15:42 ` [PATCH 074/104] driver core : Fix use after free of dev->parent in device_shutdown Kamal Mostafa
2013-10-10 15:42 ` [PATCH 075/104] USB: Fix breakage in ffs_fs_mount() Kamal Mostafa
2013-10-10 15:42 ` [PATCH 076/104] usb: dwc3: pci: add support for BayTrail Kamal Mostafa
2013-10-10 15:42 ` [PATCH 077/104] usb: dwc3: add support for Merrifield Kamal Mostafa
2013-10-10 15:42 ` [PATCH 078/104] ASoC: max98095: a couple array underflows Kamal Mostafa
2013-10-10 15:42 ` [PATCH 079/104] ASoC: ab8500-codec: info leak in anc_status_control_put() Kamal Mostafa
2013-10-10 15:42 ` [PATCH 080/104] ASoC: 88pm860x: array overflow in snd_soc_put_volsw_2r_st() Kamal Mostafa
2013-10-10 15:42 ` [PATCH 081/104] Bluetooth: Add a new PID/VID 0cf3/e005 for AR3012 Kamal Mostafa
2013-10-10 15:42 ` [PATCH 082/104] Bluetooth: Fix security level for peripheral role Kamal Mostafa
2013-10-10 15:42 ` [PATCH 083/104] Bluetooth: Fix encryption key size " Kamal Mostafa
2013-10-10 15:42 ` [PATCH 084/104] Bluetooth: Add support for BCM20702A0 [0b05, 17cb] Kamal Mostafa
2013-10-10 15:42 ` [PATCH 085/104] Bluetooth: Introduce a new HCI_RFKILLED flag Kamal Mostafa
2013-10-10 15:42 ` [PATCH 086/104] rtlwifi: Align private space in rtl_priv struct Kamal Mostafa
2013-10-10 15:42 ` [PATCH 087/104] p54usb: add USB ID for Corega WLUSB2GTST USB adapter Kamal Mostafa
2013-10-10 15:42 ` [PATCH 088/104] mwifiex: fix hang issue for USB chipsets Kamal Mostafa
2013-10-10 15:42 ` [PATCH 089/104] mwifiex: fix NULL pointer dereference in usb suspend handler Kamal Mostafa
2013-10-10 15:42 ` Kamal Mostafa [this message]
2013-10-10 15:42 ` [PATCH 091/104] nilfs2: fix issue with race condition of competition between segments for dirty blocks Kamal Mostafa
2013-10-10 15:42 ` [PATCH 092/104] mm: avoid reinserting isolated balloon pages into LRU lists Kamal Mostafa
2013-10-10 15:42 ` [PATCH 093/104] USB: serial: option: Ignore card reader interface on Huawei E1750 Kamal Mostafa
2013-10-10 15:42 ` [PATCH 094/104] gpio/omap: maintain GPIO and IRQ usage separately Kamal Mostafa
2013-10-10 15:42 ` [PATCH 095/104] gpio/omap: auto-setup a GPIO when used as an IRQ Kamal Mostafa
2013-10-10 15:42 ` [PATCH 096/104] ib_srpt: Destroy cm_id before destroying QP Kamal Mostafa
2013-10-10 15:42 ` [PATCH 097/104] powerpc: Fix parameter clobber in csum_partial_copy_generic() Kamal Mostafa
2013-10-10 15:42 ` [PATCH 098/104] powerpc: Restore registers on error exit from csum_partial_copy_generic() Kamal Mostafa
2013-10-10 15:42 ` [PATCH 099/104] powerpc/sysfs: Disable writing to PURR in guest mode Kamal Mostafa
2013-10-10 15:42 ` [PATCH 100/104] powerpc/iommu: Use GFP_KERNEL instead of GFP_ATOMIC in iommu_init_table() Kamal Mostafa
2013-10-10 15:42 ` [PATCH 101/104] powerpc/vio: Fix modalias_show return values Kamal Mostafa
2013-10-10 15:42 ` [PATCH 102/104] ib_srpt: always set response for task management Kamal Mostafa
2013-10-10 15:42 ` [PATCH 103/104] xen/hvc: allow xenboot console to be used again Kamal Mostafa
2013-10-10 15:42 ` [PATCH 104/104] net: Update the sysctl permissions handler to test effective uid/gid Kamal Mostafa
2013-10-10 17:37 ` [ 3.8.y.z extended stable ] Linux 3.8.13.11 stable review Bjorn Helgaas
2013-10-18  1:30   ` Ben Hutchings
2013-10-18 15:41     ` Bjorn Helgaas
2013-10-18 15:56       ` Luis Henriques

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=1381419752-29733-91-git-send-email-kamal@canonical.com \
    --to=kamal@canonical.com \
    --cc=akpm@linux-foundation.org \
    --cc=alonid@stratoscale.com \
    --cc=kernel-team@lists.ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vda.linux@googlemail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®