stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Nathan Chancellor <natechancellor@gmail.com>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	stable@kernel.org, Will Deacon <will.deacon@arm.com>
Subject: Re: [PATCH 4.9 72/76] arm64: futex: Fix FUTEX_WAKE_OP atomic ops with non-zero result value
Date: Wed, 17 Apr 2019 08:47:31 +0200	[thread overview]
Message-ID: <20190417064731.GB19549@kroah.com> (raw)
In-Reply-To: <20190417064153.GA14656@archlinux-i9>

On Tue, Apr 16, 2019 at 11:41:53PM -0700, Nathan Chancellor wrote:
> On Wed, Apr 17, 2019 at 08:15:08AM +0200, Greg Kroah-Hartman wrote:
> > On Tue, Apr 16, 2019 at 09:47:51AM -0700, Nathan Chancellor wrote:
> > > On Tue, Apr 16, 2019 at 11:00:52AM +0200, Greg Kroah-Hartman wrote:
> > > > On Mon, Apr 15, 2019 at 03:01:51PM -0700, Nathan Chancellor wrote:
> > > > > On Mon, Apr 15, 2019 at 08:44:36PM +0200, Greg Kroah-Hartman wrote:
> > > > > > From: Will Deacon <will.deacon@arm.com>
> > > > > > 
> > > > > > commit 045afc24124d80c6998d9c770844c67912083506 upstream.
> > > > > > 
> > > > > > Rather embarrassingly, our futex() FUTEX_WAKE_OP implementation doesn't
> > > > > > explicitly set the return value on the non-faulting path and instead
> > > > > > leaves it holding the result of the underlying atomic operation. This
> > > > > > means that any FUTEX_WAKE_OP atomic operation which computes a non-zero
> > > > > > value will be reported as having failed. Regrettably, I wrote the buggy
> > > > > > code back in 2011 and it was upstreamed as part of the initial arm64
> > > > > > support in 2012.
> > > > > > 
> > > > > > The reasons we appear to get away with this are:
> > > > > > 
> > > > > >   1. FUTEX_WAKE_OP is rarely used and therefore doesn't appear to get
> > > > > >      exercised by futex() test applications
> > > > > > 
> > > > > >   2. If the result of the atomic operation is zero, the system call
> > > > > >      behaves correctly
> > > > > > 
> > > > > >   3. Prior to version 2.25, the only operation used by GLIBC set the
> > > > > >      futex to zero, and therefore worked as expected. From 2.25 onwards,
> > > > > >      FUTEX_WAKE_OP is not used by GLIBC at all.
> > > > > > 
> > > > > > Fix the implementation by ensuring that the return value is either 0
> > > > > > to indicate that the atomic operation completed successfully, or -EFAULT
> > > > > > if we encountered a fault when accessing the user mapping.
> > > > > > 
> > > > > > Cc: <stable@kernel.org>
> > > > > > Fixes: 6170a97460db ("arm64: Atomic operations")
> > > > > > Signed-off-by: Will Deacon <will.deacon@arm.com>
> > > > > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > > > > 
> > > > > > ---
> > > > > >  arch/arm64/include/asm/futex.h |   16 ++++++++--------
> > > > > >  1 file changed, 8 insertions(+), 8 deletions(-)
> > > > > > 
> > > > > > --- a/arch/arm64/include/asm/futex.h
> > > > > > +++ b/arch/arm64/include/asm/futex.h
> > > > > > @@ -33,8 +33,8 @@
> > > > > >  "	prfm	pstl1strm, %2\n"					\
> > > > > >  "1:	ldxr	%w1, %2\n"						\
> > > > > >  	insn "\n"							\
> > > > > > -"2:	stlxr	%w3, %w0, %2\n"						\
> > > > > > -"	cbnz	%w3, 1b\n"						\
> > > > > > +"2:	stlxr	%w0, %w3, %2\n"						\
> > > > > > +"	cbnz	%w0, 1b\n"						\
> > > > > >  "	dmb	ish\n"							\
> > > > > >  "3:\n"									\
> > > > > >  "	.pushsection .fixup,\"ax\"\n"					\
> > > > > > @@ -53,29 +53,29 @@
> > > > > >  static inline int
> > > > > >  arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
> > > > > >  {
> > > > > > -	int oldval = 0, ret, tmp;
> > > > > > +	int oldval, ret, tmp;
> > > > > >  
> > > > > >  	pagefault_disable();
> > > > > >  
> > > > > >  	switch (op) {
> > > > > >  	case FUTEX_OP_SET:
> > > > > > -		__futex_atomic_op("mov	%w0, %w4",
> > > > > > +		__futex_atomic_op("mov	%w3, %w4",
> > > > > >  				  ret, oldval, uaddr, tmp, oparg);
> > > > > >  		break;
> > > > > >  	case FUTEX_OP_ADD:
> > > > > > -		__futex_atomic_op("add	%w0, %w1, %w4",
> > > > > > +		__futex_atomic_op("add	%w3, %w1, %w4",
> > > > > >  				  ret, oldval, uaddr, tmp, oparg);
> > > > > >  		break;
> > > > > >  	case FUTEX_OP_OR:
> > > > > > -		__futex_atomic_op("orr	%w0, %w1, %w4",
> > > > > > +		__futex_atomic_op("orr	%w3, %w1, %w4",
> > > > > >  				  ret, oldval, uaddr, tmp, oparg);
> > > > > >  		break;
> > > > > >  	case FUTEX_OP_ANDN:
> > > > > > -		__futex_atomic_op("and	%w0, %w1, %w4",
> > > > > > +		__futex_atomic_op("and	%w3, %w1, %w4",
> > > > > >  				  ret, oldval, uaddr, tmp, ~oparg);
> > > > > >  		break;
> > > > > >  	case FUTEX_OP_XOR:
> > > > > > -		__futex_atomic_op("eor	%w0, %w1, %w4",
> > > > > > +		__futex_atomic_op("eor	%w3, %w1, %w4",
> > > > > >  				  ret, oldval, uaddr, tmp, oparg);
> > > > > >  		break;
> > > > > >  	default:
> > > > > > 
> > > > > >
> > > > > 
> > > > > This causes a (false) build warning with AOSP's GCC 4.9.4 (which is
> > > > > used to build nearly all arm64 Android kernels before 4.14):
> > > > > 
> > > > >   CC      kernel/futex.o
> > > > > ../kernel/futex.c: In function 'do_futex':
> > > > > ../kernel/futex.c:1492:17: warning: 'oldval' may be used uninitialized in this function [-Wmaybe-uninitialized]
> > > > >    return oldval == cmparg;
> > > > >                  ^
> > > > > In file included from ../kernel/futex.c:69:0:
> > > > > ../arch/arm64/include/asm/futex.h:56:6: note: 'oldval' was declared here
> > > > >   int oldval, ret, tmp;
> > > > >       ^
> > > > > 
> > > > > The only reason I bring this up is Qualcomm based kernels have a Python
> > > > > script that emulates -Werror, meaning this will be fatal for a large
> > > > > number of kernels, when this eventually gets merged into them.
> > > > 
> > > > Argh, really?  That's a buggy compiler that you have there, as oldval
> > > > will be set correctly if all is good, and if not, ret will be and the
> > > > code will error out.
> > > > 
> > > 
> > > Correct.
> > > 
> > > > Working around broken compilers is not something I really like doing :(
> > > > 
> > > 
> > > Indeed, I wouldn't have brought it up if it wasn't the compiler for all
> > > Android 4.9 kernels aside from the Pixel 3 (XL).
> > > 
> > > > That being said, does this also show up in the 4.19.y and 5.0.y tree
> > > > right now?  If not, why not?
> > > > 
> > > 
> > > It does.
> > > 
> > > $ make ARCH=arm64 CROSS_COMPILE=<path>/bin/aarch64-linux-gnu- defconfig kernel/futex.o
> > 
> > Great, so it seems this needs to be fixed in Linus's tree first, before
> > I can backport it everywhere.
> > 
> 
> Well, is it worth working around this in Linus's tree? I know you hate
> taking patches just for stable but this compiler won't be used on 4.14+
> according to [1] and support for it is planned to be discontinued in
> less than a year [2]. This warning doesn't happen with Clang or newer
> versions of GCC (I tested 6.3 in a Debian Docker image, which seems to
> be the oldest I can find). I suppose there could be other buggy/ancient
> compilers to work around...

Yes it is worth it, I do not take fixes that are not in Linus's tree,
otherwise we will have major problems over time.

As this is a valid compiler version to be using for 5.0+, it should be
fixed upstream first.

thanks,

greg k-h

  reply	other threads:[~2019-04-17  6:47 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-15 18:43 [PATCH 4.9 00/76] 4.9.169-stable review Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 01/76] x86/power: Fix some ordering bugs in __restore_processor_context() Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 02/76] x86/power/64: Use struct desc_ptr for the IDT in struct saved_context Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 03/76] x86/power/32: Move SYSENTER MSR restoration to fix_processor_context() Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 04/76] x86/power: Make restore_processor_context() sane Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 05/76] powerpc/tm: Limit TM code inside PPC_TRANSACTIONAL_MEM Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 06/76] kbuild: clang: choose GCC_TOOLCHAIN_DIR not on LD Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 07/76] x86: vdso: Use $LD instead of $CC to link Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 08/76] x86/vdso: Drop implicit common-page-size linker flag Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 09/76] lib/string.c: implement a basic bcmp Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 10/76] powerpc: Fix invalid use of register expressions Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 11/76] powerpc/64s: Add barrier_nospec Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 12/76] powerpc/64s: Add support for ori barrier_nospec patching Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 13/76] powerpc: Avoid code patching freed init sections Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 14/76] powerpc/64s: Patch barrier_nospec in modules Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 15/76] powerpc/64s: Enable barrier_nospec based on firmware settings Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 16/76] powerpc: Use barrier_nospec in copy_from_user() Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 17/76] powerpc/64: Use barrier_nospec in syscall entry Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 18/76] powerpc/64s: Enhance the information in cpu_show_spectre_v1() Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 19/76] powerpc64s: Show ori31 availability in spectre_v1 sysfs file not v2 Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 20/76] powerpc/64: Disable the speculation barrier from the command line Greg Kroah-Hartman
