stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	alan@lxorguk.ukuu.org.uk, Kees Cook <keescook@chromium.org>,
	Michal Marek <mmarek@suse.cz>,
	Brad Spengler <spender@grsecurity.net>,
	PaX Team <pageexec@freemail.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [ 006/101] gen_init_cpio: avoid stack overflow when expanding
Date: Mon, 29 Oct 2012 14:34:19 -0700	[thread overview]
Message-ID: <20121029213240.856149674@linuxfoundation.org> (raw)
In-Reply-To: <20121029213240.128426598@linuxfoundation.org>

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

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

From: Kees Cook <keescook@chromium.org>

commit 20f1de659b77364d55d4e7fad2ef657e7730323f upstream.

Fix possible overflow of the buffer used for expanding environment
variables when building file list.

In the extremely unlikely case of an attacker having control over the
environment variables visible to gen_init_cpio, control over the
contents of the file gen_init_cpio parses, and gen_init_cpio was built
without compiler hardening, the attacker can gain arbitrary execution
control via a stack buffer overflow.

  $ cat usr/crash.list
  file foo ${BIG}${BIG}${BIG}${BIG}${BIG}${BIG} 0755 0 0
  $ BIG=$(perl -e 'print "A" x 4096;') ./usr/gen_init_cpio usr/crash.list
  *** buffer overflow detected ***: ./usr/gen_init_cpio terminated

This also replaces the space-indenting with tabs.

Patch based on existing fix extracted from grsecurity.

Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Brad Spengler <spender@grsecurity.net>
Cc: PaX Team <pageexec@freemail.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 usr/gen_init_cpio.c |   41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name,
 	int retval;
 	int rc = -1;
 	int namesize;
-	int i;
+	unsigned int i;
 
 	mode |= S_IFREG;
 
