mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk, Al Viro <viro@zeniv.linux.org.uk>
Subject: [100/107] deal with races in /proc/*/{syscall,stack,personality}
Date: Wed, 02 Nov 2011 15:15:06 -0700	[thread overview]
Message-ID: <20111102221459.285225069@clark.kroah.org> (raw)
In-Reply-To: <20111102221600.GA26650@kroah.com>

2.6.32-longterm review patch.  If anyone has any objections, please let us know.

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

From: Al Viro <viro@zeniv.linux.org.uk>

commit a9712bc12c40c172e393f85a9b2ba8db4bf59509 upstream.

All of those are rw-r--r-- and all are broken for suid - if you open
a file before the target does suid-root exec, you'll be still able
to access it.  For personality it's not a big deal, but for syscall
and stack it's a real problem.

Fix: check that task is tracable for you at the time of read().

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 fs/proc/base.c |   69 +++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 50 insertions(+), 19 deletions(-)

--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -328,6 +328,23 @@ static int proc_pid_wchan(struct task_st
 }
 #endif /* CONFIG_KALLSYMS */
 
+static int lock_trace(struct task_struct *task)
+{
+	int err = mutex_lock_killable(&task->cred_guard_mutex);
+	if (err)
+		return err;
+	if (!ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
+		mutex_unlock(&task->cred_guard_mutex);
+		return -EPERM;
+	}
+	return 0;
+}
+
+static void unlock_trace(struct task_struct *task)
+{
+	mutex_unlock(&task->cred_guard_mutex);
+}
+
 #ifdef CONFIG_STACKTRACE
 
 #define MAX_STACK_TRACE_DEPTH	64
