lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <201106211325.16777.arnd@arndb.de>
Date:	Tue, 21 Jun 2011 13:25:16 +0200
From:	Arnd Bergmann <arnd@...db.de>
To:	Nicolas Pitre <nico@...xnic.net>
Cc:	"Russell King - ARM Linux" <linux@....linux.org.uk>,
	linux-arm-kernel@...ts.infradead.org,
	Alan Stern <stern@...land.harvard.edu>,
	linux-usb@...r.kernel.org, gregkh@...e.de,
	lkml <linux-kernel@...r.kernel.org>,
	Rabin Vincent <rabin@....in>,
	Alexander Holler <holler@...oftware.de>
Subject: Re: [PATCH] USB: ehci: use packed,aligned(4) instead of removing the packed attribute

On Tuesday 21 June 2011, Nicolas Pitre wrote:
> On Mon, 20 Jun 2011, Arnd Bergmann wrote:

> This example is flawed. The DMA API documentation already forbids DMA to 
> the stack because of cache line sharing issues.  If you declare your 
> buffer outside of the function body, the compiler can't optimize away 
> the buffer store anymore, and this example works as expected without any 
> memory clobber.

Ok, another example, even simpler:

int f(int *dma_buf, volatile int *mmio_reg)
{
        (void) *mmio_reg; /* wait for DMA to complete */
        return *dma_buf;
}


gcc-4.4, 4.5 and 4.6 all turn this into:

        ldr     r0, [r0, #0]
        ldr     r3, [r1, #0]
        bx      lr

which means that the dma_buf variable is dereferenced before the
volatile mmio_reg variable, which opens up a race: An interrupt may have
signalled us that a DMA is in progress, so we read a MMIO register from
the device (this is guaranteed to flush the DMA on PCI and similar buses).
If we read the dma_buf before we read the mmio register, the data we get
back may be stale.

Adding a barrier() between the two turns the assembly into the expected

        ldr     r3, [r1, #0]
        ldr     r0, [r0, #0]
        bx      lr


	Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