Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jan 2018 02:55:24 +0800
From:      Li-Wen Hsu <lwhsu@freebsd.org>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Yuri Pankov <yuripv@icloud.com>, freebsd-hackers@freebsd.org
Subject:   Re: Calling getaddrinfo(3) in 32-bit binary on 64-bit host
Message-ID:  <CAKBkRUz6vt_ynoENce%2BL6G05O4vjS4Z31Cq4wG6px1KMJQDCew@mail.gmail.com>
In-Reply-To: <20180122154709.GF55707@kib.kiev.ua>
References:  <CAKBkRUx14r%2B%2BZ-n64SNDd4uu=hoJv-KaXxeyUGM7f%2BDS2Ha%2BmQ@mail.gmail.com> <8c6dc5b5-7640-61fc-b687-08efd1e621ee@icloud.com> <20180122154709.GF55707@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 22, 2018 at 11:47 PM, Konstantin Belousov <kostikbel@gmail.com>
wrote:

> On Mon, Jan 22, 2018 at 02:33:12AM +0300, Yuri Pankov wrote:
> > On Mon, Jan 22, 2018 at 05:14:59AM +0800, Li-Wen Hsu wrote:
> > > Hi all,
> > >
> > > Recently I found a strange case: calling getaddrinfo(3) cannot resolve
> IPv6
> > > address in 32-bit binary on 64-bit host.
> > > It happens on vanilla installed 11.1-R and also on r327788 snapshot
> build.
> > >
> > > For a program like this:
> > > https://gist.github.com/lwhsu/1288aa5be90b9e7da934a3e2bfc55aa3
> > >
> > > It works fine when compiled as a 32-bit binary and run on a 32-bit
> host.
> > > As expected, It is also works fine when compiled as a 64-bit binary
> and run
> > > on a 64-bit host
> > >
> > > However, when taking the 32-bit binary and run on a 64 bit system (with
> > > /usr/lib32 installed),
> > > getaddrinfo(3) just returns: "Non-recoverable failure in name
> resolution"
> >
> > Apparently, it goes through addrconfig() down to getifaddrs() returning
> > bogus data for IPv6 addresses.  This most likely has to with SALIGN
> > being incorrect for 32-bit binary trying to parse route messages from
> > 64-bit kernel.  I'm not sure about proper fix here, but changing SALIGN
> > to be 7 (that is, "sizeof(long) - 1" on amd64 platform) makes your test
> > case return correct data.
>
> Thank you for the diagnostic.  The following worked for me.
> Most likely there are may be more issues, since there are more SA_SIZE()
> uses from sysctl context. Also, it is probably impossible to provide
> COMPAT32 for rtsock itself.
>

Also thanks Yuri for the diagnostic.  Just be curious, did you find this
out by looking at the code or with some other tools?  Another thing I don't
understand is why gdb desn't step into getaddrinfo.c in compat32 mode.

Thanks Konstantin for fixing this.  I've also tested and it works here.

I'll try to find other uses of SA_SIZE() and see if they would be run in
compat32 mode and works or not.

Best,
Li-Wen

-- 
Li-Wen Hsu <lwhsu@FreeBSD.org>
https://lwhsu.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAKBkRUz6vt_ynoENce%2BL6G05O4vjS4Z31Cq4wG6px1KMJQDCew>