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, Andi Kleen <ak@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@elte.hu>
Subject: [patch 06/33] x86: use early clobbers in usercopy*.c
Date: Wed, 4 Feb 2009 10:34:27 -0800 [thread overview]
Message-ID: <20090204183427.GG13936@kroah.com> (raw)
In-Reply-To: <20090204183403.GA13936@kroah.com>
[-- Attachment #1: x86-use-early-clobbers-in-usercopy-.c.patch --]
[-- Type: text/plain, Size: 3990 bytes --]
2.6.28-stable review patch. If anyone has any objections, please let us know.
------------------
From: Andi Kleen <andi@firstfloor.org>
commit e0a96129db574d6365e3439d16d88517c437ab33 upstream.
Impact: fix rare (but currently harmless) miscompile with certain configs and gcc versions
Hugh Dickins noticed that strncpy_from_user() was miscompiled
in some circumstances with gcc 4.3.
Thanks to Hugh's excellent analysis it was easy to track down.
Hugh writes:
> Try building an x86_64 defconfig 2.6.29-rc1 kernel tree,
> except not quite defconfig, switch CONFIG_PREEMPT_NONE=y
> and CONFIG_PREEMPT_VOLUNTARY off (because it expands a
> might_fault() there, which hides the issue): using a
> gcc 4.3.2 (I've checked both openSUSE 11.1 and Fedora 10).
>
> It generates the following:
>
> 0000000000000000 <__strncpy_from_user>:
> 0: 48 89 d1 mov %rdx,%rcx
> 3: 48 85 c9 test %rcx,%rcx
> 6: 74 0e je 16 <__strncpy_from_user+0x16>
> 8: ac lods %ds:(%rsi),%al
> 9: aa stos %al,%es:(%rdi)
> a: 84 c0 test %al,%al
> c: 74 05 je 13 <__strncpy_from_user+0x13>
> e: 48 ff c9 dec %rcx
> 11: 75 f5 jne 8 <__strncpy_from_user+0x8>
> 13: 48 29 c9 sub %rcx,%rcx
> 16: 48 89 c8 mov %rcx,%rax
> 19: c3 retq
>
> Observe that "sub %rcx,%rcx; mov %rcx,%rax", whereas gcc 4.2.1
> (and many other configs) say "sub %rcx,%rdx; mov %rdx,%rax".
> Isn't it returning 0 when it ought to be returning strlen?
The asm constraints for the strncpy_from_user() result were missing an
early clobber, which tells gcc that the last output arguments
are written before all input arguments are read.
Also add more early clobbers in the rest of the file and fix 32-bit
usercopy.c in the same way.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
[ since this API is rarely used and no in-kernel user relies on a 'len'
return value (they only rely on negative return values) this miscompile
was never noticed in the field. But it's worth fixing it nevertheless. ]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
arch/x86/lib/usercopy_32.c | 4 ++--
arch/x86/lib/usercopy_64.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
--- a/arch/x86/lib/usercopy_32.c
+++ b/arch/x86/lib/usercopy_32.c
@@ -56,7 +56,7 @@ do { \
" jmp 2b\n" \
".previous\n" \
_ASM_EXTABLE(0b,3b) \
- : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \
+ : "=&d"(res), "=&c"(count), "=&a" (__d0), "=&S" (__d1), \
"=&D" (__d2) \
: "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
: "memory"); \
@@ -218,7 +218,7 @@ long strnlen_user(const char __user *s,
" .align 4\n"
" .long 0b,2b\n"
".previous"
- :"=r" (n), "=D" (s), "=a" (res), "=c" (tmp)
+ :"=&r" (n), "=&D" (s), "=&a" (res), "=&c" (tmp)
:"0" (n), "1" (s), "2" (0), "3" (mask)
:"cc");
return res & mask;
--- a/arch/x86/lib/usercopy_64.c
+++ b/arch/x86/lib/usercopy_64.c
@@ -32,7 +32,7 @@ do { \
" jmp 2b\n" \
".previous\n" \
_ASM_EXTABLE(0b,3b) \
- : "=r"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \
+ : "=&r"(res), "=&c"(count), "=&a" (__d0), "=&S" (__d1), \
"=&D" (__d2) \
: "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
: "memory"); \
@@ -86,7 +86,7 @@ unsigned long __clear_user(void __user *
".previous\n"
_ASM_EXTABLE(0b,3b)
_ASM_EXTABLE(1b,2b)
- : [size8] "=c"(size), [dst] "=&D" (__d0)
+ : [size8] "=&c"(size), [dst] "=&D" (__d0)
: [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
[zero] "r" (0UL), [eight] "r" (8UL));
return size;
next prev parent reply other threads:[~2009-02-04 18:39 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20090204182823.831027530@mini.kroah.org>
2009-02-04 18:34 ` [patch 00/33] 2.6.28-stable review Greg KH
2009-02-04 18:34 ` [patch 01/33] Manually revert "mlock: downgrade mmap sem while populating mlocked regions" Greg KH
2009-02-04 18:34 ` [patch 02/33] xen: make sysfs files behave as their names suggest Greg KH
2009-02-04 18:34 ` [patch 03/33] sata_mv: fix 8-port timeouts on 508x/6081 chips Greg KH
2009-02-04 18:34 ` [patch 04/33] m68knommu: set NO_DMA Greg KH
2009-02-04 18:34 ` [patch 05/33] PCI/MSI: bugfix/utilize for msi_capability_init() Greg KH
2009-02-04 18:34 ` Greg KH [this message]
2009-02-04 18:34 ` [patch 07/33] cifs: make sure we allocate enough storage for socket address Greg KH
2009-02-04 18:34 ` [patch 08/33] netfilter: ctnetlink: fix scheduling while atomic Greg KH
2009-02-04 18:34 ` [patch 09/33] orinoco: move kmalloc(..., GFP_KERNEL) outside spinlock in orinoco_ioctl_set_genie Greg KH
2009-02-04 18:34 ` [patch 10/33] fbdev/atyfb: Fix DSP config on some PowerMacs & PowerBooks Greg KH
2009-02-04 18:34 ` [patch 11/33] kmalloc: return NULL instead of link failure Greg KH
2009-02-04 18:34 ` [patch 12/33] sata_nv: rename nv_nf2_hardreset() Greg KH
2009-02-04 18:34 ` [patch 13/33] sata_nv: fix MCP5x reset Greg KH
2009-02-04 18:34 ` [patch 14/33] sata_nv: ck804 has borked hardreset too Greg KH
2009-02-04 18:34 ` [patch 15/33] Fix memory corruption in console selection Greg KH
2009-02-04 18:34 ` [patch 16/33] Add enable_ms to jsm driver Greg KH
2009-02-04 18:34 ` [patch 17/33] Input: atkbd - Samsung NC10 key repeat fix Greg KH
2009-02-04 18:34 ` [patch 18/33] nfsd: only set file_lock.fl_lmops in nfsd4_lockt if a stateowner is found Greg KH
2009-02-04 18:34 ` [patch 19/33] nfsd: Ensure nfsv4 calls the underlying filesystem on LOCKT Greg KH
2009-02-04 18:34 ` [patch 20/33] iwlwifi: fix rs_get_rate WARN_ON() Greg KH
2009-02-04 18:34 ` [patch 21/33] p54: fix lm87 checksum endianness Greg KH
2009-02-04 18:34 ` [patch 22/33] p54: fix p54_read_eeprom to cope with tx_hdr_len Greg KH
2009-02-04 18:35 ` [patch 23/33] p54usb: rewriting rx/tx routines to make use of usb_anchors facilities Greg KH
2009-02-04 18:35 ` [patch 24/33] minstrel: fix warning if lowest supported rate index is not 0 Greg KH
2009-02-04 18:35 ` [patch 25/33] PCI: irq and pci_ids patch for Intel Tigerpoint DeviceIDs Greg KH
2009-02-04 18:35 ` [patch 26/33] cpuidle: Add decaying history logic to menu idle predictor Greg KH
2009-02-04 18:35 ` [patch 27/33] ACPI: Avoid array address overflow when _CST MWAIT hint bits are set Greg KH
2009-02-04 18:35 ` [patch 28/33] video: always update the brightness when poking "brightness" Greg KH
2009-02-04 18:35 ` [patch 29/33] Newly inserted battery might differ from one just removed, so Greg KH
2009-02-04 18:35 ` [patch 30/33] ACPI: Do not modify SCI_EN directly Greg KH
2009-02-04 18:35 ` [patch 31/33] dlm: initialize file_lock struct in GETLK before copying conflicting lock Greg KH
2009-02-04 18:35 ` [patch 32/33] sata_mv: Fix chip type for Hightpoint RocketRaid 1740/1742 Greg KH
2009-02-04 18:35 ` [patch 33/33] ACPICA: Allow multiple backslash prefix in namepaths 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=20090204183427.GG13936@kroah.com \
--to=gregkh@suse.de \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=cavokz@gmail.com \
--cc=cebbert@redhat.com \
--cc=chuckw@quantumlinux.com \
--cc=davej@redhat.com \
--cc=eteo@redhat.com \
--cc=hpa@zytor.com \
--cc=jake@lwn.net \
--cc=jmforbes@linuxtx.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mkrufky@linuxtv.org \
--cc=rbranco@la.checkpoint.com \
--cc=rdunlap@xenotime.net \
--cc=reviews@ml.cw.f00f.org \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--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