@@ -381,25 +381,28 @@ error:
 
 static char *cpio_replace_env(char *new_location)
 {
-       char expanded[PATH_MAX + 1];
-       char env_var[PATH_MAX + 1];
-       char *start;
-       char *end;
-
-       for (start = NULL; (start = strstr(new_location, "${")); ) {
-               end = strchr(start, '}');
-               if (start < end) {
-                       *env_var = *expanded = '\0';
-                       strncat(env_var, start + 2, end - start - 2);
-                       strncat(expanded, new_location, start - new_location);
-                       strncat(expanded, getenv(env_var), PATH_MAX);
-                       strncat(expanded, end + 1, PATH_MAX);
-                       strncpy(new_location, expanded, PATH_MAX);
-               } else
-                       break;
-       }
+	char expanded[PATH_MAX + 1];
+	char env_var[PATH_MAX + 1];
+	char *start;
+	char *end;
+
+	for (start = NULL; (start = strstr(new_location, "${")); ) {
+		end = strchr(start, '}');
+		if (start < end) {
+			*env_var = *expanded = '\0';
+			strncat(env_var, start + 2, end - start - 2);
+			strncat(expanded, new_location, start - new_location);
+			strncat(expanded, getenv(env_var),
+				PATH_MAX - strlen(expanded));
+			strncat(expanded, end + 1,
+				PATH_MAX - strlen(expanded));
+			strncpy(new_location, expanded, PATH_MAX);
+			new_location[PATH_MAX] = 0;
+		} else
+			break;
+	}
 
-       return new_location;
+	return new_location;
 }
 
 



  parent reply	other threads:[~2012-10-29 21:34 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-29 21:34 [ 000/101] 3.6.5-stable review Greg Kroah-Hartman
2012-10-29 21:34 ` [ 001/101] drm/radeon: add some new SI PCI ids Greg Kroah-Hartman
2012-10-29 21:34 ` [ 002/101] drm/radeon: add error output if VM CS fails on cayman Greg Kroah-Hartman
2012-10-29 21:34 ` [ 003/101] ALSA: hda - add dock support for Thinkpad T430 Greg Kroah-Hartman
2012-10-29 21:34 ` [ 004/101] ALSA: hda - Fix silent headphone output from Toshiba P200 Greg Kroah-Hartman
2012-10-29 21:34 ` [ 005/101] VFS: dont do protected {sym,hard}links by default Greg Kroah-Hartman
2012-10-29 21:34 ` Greg Kroah-Hartman [this message]
2012-10-29 21:34 ` [ 007/101] fs/compat_ioctl.c: VIDEO_SET_SPU_PALETTE missing error check Greg Kroah-Hartman
2012-10-29 21:34 ` [ 008/101] drivers/rtc/rtc-imxdi.c: add missing spin lock initialization Greg Kroah-Hartman
2012-10-29 21:34 ` [ 009/101] genalloc: stop crashing the system when destroying a pool Greg Kroah-Hartman
2012-10-29 21:34 ` [ 010/101] ARM: 7559/1: smp: switch away from the idmap before updating init_mm.mm_count Greg Kroah-Hartman
2012-10-29 21:34 ` [ 011/101] x86-64: Fix page table accounting Greg Kroah-Hartman
2012-10-29 21:34 ` [ 012/101] Revert "x86/mm: Fix the size calculation of mapping tables" Greg Kroah-Hartman
2012-10-29 21:34 ` [ 013/101] x86, mm: Trim memory in memblock to be page aligned Greg Kroah-Hartman
2012-10-29 21:34 ` [ 014/101] mm: fix XFS oops due to dirty pages without buffers on s390 Greg Kroah-Hartman
2012-10-29 21:34 ` [ 015/101] SUNRPC: Get rid of the xs_error_report socket callback Greg Kroah-Hartman
2012-10-29 21:34 ` [ 016/101] SUNRPC: Clear the connect flag when socket state is TCP_CLOSE_WAIT Greg Kroah-Hartman
2012-10-29 21:34 ` [ 017/101] Revert "SUNRPC: Ensure we close the socket on EPIPE errors too..." Greg Kroah-Hartman
2012-10-29 21:34 ` [ 018/101] LOCKD: fix races in nsm_client_get Greg Kroah-Hartman
2012-10-29 21:34 ` [ 019/101] SUNRPC: Prevent races in xs_abort_connection() Greg Kroah-Hartman
2012-10-29 21:34 ` [ 020/101] LOCKD: Clear ln->nsm_clnt only when ln->nsm_users is zero Greg Kroah-Hartman
2012-10-29 21:34 ` [ 021/101] xhci: Fix potential NULL ptr deref in command cancellation Greg Kroah-Hartman
2012-10-29 21:34 ` [ 022/101] xhci: fix integer overflow Greg Kroah-Hartman
2012-10-29 21:34 ` [ 023/101] xhci: endianness xhci_calculate_intel_u2_timeout Greg Kroah-Hartman
2012-10-29 21:34 ` [ 024/101] sysfs: sysfs_pathname/sysfs_add_one: Use strlcat() instead of strcat() Greg Kroah-Hartman
2012-10-29 21:34 ` [ 025/101] Staging: android: binder: Fix memory leak on thread/process exit Greg Kroah-Hartman
2012-10-29 21:34 ` [ 026/101] Staging: android: binder: Allow using highmem for binder buffers Greg Kroah-Hartman
2012-10-29 21:34 ` [ 027/101] staging: zram: Fix handling of incompressible pages Greg Kroah-Hartman
2012-10-29 21:34 ` [ 028/101] staging: comedi: das08: fix possible NULL deref during detach Greg Kroah-Hartman
2012-10-29 21:34 ` [ 029/101] staging: comedi: ni_daq_700: fix dio subdevice regression Greg Kroah-Hartman
2012-10-29 21:34 ` [ 030/101] staging: comedi: ni_labpc: fix possible NULL deref during detach Greg Kroah-Hartman
2012-10-29 21:34 ` [ 031/101] staging: comedi: amplc_dio200: " Greg Kroah-Hartman
2012-10-29 21:34 ` [ 032/101] staging: comedi: amplc_pc263: " Greg Kroah-Hartman
2012-10-29 21:34 ` [ 033/101] staging: comedi: amplc_pc236: fix invalid register access " Greg Kroah-Hartman
2012-10-29 21:34 ` [ 034/101] staging: comedi: amplc_pc236: fix possible NULL deref " Greg Kroah-Hartman
2012-10-29 21:34 ` [ 035/101] extcon: Unregister compat class at module unload to fix oops Greg Kroah-Hartman
2012-10-29 21:34 ` [ 036/101] extcon: unregister compat link on cleanup Greg Kroah-Hartman
2012-10-29 21:34 ` [ 037/101] Drivers: hv: Cleanup error handling in vmbus_open() Greg Kroah-Hartman
2012-10-29 21:34 ` [ 038/101] ehci: fix Lucid nohandoff pci quirk to be more generic with BIOS versions Greg Kroah-Hartman
2012-10-29 21:34 ` [ 039/101] ehci: Add yet-another Lucid nohandoff pci quirk Greg Kroah-Hartman
2012-10-29 21:34 ` [ 040/101] usb-storage: add unusual_devs entry for Casio EX-N1 digital camera Greg Kroah-Hartman
2012-10-29 21:34 ` [ 041/101] USB: usb-wwan: fix multiple memory leaks in error paths Greg Kroah-Hartman
2012-10-29 21:34 ` [ 042/101] usb hub: send clear_tt_buffer_complete events when canceling TT clear work Greg Kroah-Hartman
2012-10-29 21:34 ` [ 043/101] USB: ch341: fix port-data memory leak Greg Kroah-Hartman
2012-10-29 21:34 ` [ 044/101] USB: digi_acceleport: " Greg Kroah-Hartman
2012-10-29 21:34 ` [ 045/101] USB: ipw: fix interface-data memory leak in error path Greg Kroah-Hartman
2012-10-29 21:34 ` [ 046/101] USB: mct_u232: fix port-data memory leak Greg Kroah-Hartman
2012-10-29 21:35 ` [ 047/101] USB: mct_u232: fix broken close Greg Kroah-Hartman
2012-10-29 21:35 ` [ 048/101] USB: option: fix interface-data memory leak in error path Greg Kroah-Hartman
2012-10-29 21:35 ` [ 049/101] USB: keyspan: fix NULL-pointer dereferences and memory leaks Greg Kroah-Hartman
2012-10-29 21:35 ` [ 050/101] USB: omninet: fix port-data memory leak Greg Kroah-Hartman
2012-10-29 21:35 ` [ 051/101] USB: qcserial: fix interface-data memory leak in error path Greg Kroah-Hartman
2012-10-29 21:35 ` [ 052/101] USB: whiteheat: fix " Greg Kroah-Hartman
2012-10-29 21:35 ` [ 053/101] USB: whiteheat: fix port-data memory leak Greg Kroah-Hartman
2012-10-29 21:35 ` [ 054/101] USB: opticon: fix DMA from stack Greg Kroah-Hartman
2012-10-29 21:35 ` [ 055/101] USB: opticon: fix memory leak in error path Greg Kroah-Hartman
2012-10-29 21:35 ` [ 056/101] USB: metro-usb: fix port-data memory leak Greg Kroah-Hartman
2012-10-29 21:35 ` [ 057/101] USB: metro-usb: fix io after disconnect Greg Kroah-Hartman
2012-10-29 21:35 ` [ 058/101] USB: mos7720: fix port-data memory leak Greg Kroah-Hartman
2012-10-29 21:35 ` [ 059/101] USB: quatech2: fix memory leak in error path Greg Kroah-Hartman
2012-10-29 21:35 ` [ 060/101] USB: quatech2: fix port-data memory leaks Greg Kroah-Hartman
2012-10-29 21:35 ` [ 061/101] USB: quatech2: fix close and disconnect urb handling Greg Kroah-Hartman
2012-10-29 21:35 ` [ 062/101] USB: quatech2: fix io after disconnect Greg Kroah-Hartman
2012-10-29 21:35 ` [ 063/101] USB: serial: Fix memory leak in sierra_release() Greg Kroah-Hartman
2012-10-29 21:35 ` [ 064/101] USB: sierra: fix memory leak in attach error path Greg Kroah-Hartman
2012-10-29 21:35 ` [ 065/101] USB: sierra: fix memory leak in probe " Greg Kroah-Hartman
2012-10-29 21:35 ` [ 066/101] USB: sierra: fix port-data memory leak Greg Kroah-Hartman
2012-10-29 21:35 ` [ 067/101] USB: mos7840: fix urb leak at release Greg Kroah-Hartman
2012-10-29 21:35 ` [ 068/101] USB: mos7840: fix port-device leak in error path Greg Kroah-Hartman
2012-10-29 21:35 ` [ 069/101] USB: mos7840: remove NULL-urb submission Greg Kroah-Hartman
2012-10-29 21:35 ` [ 070/101] USB: mos7840: remove invalid disconnect handling Greg Kroah-Hartman
2012-10-29 21:35 ` [ 071/101] vhost: fix mergeable bufs on BE hosts Greg Kroah-Hartman
2012-10-29 21:35 ` [ 072/101] ARM: SAMSUNG: Add naming of s3c64xx-spi devices Greg Kroah-Hartman
2012-10-29 21:35 ` [ 073/101] ARM: at91/tc: fix typo in the DT document Greg Kroah-Hartman
2012-10-29 21:35 ` [ 074/101] ARM: at91/i2c: change id to let i2c-gpio work Greg Kroah-Hartman
2012-10-29 21:35 ` [ 075/101] ARM: at91: at91sam9g10: fix SOC type detection Greg Kroah-Hartman
2012-10-29 21:35 ` [ 076/101] ARM: at91: fix external interrupts in non-DT case Greg Kroah-Hartman
2012-10-29 21:35 ` [ 077/101] ARM: at91: fix external interrupt specification in board code Greg Kroah-Hartman
2012-10-29 21:35 ` [ 078/101] mac80211: connect with HT20 if HT40 is not permitted Greg Kroah-Hartman
2012-10-29 21:35 ` [ 079/101] mac80211: check if key has TKIP type before updating IV Greg Kroah-Hartman
2012-10-29 21:35 ` [ 080/101] mac80211: use ieee80211_free_txskb in a few more places Greg Kroah-Hartman
2012-10-29 21:35 ` [ 081/101] b43: Fix oops on unload when firmware not found Greg Kroah-Hartman
2012-10-29 21:35 ` [ 082/101] tilegx: fix some issues in the SW TSO support Greg Kroah-Hartman
2012-10-29 21:35 ` [ 083/101] Bluetooth: SMP: Fix setting unknown auth_req bits Greg Kroah-Hartman
2012-10-29 21:35 ` [ 084/101] qmi_wwan/cdc_ether: move Novatel 551 and E362 to qmi_wwan Greg Kroah-Hartman
2012-10-29 21:35 ` [ 085/101] freezer: exec should clear PF_NOFREEZE along with PF_KTHREAD Greg Kroah-Hartman
2012-10-29 21:35 ` [ 086/101] dmaengine: sirf: fix a typo in dma_prep_interleaved Greg Kroah-Hartman
2012-10-29 21:35 ` [ 087/101] dmaengine: sirf: fix a typo in moving running dma_desc to active queue Greg Kroah-Hartman
2012-10-29 21:35 ` [ 088/101] dmaengine: imx-dma: fix missing unlock on error in imxdma_xfer_desc() Greg Kroah-Hartman
2012-10-29 21:35 ` [ 089/101] iwlwifi: fix 6000 series channel switch command Greg Kroah-Hartman
2012-10-29 21:35 ` [ 090/101] bcma: fix unregistration of cores Greg Kroah-Hartman
2012-10-29 21:35 ` [ 091/101] net/wireless: ipw2200: Fix panic occurring in ipw_handle_promiscuous_tx() Greg Kroah-Hartman
2012-10-29 21:35 ` [ 092/101] cpufreq / powernow-k8: Remove usage of smp_processor_id() in preemptible code Greg Kroah-Hartman
2012-10-29 21:35 ` [ 093/101] Revert "ath9k_hw: Updated AR9003 tx gain table for 5GHz" Greg Kroah-Hartman
2012-10-29 21:35 ` [ 094/101] x86, mm: Find_early_table_space based on ranges that are actually being mapped Greg Kroah-Hartman
2012-10-29 21:35 ` [ 095/101] x86, mm: Undo incorrect revert in arch/x86/mm/init.c Greg Kroah-Hartman
2012-10-29 21:35 ` [ 096/101] cfg80211/mac80211: avoid state mishmash on deauth Greg Kroah-Hartman
2012-10-29 21:35 ` [ 097/101] efi: Defer freeing boot services memory until after ACPI init Greg Kroah-Hartman
2012-10-29 21:35 ` [ 098/101] x86: efi: Turn off efi_enabled after setup on mixed fw/kernel Greg Kroah-Hartman
2012-10-29 21:35 ` [ 099/101] x86, mm: Use memblock memory loop instead of e820_RAM Greg Kroah-Hartman
2012-10-29 21:35 ` [ 100/101] pnfsblock: fix non-aligned DIO read Greg Kroah-Hartman
2012-10-29 21:35 ` [ 101/101] pnfsblock: fix non-aligned DIO write Greg Kroah-Hartman
2012-10-30  9:38 ` [PATCH] USB: io_edgeport: remove unused variable Paul Bolle

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=20121029213240.856149674@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=pageexec@freemail.hu \
    --cc=spender@grsecurity.net \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.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).