md5sum makes unaligned word accesses...

Andre armcc2000 at yahoo.com
Fri May 12 08:56:05 UTC 2006


--- Mike Frysinger <vapier at gentoo.org> wrote:
> > On Thursday 11 May 2006 2:05 am, Andre wrote:
> > > Anyway, comparing the faulting PC with a disassembly of
> > > busybox, it looks like the fault happens in md5_hash_block()
> > >
> > > void md5_hash_block(const void *buffer, size_t len,
> > >                     md5_ctx_t *ctx)
> > > {
> > >     uint32_t correct_words[16];
> > >     const uint32_t *words = buffer;
> > >     ....
> > >
> > > Casting a void * to an unsigned int * is highly suspect unless
> > > all callers of md5_has_block() somehow know that 'buffer' has
> > > implicit alignment constraints...
> 
> considering there is only one caller of md5_has_block(), this is
> possible
> 

Currently, that one caller doesn't respect the constrains...

In md5_hash_bytes(), if ctx->buflen is non-zero, bytes are stolen
from the beginning of 'buffer' to create a complete hash block. Even
if 'buffer' is initially aligned, alignment is lost if the number of
bytes required to complete a previous hash block isn't a multiple of
4.

> or in md5_hash_block(), make use of posix_memalign()
> 

Allocating a bounce buffer in md5_hash_block() would be a solution if
md5_hash_block() really needs to be public (it used to be static in
1.1.0 ??) and potential callers can't be trusted to respect
alignment...

However, it might be less overhead to make md5_hash_block() static
again and then fixup alignment in md5_hash_bytes() - at the point
'buffer' becomes misaligned, ctx->buffer is empty and can therefore
be used as a bounce buffer without needing to allocate anything.

Andre
--



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the busybox mailing list