From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
Zwane Mwaikambo <zwane@arm.linux.org.uk>,
"Theodore Ts'o" <tytso@mit.edu>,
Randy Dunlap <rdunlap@xenotime.net>,
Dave Jones <davej@redhat.com>,
Chuck Wolber <chuckw@quantumlinux.com>,
Chris Wedgwood <reviews@ml.cw.f00f.org>,
Michael Krufky <mkrufky@linuxtv.org>,
Chuck Ebbert <cebbert@redhat.com>,
Domenico Andreoli <cavokz@gmail.com>, Willy Tarreau <w@1wt.eu>,
Rodrigo Rubira Branco <rbranco@la.checkpoint.com>,
Jake Edge <jake@lwn.net>, Eugene Teo <eteo@redhat.com>,
torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk,
Ulrich Weigand <ulrich.weigand@de.ibm.com>,
Roland McGrath <roland@redhat.com>, Arnd Bergmann <arnd@arndb.de>
Subject: [patch 79/83] tracehook: exec double-reporting fix
Date: Thu, 11 Dec 2008 11:16:46 -0800 [thread overview]
Message-ID: <20081211191646.GA5894@kroah.com> (raw)
In-Reply-To: <20081211191014.GA5759@suse.de>
[-- Attachment #1: tracehook-exec-double-reporting-fix.patch --]
[-- Type: text/plain, Size: 4729 bytes --]
2.6.27-stable review patch. If anyone has any objections, please let us know.
------------------
From: Roland McGrath <roland@redhat.com>
commit 85f334666a771680472722eee43ae0fc8730a619 upstream.
The patch 6341c39 "tracehook: exec" introduced a small regression in
2.6.27 regarding binfmt_misc exec event reporting. Since the reporting
is now done in the common search_binary_handler() function, an exec
of a misc binary will result in two (or possibly multiple) exec events
being reported, instead of just a single one, because the misc handler
contains a recursive call to search_binary_handler.
To add to the confusion, if PTRACE_O_TRACEEXEC is not active, the multiple
SIGTRAP signals will in fact cause only a single ptrace intercept, as the
signals are not queued. However, if PTRACE_O_TRACEEXEC is on, the debugger
will actually see multiple ptrace intercepts (PTRACE_EVENT_EXEC).
The test program included below demonstrates the problem.
This change fixes the bug by calling tracehook_report_exec() only in the
outermost search_binary_handler() call (bprm->recursion_depth == 0).
The additional change to restore bprm->recursion_depth after each binfmt
load_binary call is actually superfluous for this bug, since we test the
value saved on entry to search_binary_handler(). But it keeps the use of
of the depth count to its most obvious expected meaning. Depending on what
binfmt handlers do in certain cases, there could have been false-positive
tests for recursion limits before this change.
/* Test program using PTRACE_O_TRACEEXEC.
This forks and exec's the first argument with the rest of the arguments,
while ptrace'ing. It expects to see one PTRACE_EVENT_EXEC stop and
then a successful exit, with no other signals or events in between.
Test for kernel doing two PTRACE_EVENT_EXEC stops for a binfmt_misc exec:
$ gcc -g traceexec.c -o traceexec
$ sudo sh -c 'echo :test:M::foobar::/bin/cat: > /proc/sys/fs/binfmt_misc/register'
$ echo 'foobar test' > ./foobar
$ chmod +x ./foobar
$ ./traceexec ./foobar; echo $?
==> good <==
foobar test
0
$
==> bad <==
foobar test
unexpected status 0x4057f != 0
3
$
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
static void
wait_for (pid_t child, int expect)
{
int status;
pid_t p = wait (&status);
if (p != child)
{
perror ("wait");
exit (2);
}
if (status != expect)
{
fprintf (stderr, "unexpected status %#x != %#x\n", status, expect);
exit (3);
}
}
int
main (int argc, char **argv)
{
pid_t child = fork ();
if (child < 0)
{
perror ("fork");
return 127;
}
else if (child == 0)
{
ptrace (PTRACE_TRACEME);
raise (SIGUSR1);
execv (argv[1], &argv[1]);
perror ("execve");
_exit (127);
}
wait_for (child, W_STOPCODE (SIGUSR1));
if (ptrace (PTRACE_SETOPTIONS, child,
0L, (void *) (long) PTRACE_O_TRACEEXEC) != 0)
{
perror ("PTRACE_SETOPTIONS");
return 4;
}
if (ptrace (PTRACE_CONT, child, 0L, 0L) != 0)
{
perror ("PTRACE_CONT");
return 5;
}
wait_for (child, W_STOPCODE (SIGTRAP | (PTRACE_EVENT_EXEC << 8)));
if (ptrace (PTRACE_CONT, child, 0L, 0L) != 0)
{
perror ("PTRACE_CONT");
return 6;
}
wait_for (child, W_EXITCODE (0, 0));
return 0;
}
Reported-by: Arnd Bergmann <arnd@arndb.de>
CC: Ulrich Weigand <ulrich.weigand@de.ibm.com>
Signed-off-by: Roland McGrath <roland@redhat.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
fs/exec.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1164,6 +1164,7 @@ EXPORT_SYMBOL(remove_arg_zero);
*/
int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
{
+ unsigned int depth = bprm->recursion_depth;
int try,retval;
struct linux_binfmt *fmt;
#ifdef __alpha__
@@ -1224,8 +1225,15 @@ int search_binary_handler(struct linux_b
continue;
read_unlock(&binfmt_lock);
retval = fn(bprm, regs);
+ /*
+ * Restore the depth counter to its starting value
+ * in this call, so we don't have to rely on every
+ * load_binary function to restore it on return.
+ */
+ bprm->recursion_depth = depth;
if (retval >= 0) {
- tracehook_report_exec(fmt, bprm, regs);
+ if (depth == 0)
+ tracehook_report_exec(fmt, bprm, regs);
put_binfmt(fmt);
allow_write_access(bprm->file);
if (bprm->file)
next prev parent reply other threads:[~2008-12-11 19:46 UTC|newest]
Thread overview: 107+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20081211190201.612240183@mini.kroah.org>
2008-12-11 19:10 ` [patch 00/83] 2.6.27.9-stable review Greg KH
2008-12-11 19:13 ` [patch 01/83] libata: improve phantom device detection Greg KH
2008-12-11 19:13 ` [patch 02/83] af_unix: netns: fix problem of return value Greg KH
2008-12-11 19:13 ` [patch 03/83] cxgb3: Fix kernel crash caused by uninitialized l2t_entry.arpq Greg KH
2008-12-11 21:12 ` Stefan Lippers-Hollmann
2008-12-11 23:41 ` Greg KH
2008-12-12 3:49 ` David Miller
2008-12-12 4:00 ` Greg KH
2008-12-12 5:11 ` David Miller
2008-12-11 19:13 ` [patch 04/83] niu: Fix readq implementation when architecture does not provide one Greg KH
2008-12-11 19:13 ` [patch 05/83] pppol2tp: Add missing sock_put() in pppol2tp_release() Greg KH
2008-12-11 19:13 ` [patch 06/83] udp: multicast packets need to check namespace Greg KH
2008-12-11 19:13 ` [patch 07/83] sparc64: Fix offset calculation in compute_size() Greg KH
2008-12-11 19:13 ` [patch 08/83] sparc64: Fix __copy_{to,from}_user_inatomic defines Greg KH
2008-12-11 19:13 ` [patch 09/83] sparc64: Fix PCI resource mapping on sparc64 Greg KH
2008-12-11 19:13 ` [patch 10/83] sparc64: Fix bug in PTRACE_SETFPREGS64 handling Greg KH
2008-12-11 19:13 ` [patch 11/83] sparc64: Fix VIS emulation bugs Greg KH
2008-12-11 19:13 ` [patch 12/83] sparc64: Sync FPU state in VIS emulation handler Greg KH
2008-12-11 19:13 ` [patch 13/83] Enforce a minimum SG_IO timeout Greg KH
2008-12-11 19:14 ` [patch 14/83] Fix a race condition in FASYNC handling Greg KH
2008-12-11 19:14 ` [patch 15/83] ACPI suspend: Blacklist boxes that require us to set SCI_EN directly on resume Greg KH
2008-12-11 19:14 ` [patch 16/83] jbd: fix error handling for checkpoint io Greg KH
2008-12-11 19:14 ` [patch 17/83] jbd: test BH_Write_EIO to detect errors on metadata buffers Greg KH
2008-12-11 19:14 ` [patch 18/83] spi: avoid spidev crash when device is removed Greg KH
2008-12-11 19:14 ` [patch 19/83] ATM: CVE-2008-5079: duplicate listen() on socket corrupts the vcc table Greg KH
2008-12-11 19:14 ` [patch 20/83] powerpc/mpic: Dont reset affinity for secondary MPIC on boot Greg KH
2008-12-11 19:14 ` [patch 21/83] Input: i8042 - add Thinkpad R31 to nomux list Greg KH
2008-12-11 19:14 ` [patch 22/83] Input: i8042 - add Blue FB5601 to noloop exception table Greg KH
2008-12-11 19:14 ` [patch 23/83] Input: i8042 - add Dell XPS M1530 to nomux list Greg KH
2008-12-11 19:14 ` [patch 24/83] Input: i8042 - add Compal Hel80 laptop to nomux blacklist Greg KH
2008-12-11 19:14 ` [patch 25/83] edac: fix enabling of polling cell module Greg KH
2008-12-11 19:14 ` [patch 26/83] USB: option: add Ericsson F3507g and Dell 5530 Greg KH
2008-12-11 19:14 ` [patch 27/83] USB: option.c remove duplicate device ids now supported in hso.c Greg KH
2008-12-11 19:14 ` [patch 28/83] USB: Option / AnyData new modem, same ID Greg KH
2008-12-11 19:14 ` [patch 29/83] USB: option: add Pantech cards Greg KH
2008-12-11 19:14 ` [patch 30/83] USB: add ZTE MF626 USB GSM modem entry Greg KH
2008-12-11 19:14 ` [patch 31/83] USB: support Huawei data card product IDs Greg KH
2008-12-11 19:14 ` [patch 32/83] USB: Add YISO u893 usb modem vendor and product IDs to option driver Greg KH
2008-12-11 19:14 ` [patch 33/83] USB: serial: add more Onda device ids " Greg KH
2008-12-11 19:14 ` [patch 34/83] USB: unusual-devs: support Huawei data card product IDs Greg KH
2008-12-11 19:14 ` [patch 35/83] USB: Unusual dev for Mio moov 330 gps Greg KH
2008-12-11 19:14 ` [patch 36/83] USB: Unusual dev for the "Kyocera / Contax SL300R T*" digital camera Greg KH
2008-12-11 19:14 ` [patch 37/83] USB: add Nikon D300 camera to unusual_devs Greg KH
2008-12-11 19:29 ` Chris Wedgwood
2008-12-11 19:51 ` Alan Stern
2008-12-11 23:42 ` Greg KH
2008-12-11 19:14 ` [patch 38/83] USB: unusual devs patch for Nokia 7610 Supernova Greg KH
2008-12-11 19:14 ` [patch 39/83] USB: storage: updates unusual_devs entry for the Nokia 6300 Greg KH
2008-12-11 19:15 ` [patch 40/83] USB: storage: update unusual_devs entries for Nokia 5300 and 5310 Greg KH
2008-12-11 19:15 ` [patch 41/83] USB: storage: unusual_devs entry for Mio C520-GPS Greg KH
2008-12-11 19:15 ` [patch 42/83] USB: usb-storage: unusual_devs entry for Nikon D2H Greg KH
2008-12-11 19:15 ` [patch 43/83] ALSA: HDA: hda_proc: Fix printf format specifier Greg KH
2008-12-11 19:15 ` [patch 44/83] ALSA: hda - Fix sound on NEC Versa S9100 Greg KH
2008-12-11 19:15 ` [patch 45/83] ALSA: hda: Add support for ECS/PC Chips boards with Sigmatel codecs Greg KH
2008-12-11 19:15 ` [patch 46/83] ALSA: hda - Fix ALC269 capture source Greg KH
2008-12-11 19:15 ` [patch 47/83] ALSA: hda - Add model for Toshiba L305 laptop Greg KH
2008-12-11 19:15 ` [patch 48/83] ALSA: hda: fixed hp_nid DAC for DELL_M6 Greg KH
2008-12-11 19:15 ` [patch 49/83] ALSA: HDA: patch_analog: Fix SPDIF output on AD1989B Greg KH
2008-12-11 19:15 ` [patch 50/83] ALSA: HDA: patch_analog: Quirk for Asus P5Q Premium/Pro boards Greg KH
2008-12-11 19:15 ` [patch 51/83] ALSA: hda: appletv support Greg KH
2008-12-11 19:15 ` [patch 52/83] ALSA: hda - Fix another ALC889A (rev 0x100101) Greg KH
2008-12-11 19:15 ` [patch 53/83] ALSA: hda - Add ALC887 support Greg KH
2008-12-11 19:15 ` [patch 54/83] ALSA: hda - Add support of ALC272 Greg KH
2008-12-11 19:15 ` [patch 55/83] ALSA: hda - Restore default pin configs for realtek codecs Greg KH
2008-12-11 19:15 ` [patch 56/83] ALSA: hda - Add another HP model for AD1884A Greg KH
2008-12-11 19:15 ` [patch 57/83] ALSA: hda - Add a quirk for another Acer Aspire (1025:0090) Greg KH
2008-12-11 19:15 ` [patch 58/83] ALSA: hda - Add a quirk for MEDION MD96630 Greg KH
2008-12-11 19:15 ` [patch 59/83] ALSA: hda - Add another HP model (6730s) for AD1884A Greg KH
2008-12-11 19:16 ` [patch 60/83] ALSA: hda - Make the HP EliteBook 8530p use AD1884A model laptop Greg KH
2008-12-11 19:16 ` [patch 61/83] ALSA: hda - Add a quirk for Dell Studio 15 Greg KH
2008-12-11 19:16 ` [patch 62/83] ALSA: hda - No Headphone as Line-out swich without line-outs Greg KH
2008-12-11 19:16 ` [patch 63/83] ALSA: hda - mark Dell studio 1535 quirk Greg KH
2008-12-11 19:16 ` [patch 64/83] ALSA: emu10k1 - Add more invert_shared_spdif flag to Audigy models Greg KH
2008-12-11 19:16 ` [patch 65/83] cxgb3 - fix race in EEH Greg KH
2008-12-11 19:16 ` [patch 66/83] cxgb3 - remove duplicate tests in lro Greg KH
2008-12-11 19:16 ` [patch 67/83] sched: fix a bug in sched domain degenerate Greg KH
2008-12-11 19:16 ` [patch 68/83] x86: HPET: convert WARN_ON to WARN_ON_ONCE Greg KH
2008-12-17 11:26 ` Matt Fleming
2008-12-17 11:33 ` Takashi Iwai
2008-12-17 12:03 ` Matt Fleming
2008-12-17 18:42 ` Greg KH
2008-12-17 19:51 ` Matt Fleming
2008-12-17 19:54 ` Greg KH
2008-12-18 11:37 ` Thomas Gleixner
2008-12-18 19:01 ` Greg KH
2008-12-11 19:16 ` [patch 69/83] x86, memory hotplug: remove wrong -1 in calling init_memory_mapping() Greg KH
2008-12-11 19:16 ` [patch 70/83] x86: remove debug code from arch_add_memory() Greg KH
2008-12-11 19:16 ` [patch 71/83] sched: CPU remove deadlock fix Greg KH
2008-12-11 19:16 ` [patch 72/83] PCI: stop leaking slot_name in pci_create_slot Greg KH
2008-12-11 19:16 ` [patch 73/83] PCIe: ASPM: Break out of endless loop waiting for PCI config bits to switch Greg KH
2008-12-11 19:16 ` [patch 74/83] uml: boot broken due to buffer overrun Greg KH
2008-12-11 19:16 ` [patch 75/83] pagemap: fix 32-bit pagemap regression Greg KH
2008-12-11 19:16 ` [patch 76/83] fix mapping_writably_mapped() Greg KH
2008-12-11 19:16 ` [patch 77/83] atv: hid quirk for appletv IR receiver Greg KH
2008-12-11 19:16 ` [patch 78/83] Allow recursion in binfmt_script and binfmt_misc Greg KH
2008-12-11 19:16 ` Greg KH [this message]
2008-12-11 19:16 ` [patch 80/83] powerpc/virtex5: Fix Virtex5 machine check handling Greg KH
2008-12-11 19:16 ` [patch 81/83] ACPI: delete OSI(Linux) DMI dmesg spam Greg KH
2008-12-11 19:16 ` [patch 82/83] cifs: fix a regression in cifs umount codepath Greg KH
2008-12-11 19:16 ` [patch 83/83] pnp: make the resource type an unsigned long Greg KH
2008-12-12 5:19 ` [stable] [patch 00/83] 2.6.27.9-stable review Greg KH
2008-12-12 5:21 ` [patch 84/83] powerpc: Use cpu_thread_in_core in smp_init for of_spin_map Greg KH
2008-12-12 5:24 ` [patch 85/83] XFS: Fix hang after disallowed rename across directory quota domains Greg KH
2008-12-13 9:29 ` [patch 00/83] 2.6.27.9-stable review François Valenduc
2008-12-16 23:25 ` Greg KH
2008-12-17 18:58 ` François Valenduc
2008-12-18 19:00 ` 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=20081211191646.GA5894@kroah.com \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arnd@arndb.de \
--cc=cavokz@gmail.com \
--cc=cebbert@redhat.com \
--cc=chuckw@quantumlinux.com \
--cc=davej@redhat.com \
--cc=eteo@redhat.com \
--cc=jake@lwn.net \
--cc=jmforbes@linuxtx.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkrufky@linuxtv.org \
--cc=rbranco@la.checkpoint.com \
--cc=rdunlap@xenotime.net \
--cc=reviews@ml.cw.f00f.org \
--cc=roland@redhat.com \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=ulrich.weigand@de.ibm.com \
--cc=w@1wt.eu \
--cc=zwane@arm.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