Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-26 Thread Andi Kleen
> Instead of barrier(), this works with gcc-3.2.3 up to gcc-4.4.3 > for the purpose of making the memset() not disappear: > > { > struct s { char c[n]; }; > asm("" : : "m"(*(struct s *)p)); > } > > Every byte in the [p,p+n[ range must be used. If you only u

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-26 Thread Mikael Pettersson
Mikael Pettersson writes: > Andi Kleen writes: > > roel kluin writes: > > > > >> And it's wrong because the reason the memset() is there seems to be > > >> to clear out key information that might exist kernel stack so that > > >> it's more difficult for rogue code to get at things. >

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-26 Thread Mikael Pettersson
Andi Kleen writes: > roel kluin writes: > > >> And it's wrong because the reason the memset() is there seems to be > >> to clear out key information that might exist kernel stack so that > >> it's more difficult for rogue code to get at things. > > > > If the memset is optimized away then

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-26 Thread Andi Kleen
roel kluin writes: >> And it's wrong because the reason the memset() is there seems to be >> to clear out key information that might exist kernel stack so that >> it's more difficult for rogue code to get at things. > > If the memset is optimized away then the clear out does not occur. Do you > k

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread Roel Kluin
> Also from that document: > > If you know how large the accessed memory is, you can add it as input or > output but if this is not known, you should add memory. As an example, if > you access ten bytes of a string, you can use a memory input like: > > {"m"( ({ struct { char x[10]; } *p = (v

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread Roel Kluin
Op 25-02-10 18:32, Brian Gerst schreef: > On Thu, Feb 25, 2010 at 12:09 PM, Mikael Pettersson wrote: >> Brian Gerst wrote: >>> Would barrier() (which is a simple memory clobber) after the memset work? >> >> I don't know. It's implemented as an asm with a "memory" clobber, >> but I wouldn't bet on

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread Brian Gerst
On Thu, Feb 25, 2010 at 10:56 AM, Mikael Pettersson wrote: > Roel Kluin writes: >  > Due to optimization A call to memset() may be removed as a dead store when >  > the buffer is not used after its value is overwritten. >  > >  > Signed-off-by: Roel Kluin >  > --- >  > see http://cwe.mitre.org/da

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread roel kluin
On Thu, Feb 25, 2010 at 5:16 PM, Pekka Enberg wrote: > On Thu, Feb 25, 2010 at 5:56 PM, Mikael Pettersson wrote: >> I fear that the only portable (across compiler versions) and safe >> solution is to invoke an assembly-coded dummy function with prototype >> >>        void use(void *p); >> >> and

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread Mikael Pettersson
Pekka Enberg writes: > On Thu, Feb 25, 2010 at 5:56 PM, Mikael Pettersson wrote: > > I fear that the only portable (across compiler versions) and safe > > solution is to invoke an assembly-coded dummy function with prototype > > > >        void use(void *p); > > > > and rewrite the code abo

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread Pekka Enberg
On Thu, Feb 25, 2010 at 5:56 PM, Mikael Pettersson wrote: > I fear that the only portable (across compiler versions) and safe > solution is to invoke an assembly-coded dummy function with prototype > >        void use(void *p); > > and rewrite the code above as > >        { >                u32 te

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread Mikael Pettersson
Roel Kluin writes: > Due to optimization A call to memset() may be removed as a dead store when > the buffer is not used after its value is overwritten. > > Signed-off-by: Roel Kluin > --- > see http://cwe.mitre.org/data/slices/2000.html#14 > > checkpatch.pl, compile and sparse tested. C

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread David Miller
From: roel kluin Date: Thu, 25 Feb 2010 16:31:36 +0100 > On Thu, Feb 25, 2010 at 4:17 PM, David Miller wrote: >> From: Roel Kluin >> Date: Thu, 25 Feb 2010 16:10:27 +0100 >> >>> Due to optimization A call to memset() may be removed as a dead store when >>> the buffer is not used after its value

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread roel kluin
On Thu, Feb 25, 2010 at 4:17 PM, David Miller wrote: > From: Roel Kluin > Date: Thu, 25 Feb 2010 16:10:27 +0100 > >> Due to optimization A call to memset() may be removed as a dead store when >> the buffer is not used after its value is overwritten. >> >> Signed-off-by: Roel Kluin > > Solution i

Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread David Miller
From: Roel Kluin Date: Thu, 25 Feb 2010 16:10:27 +0100 > Due to optimization A call to memset() may be removed as a dead store when > the buffer is not used after its value is overwritten. > > Signed-off-by: Roel Kluin Solution is wrong and overkill in my mind. It's overkill because the whole

[PATCH] sha: prevent removal of memset as dead store in sha1_update()

2010-02-25 Thread Roel Kluin
Due to optimization A call to memset() may be removed as a dead store when the buffer is not used after its value is overwritten. Signed-off-by: Roel Kluin --- see http://cwe.mitre.org/data/slices/2000.html#14 checkpatch.pl, compile and sparse tested. Comments? diff --git a/crypto/sha1_generic.