Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Jan 2008 06:15:40 +0200
From:      John Hay <jhay@meraka.org.za>
To:        Willem Jan Withagen <wjw@digiware.nl>
Cc:        des@des.no, freebsd-arm@freebsd.org
Subject:   Re: sshd broken on arm?
Message-ID:  <20080125041540.GA30262@zibbi.meraka.csir.co.za>
In-Reply-To: <47991E08.6070609@digiware.nl>
References:  <479880A7.1030107@digiware.nl> <20080124.084828.1608359032.imp@bsdimp.com> <864pd386mj.fsf@ds4.des.no> <20080124.110954.179240992.imp@bsdimp.com> <47991E08.6070609@digiware.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
> >
> >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@meraka.csir.co.za / jhay@FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080125041540.GA30262>