@@ -337,6 +354,7 @@ static int proc_pid_stack(struct seq_fil
 {
 	struct stack_trace trace;
 	unsigned long *entries;
+	int err;
 	int i;
 
 	entries = kmalloc(MAX_STACK_TRACE_DEPTH * sizeof(*entries), GFP_KERNEL);
@@ -347,15 +365,20 @@ static int proc_pid_stack(struct seq_fil
 	trace.max_entries	= MAX_STACK_TRACE_DEPTH;
 	trace.entries		= entries;
 	trace.skip		= 0;
-	save_stack_trace_tsk(task, &trace);
 
-	for (i = 0; i < trace.nr_entries; i++) {
-		seq_printf(m, "[<%p>] %pS\n",
-			   (void *)entries[i], (void *)entries[i]);
+	err = lock_trace(task);
+	if (!err) {
+		save_stack_trace_tsk(task, &trace);
+
+		for (i = 0; i < trace.nr_entries; i++) {
+			seq_printf(m, "[<%p>] %pS\n",
+				   (void *)entries[i], (void *)entries[i]);
+		}
+		unlock_trace(task);
 	}
 	kfree(entries);
 
-	return 0;
+	return err;
 }
 #endif
 
@@ -527,18 +550,22 @@ static int proc_pid_syscall(struct task_
 {
 	long nr;
 	unsigned long args[6], sp, pc;
+	int res = lock_trace(task);
+	if (res)
+		return res;
 
 	if (task_current_syscall(task, &nr, args, 6, &sp, &pc))
-		return sprintf(buffer, "running\n");
-
-	if (nr < 0)
-		return sprintf(buffer, "%ld 0x%lx 0x%lx\n", nr, sp, pc);
-
-	return sprintf(buffer,
+		res = sprintf(buffer, "running\n");
+	else if (nr < 0)
+		res = sprintf(buffer, "%ld 0x%lx 0x%lx\n", nr, sp, pc);
+	else
+		res = sprintf(buffer,
 		       "%ld 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
 		       nr,
 		       args[0], args[1], args[2], args[3], args[4], args[5],
 		       sp, pc);
+	unlock_trace(task);
+	return res;
 }
 #endif /* CONFIG_HAVE_ARCH_TRACEHOOK */
 
@@ -2497,8 +2524,12 @@ static int proc_tgid_io_accounting(struc
 static int proc_pid_personality(struct seq_file *m, struct pid_namespace *ns,
 				struct pid *pid, struct task_struct *task)
 {
-	seq_printf(m, "%08x\n", task->personality);
-	return 0;
+	int err = lock_trace(task);
+	if (!err) {
+		seq_printf(m, "%08x\n", task->personality);
+		unlock_trace(task);
+	}
+	return err;
 }
 
 /*
@@ -2517,13 +2548,13 @@ static const struct pid_entry tgid_base_
 	REG("environ",    S_IRUSR, proc_environ_operations),
 	INF("auxv",       S_IRUSR, proc_pid_auxv),
 	ONE("status",     S_IRUGO, proc_pid_status),
-	ONE("personality", S_IRUSR, proc_pid_personality),
+	ONE("personality", S_IRUGO, proc_pid_personality),
 	INF("limits",	  S_IRUSR, proc_pid_limits),
 #ifdef CONFIG_SCHED_DEBUG
 	REG("sched",      S_IRUGO|S_IWUSR, proc_pid_sched_operations),
 #endif
 #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
-	INF("syscall",    S_IRUSR, proc_pid_syscall),
+	INF("syscall",    S_IRUGO, proc_pid_syscall),
 #endif
 	INF("cmdline",    S_IRUGO, proc_pid_cmdline),
 	ONE("stat",       S_IRUGO, proc_tgid_stat),
@@ -2551,7 +2582,7 @@ static const struct pid_entry tgid_base_
 	INF("wchan",      S_IRUGO, proc_pid_wchan),
 #endif
 #ifdef CONFIG_STACKTRACE
-	ONE("stack",      S_IRUSR, proc_pid_stack),
+	ONE("stack",      S_IRUGO, proc_pid_stack),
 #endif
 #ifdef CONFIG_SCHEDSTATS
 	INF("schedstat",  S_IRUGO, proc_pid_schedstat),
@@ -2856,13 +2887,13 @@ static const struct pid_entry tid_base_s
 	REG("environ",   S_IRUSR, proc_environ_operations),
 	INF("auxv",      S_IRUSR, proc_pid_auxv),
 	ONE("status",    S_IRUGO, proc_pid_status),
-	ONE("personality", S_IRUSR, proc_pid_personality),
+	ONE("personality", S_IRUGO, proc_pid_personality),
 	INF("limits",	 S_IRUSR, proc_pid_limits),
 #ifdef CONFIG_SCHED_DEBUG
 	REG("sched",     S_IRUGO|S_IWUSR, proc_pid_sched_operations),
 #endif
 #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
-	INF("syscall",   S_IRUSR, proc_pid_syscall),
+	INF("syscall",   S_IRUGO, proc_pid_syscall),
 #endif
 	INF("cmdline",   S_IRUGO, proc_pid_cmdline),
 	ONE("stat",      S_IRUGO, proc_tid_stat),
@@ -2889,7 +2920,7 @@ static const struct pid_entry tid_base_s
 	INF("wchan",     S_IRUGO, proc_pid_wchan),
 #endif
 #ifdef CONFIG_STACKTRACE
-	ONE("stack",      S_IRUSR, proc_pid_stack),
+	ONE("stack",      S_IRUGO, proc_pid_stack),
 #endif
 #ifdef CONFIG_SCHEDSTATS
 	INF("schedstat", S_IRUGO, proc_pid_schedstat),



  parent reply	other threads:[~2011-11-03  1:37 UTC|newest]

Thread overview: 122+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-02 22:16 [000/107] 2.6.32.47-longterm review Greg KH
2011-11-02 22:13 ` [001/107] USB: ftdi_sio: add Calao reference board support Greg KH
2011-11-02 22:13 ` [002/107] USB: EHCI: Do not rely on PORT_SUSPEND to stop USB resuming in ehci_bus_resume() Greg KH
2011-11-02 22:13 ` [003/107] rt2x00: do not drop usb dev reference counter on suspend Greg KH
2011-11-02 22:13 ` [004/107] atm: br2684: Fix oops due to skb->dev being NULL Greg KH
2011-11-02 22:13 ` [005/107] sparc: Allow handling signals when stack is corrupted Greg KH
2011-11-04  4:33   ` Ben Hutchings
2011-11-04  6:09     ` David Miller
2011-11-02 22:13 ` [006/107] sparc: fix array bounds error setting up PCIC NMI trap Greg KH
2011-11-02 22:13 ` [007/107] Fix broken backport for IPv6 tunnels Greg KH
2011-11-02 22:13 ` [008/107] net: Fix IPv6 GSO type checks in Intel ethernet drivers Greg KH
2011-11-02 22:13 ` [009/107] ipv6: Add GSO support on forwarding path Greg KH
2011-11-02 22:13 ` [010/107] Revert "x86, hotplug: Use mwait to offline a processor, fix the legacy case" Greg KH
2011-11-02 22:13 ` [011/107] GRO: fix merging a paged skb after non-paged skbs Greg KH
2011-11-02 22:13 ` [012/107] xen-blkfront: fix data size for xenbus_gather in blkfront_connect Greg KH
2011-11-02 22:13 ` [013/107] md/linear: avoid corrupting structure while waiting for rcu_free to complete Greg KH
2011-11-02 22:13 ` [014/107] powerpc/mpic: Fix problem that affinity is not updated Greg KH
2011-11-02 22:13 ` [015/107] powerpc/pci: Check devices status property when scanning OF tree Greg KH
2011-11-02 22:13 ` [016/107] xen: x86_32: do not enable iterrupts when returning from exception in interrupt context Greg KH
2011-11-02 22:13 ` [017/107] xen/smp: Warn user why they keel over - nosmp or noapic and what to use instead Greg KH
2011-11-02 22:13 ` [018/107] ARM: davinci: da850 EVM: read mac address from SPI flash Greg KH
2011-11-02 22:13 ` [019/107] md: Fix handling for devices from 2TB to 4TB in 0.90 metadata Greg KH
2011-11-02 22:13 ` [020/107] net/9p: fix client code to fail more gracefully on protocol error Greg KH
2011-11-02 22:13 ` [021/107] fs/9p: Fid is not valid after a failed clunk Greg KH
2011-11-02 22:13 ` [022/107] net/9p: Fix the msize calculation Greg KH
2011-11-02 22:13 ` [023/107] irda: fix smsc-ircc2 section mismatch warning Greg KH
2011-11-02 22:13 ` [024/107] [SCSI] qla2xxx: Correct inadvertent loop state transitions during port-update handling Greg KH
2011-11-02 22:13 ` [025/107] e1000: Fix driver to be used on PA RISC C8000 workstations Greg KH
2011-11-02 22:13 ` [026/107] ASoC: Fix reporting of partial jack updates Greg KH
2011-11-02 22:13 ` [027/107] ALSA: HDA: Cirrus - fix "Surround Speaker" volume control name Greg KH
2011-11-02 22:13 ` [028/107] drm/radeon/kms: fix typo in r100_blit_copy Greg KH
2011-11-03 13:01   ` Deucher, Alexander
2011-11-03 13:15     ` Greg KH
2011-11-02 22:13 ` [029/107] cifs: fix possible memory corruption in CIFSFindNext Greg KH
2011-11-02 22:13 ` [030/107] b43: Fix beacon problem in ad-hoc mode Greg KH
2011-11-02 22:13 ` [031/107] wireless: Reset beacon_found while updating regulatory Greg KH
2011-11-02 22:13 ` [032/107] USB: PL2303: correctly handle baudrates above 115200 Greg KH
2011-11-02 22:13 ` [033/107] ASIX: Add AX88772B USB ID Greg KH
2011-11-02 22:14 ` [034/107] hvc_console: Improve tty/console put_chars handling Greg KH
2011-11-02 22:14 ` [035/107] TPM: Call tpm_transmit with correct size Greg KH
2011-11-02 22:14 ` [036/107] TPM: Zero buffer after copying to userspace Greg KH
2011-11-02 22:14 ` [037/107] [SCSI] libiscsi_tcp: fix LLD data allocation Greg KH
2011-11-02 22:14 ` [038/107] cnic: Improve NETDEV_UP event handling Greg KH
2011-11-02 22:14 ` [039/107] ALSA: hda/realtek - Avoid bogus HP-pin assignment Greg KH
2011-11-02 22:14 ` [040/107] [SCSI] 3w-9xxx: fix iommu_iova leak Greg KH
2011-11-02 22:14 ` [041/107] [SCSI] aacraid: reset should disable MSI interrupt Greg KH
2011-11-02 22:14 ` [042/107] [SCSI] libsas: fix failure to revalidate domain for anything but the first expander child Greg KH
2011-11-02 22:14 ` [043/107] cfg80211: Fix validation of AKM suites Greg KH
2011-11-02 22:14 ` [044/107] splice: direct_splice_actor() should not use pos in sd Greg KH
2011-11-02 22:14 ` [045/107] [SCSI] libsas: fix panic when single phy is disabled on a wide port Greg KH
2011-11-02 22:14 ` [046/107] ahci: Enable SB600 64bit DMA on Asus M3A Greg KH
2011-11-02 22:14 ` [047/107] HID: usbhid: Add support for SiGma Micro chip Greg KH
2011-11-02 22:14 ` [048/107] hwmon: (w83627ehf) Properly report thermal diode sensors Greg KH
2011-11-02 22:14 ` [049/107] x25: Prevent skb overreads when checking call user data Greg KH
2011-11-02 22:14 ` [050/107] block: check for proper length of iov entries earlier in blk_rq_map_user_iov() Greg KH
2011-11-04 15:24   ` Ben Hutchings
2011-11-04 17:14     ` Greg KH
2011-11-04 19:06       ` Ben Hutchings
2011-11-04 20:28         ` Greg KH
2011-11-04 21:00           ` Dan Carpenter
2011-11-04 21:04             ` Greg KH
2011-11-04 19:36     ` Dan Carpenter
2011-11-02 22:14 ` [051/107] staging: quatech_usb2: Potential lost wakeup scenario in TIOCMIWAIT Greg KH
2011-11-02 22:14 ` [052/107] USB: qcserial: add device ID for "HP un2430 Mobile Broadband Module" Greg KH
2011-11-02 22:14 ` [053/107] xhci-mem.c: Check for ring->first_seg != NULL Greg KH
2011-11-02 22:14 ` [054/107] [SCSI] ipr: Always initiate hard reset in kdump kernel Greg KH
2011-11-02 22:14 ` [055/107] [SCSI] libsas: set sas_address and device type of rphy Greg KH
2011-11-02 22:14 ` [056/107] ALSA: HDA: Add new revision for ALC662 Greg KH
2011-11-02 22:14 ` [057/107] x86: Fix compilation bug in kprobes twobyte_is_boostable Greg KH
2011-11-02 22:14 ` [058/107] epoll: fix spurious lockdep warnings Greg KH
2011-11-02 22:14 ` [059/107] usbmon vs. tcpdump: fix dropped packet count Greg KH
2011-11-02 22:14 ` [060/107] USB: storage: Use normalized sense when emulating autosense Greg KH
2011-11-02 22:14 ` [061/107] USB: pid_ns: ensure pid is not freed during kill_pid_info_as_uid Greg KH
2011-11-02 22:14 ` [062/107] usb: cdc-acm: Owen SI-30 support Greg KH
2011-11-02 22:14 ` [063/107] USB: add RESET_RESUME for webcams shown to be quirky Greg KH
2011-11-02 22:14 ` [064/107] USB: pl2303: add id for SMART device Greg KH
2011-11-02 22:14 ` [065/107] USB: ftdi_sio: add PID for Sony Ericsson Urban Greg KH
2011-11-02 22:14 ` [066/107] USB: ftdi_sio: Support TI/Luminary Micro Stellaris BD-ICDI Board Greg KH
2011-11-02 22:14 ` [067/107] QE/FHCI: fixed the CONTROL bug Greg KH
2011-11-02 22:14 ` [068/107] Update email address for stable patch submission Greg KH
2011-11-03  8:08   ` Christoph Biedl
2011-11-03  8:25     ` Sven Joachim
2011-11-03 12:18       ` Greg KH
2011-11-02 22:14 ` [069/107] kobj_uevent: Ignore if some listeners cannot handle message Greg KH
2011-11-02 22:14 ` [070/107] kmod: prevent kmod_loop_msg overflow in __request_module() Greg KH
2011-11-02 22:14 ` [071/107] time: Change jiffies_to_clock_t() argument type to unsigned long Greg KH
2011-11-02 22:14 ` [072/107] nfsd4: Remove check for a 32-bit cookie in nfsd4_readdir() Greg KH
2011-11-02 22:14 ` [073/107] nfsd4: ignore WANT bits in open downgrade Greg KH
2011-11-02 22:14 ` [074/107] ASoC: wm8940: Properly set codec->dapm.bias_level Greg KH
2011-11-02 22:14 ` [075/107] ASoC: ak4642: fixup cache register table Greg KH
2011-11-02 22:14 ` [076/107] ASoC: ak4535: " Greg KH
2011-11-02 22:14 ` [077/107] KVM: s390: check cpu_id prior to using it Greg KH
2011-11-02 22:14 ` [078/107] [S390] ccwgroup: move attributes to attribute group Greg KH
2011-11-02 22:14 ` [079/107] iommu/amd: Fix wrong shift direction Greg KH
2011-11-02 22:14 ` [080/107] carminefb: Fix module parameters permissions Greg KH
2011-11-02 22:14 ` [081/107] [media] uvcvideo: Set alternate setting 0 on resume if the bus has been reset Greg KH
2011-11-02 22:14 ` [082/107] [media] tuner_xc2028: Allow selection of the frequency adjustment code for XC3028 Greg KH
2011-11-02 22:14 ` [083/107] plat-mxc: iomux-v3.h: implicitly enable pull-up/down when thats desired Greg KH
2011-11-02 22:14 ` [084/107] um: fix ubd cow size Greg KH
2011-11-02 22:14 ` [085/107] cfq: calculate the seek_mean per cfq_queue not per cfq_io_context Greg KH
2011-11-02 22:14 ` [086/107] cfq: merge cooperating cfq_queues Greg KH
2011-11-02 22:14 ` [087/107] cfq: change the meaning of the cfqq_coop flag Greg KH
2011-11-02 22:14 ` [088/107] cfq: break apart merged cfqqs if they stop cooperating Greg KH
2011-11-02 22:14 ` [089/107] cfq-iosched: get rid of the coop_preempt flag Greg KH
2011-11-02 22:14 ` [090/107] cfq: Dont allow queue merges for queues that have no process references Greg KH
2011-11-02 22:14 ` [091/107] xen/timer: Missing IRQF_NO_SUSPEND in timer code broke suspend Greg KH
2011-11-02 22:14 ` [092/107] KVM: x86: Reset tsc_timestamp on TSC writes Greg KH
2011-11-02 22:14 ` [093/107] genirq: Add IRQF_RESUME_EARLY and resume such IRQs earlier Greg KH
2011-11-02 22:15 ` [094/107] Revert "usb: musb: restore INDEX register in resume path" Greg KH
2011-11-02 22:15 ` [095/107] Revert "MIPS: MTX-1: Make au1000_eth probe all PHY Greg KH
2011-11-02 22:15 ` [096/107] watchdog: mtx1-wdt: fix build failure Greg KH
2011-11-02 22:15 ` [097/107] kcore: fix test for end of list Greg KH
2011-11-02 22:15 ` [098/107] thinkpad-acpi: module autoloading for newer Lenovo ThinkPads Greg KH
2011-11-02 22:15 ` [099/107] scm: lower SCM_MAX_FD Greg KH
2011-11-02 22:15 ` Greg KH [this message]
2011-11-02 22:15 ` [101/107] NLM: Dont hang forever on NLM unlock requests Greg KH
2011-11-02 22:15 ` [102/107] Bluetooth: l2cap and rfcomm: fix 1 byte infoleak to userspace Greg KH
2011-11-02 22:15 ` [103/107] vm: fix vm_pgoff wrap in stack expansion Greg KH
2011-11-02 22:15 ` [104/107] vm: fix vm_pgoff wrap in upward expansion Greg KH
2011-11-02 22:15 ` [105/107] Bluetooth: Prevent buffer overflow in l2cap config request Greg KH
2011-11-02 22:15 ` [106/107] nl80211: fix overflow in ssid_len Greg KH
2011-11-02 22:15 ` [107/107] net_sched: Fix qdisc_notify() Greg KH

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=20111102221459.285225069@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --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®