2019-04-16 15:43   ` Diana Madalina Craciun
2019-04-16 18:46     ` Greg Kroah-Hartman
2019-04-17  8:41     ` Michael Ellerman
2019-04-15 18:43 ` [PATCH 4.9 21/76] powerpc/64: Make stf barrier PPC_BOOK3S_64 specific Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 22/76] powerpc/64: Add CONFIG_PPC_BARRIER_NOSPEC Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 23/76] powerpc/64: Call setup_barrier_nospec() from setup_arch() Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 24/76] powerpc/64: Make meltdown reporting Book3S 64 specific Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 25/76] powerpc/fsl: Add barrier_nospec implementation for NXP PowerPC Book3E Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 26/76] powerpc/fsl: Sanitize the syscall table for NXP PowerPC 32 bit platforms Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 27/76] powerpc/asm: Add a patch_site macro & helpers for patching instructions Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 28/76] powerpc/64s: Add new security feature flags for count cache flush Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 29/76] powerpc/64s: Add support for software " Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 30/76] powerpc/pseries: Query hypervisor for count cache flush settings Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 31/76] powerpc/powernv: Query firmware " Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 32/76] powerpc/fsl: Add infrastructure to fixup branch predictor flush Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 33/76] powerpc/fsl: Add macro to flush the branch predictor Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 34/76] powerpc/fsl: Fix spectre_v2 mitigations reporting Greg Kroah-Hartman
2019-04-15 18:43 ` [PATCH 4.9 35/76] powerpc/fsl: Emulate SPRN_BUCSR register Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 36/76] powerpc/fsl: Add nospectre_v2 command line argument Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 37/76] powerpc/fsl: Flush the branch predictor at each kernel entry (64bit) Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 38/76] powerpc/fsl: Flush the branch predictor at each kernel entry (32 bit) Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 39/76] powerpc/fsl: Flush branch predictor when entering KVM Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 40/76] powerpc/fsl: Enable runtime patching if nospectre_v2 boot arg is used Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 41/76] powerpc/fsl: Update Spectre v2 reporting Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 42/76] powerpc/fsl: Fixed warning: orphan section `__btb_flush_fixup Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 43/76] powerpc/fsl: Fix the flush of branch predictor Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 44/76] powerpc/security: Fix spectre_v2 reporting Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 45/76] arm64: kaslr: Reserve size of ARM64_MEMSTART_ALIGN in linear region Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 46/76] tty: mark Siemens R3964 line discipline as BROKEN Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 47/76] tty: ldisc: add sysctl to prevent autoloading of ldiscs Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 48/76] ipv6: Fix dangling pointer when ipv6 fragment Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 49/76] ipv6: sit: reset ip header pointer in ipip6_rcv Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 50/76] kcm: switch order of device registration to fix a crash Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 51/76] net: rds: force to destroy connection if t_sock is NULL in rds_tcp_kill_sock() Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 52/76] openvswitch: fix flow actions reallocation Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 53/76] qmi_wwan: add Olicard 600 Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 54/76] sctp: initialize _pad of sockaddr_in before copying to user memory Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 55/76] tcp: Ensure DCTCP reacts to losses Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 56/76] vrf: check accept_source_route on the original netdevice Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 57/76] bnxt_en: Reset device on RX buffer errors Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 58/76] bnxt_en: Improve RX consumer index validity check Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 59/76] net/mlx5e: Add a lock on tir list Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 60/76] netns: provide pure entropy for net_hash_mix() Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 61/76] net: ethtool: not call vzalloc for zero sized memory request Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 62/76] ip6_tunnel: Match to ARPHRD_TUNNEL6 for dev type Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 63/76] ALSA: seq: Fix OOB-reads from strlcpy Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 64/76] parisc: Detect QEMU earlier in boot process Greg Kroah-Hartman
2019-04-16 13:50   ` Helge Deller
2019-04-16 14:23     ` Greg Kroah-Hartman
2019-04-16 15:00       ` Helge Deller
2019-04-16 18:03         ` Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 65/76] include/linux/bitrev.h: fix constant bitrev Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 66/76] ASoC: fsl_esai: fix channel swap issue when stream starts Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 67/76] Btrfs: do not allow trimming when a fs is mounted with the nologreplay option Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 68/76] block: do not leak memory in bio_copy_user_iov() Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 69/76] genirq: Respect IRQCHIP_SKIP_SET_WAKE in irq_chip_set_wake_parent() Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 70/76] virtio: Honour may_reduce_num in vring_create_virtqueue Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 71/76] ARM: dts: at91: Fix typo in ISC_D0 on PC9 Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 72/76] arm64: futex: Fix FUTEX_WAKE_OP atomic ops with non-zero result value Greg Kroah-Hartman
2019-04-15 22:01   ` Nathan Chancellor
2019-04-16  9:00     ` Greg Kroah-Hartman
2019-04-16 16:47       ` Nathan Chancellor
2019-04-17  6:15         ` Greg Kroah-Hartman
2019-04-17  6:41           ` Nathan Chancellor
2019-04-17  6:47             ` Greg Kroah-Hartman [this message]
2019-04-16  9:13     ` Will Deacon
2019-04-16 16:49       ` Nathan Chancellor
2019-04-15 18:44 ` [PATCH 4.9 73/76] xen: Prevent buffer overflow in privcmd ioctl Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 74/76] sched/fair: Do not re-read ->h_load_next during hierarchical load calculation Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 75/76] xtensa: fix return_address Greg Kroah-Hartman
2019-04-15 18:44 ` [PATCH 4.9 76/76] PCI: Add function 1 DMA alias quirk for Marvell 9170 SATA controller Greg Kroah-Hartman
2019-04-16  0:44 ` [PATCH 4.9 00/76] 4.9.169-stable review kernelci.org bot
2019-04-16  4:06 ` Naresh Kamboju
2019-04-16 10:33 ` Jon Hunter
2019-04-16 13:12 ` Guenter Roeck
2019-04-16 16:29 ` Guenter Roeck
2019-04-16 18:46   ` Greg Kroah-Hartman
2019-04-16 20:19     ` Guenter Roeck
2019-04-16 20:27       ` Greg Kroah-Hartman
2019-04-16 21:39 ` shuah
2019-04-16 22:05 ` Bharath Vedartham

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=20190417064731.GB19549@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=natechancellor@gmail.com \
    --cc=stable@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=will.deacon@arm.com \
    /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).