sshd broken on arm?

John Hay jhay at meraka.org.za
Thu Jan 24 20:15:45 PST 2008


> >
> >The problem is that the char array isn't guaranteed to be aligned in
> >any way.  The fix posted is correct.
> >
> >There may be other fixes too, such as using a union to force
> >alignment.
> 
> Well I'm sort of puzzled right now since after preprocessing the 
> variable allocation part boils down to:
> =====
>  struct msghdr msg;
>  struct iovec vec;
>  char ch = '\0';
>  ssize_t n;
> 
>  char tmp[((((unsigned)(sizeof(struct cmsghdr)) + (sizeof(int) - 1)) & 
> ~(sizeof(int) - 1)) + (((unsigned)(sizeof(int)) + (sizeof(int
> ) - 1)) & ~(sizeof(int) - 1)))];
>  struct cmsghdr *cmsg;
> =====
> So as far as I can see is char tmp[] included between 2 4-byte items and 
>  allocation should be "automagically" 4-byte aligned.
> 
> Now adding simple code like tmp[0] = 50, the first part of the assembly 
> is: (Comments are mine for as far as I can grasp them)

Just doing tmp[0] = 50 will cause a byte access which should not be a
problem. The original code does something like this (simplified):

char tmp[CMSG_SPACE(sizeof(int))];
int *ti;

ti = tmp;
*ti = 50;

Now the 50 is an int and not a byte and then the alignment does matter.

John
-- 
John Hay -- John.Hay at meraka.csir.co.za / jhay at FreeBSD.org


More information about the freebsd-arm mailing list