From owner-freebsd-hackers@freebsd.org Mon Jan 22 18:55:27 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BA358ECFF07 for ; Mon, 22 Jan 2018 18:55:27 +0000 (UTC) (envelope-from lwhsu.freebsd@gmail.com) Received: from mail-wr0-x22d.google.com (mail-wr0-x22d.google.com [IPv6:2a00:1450:400c:c0c::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BA0468C73 for ; Mon, 22 Jan 2018 18:55:27 +0000 (UTC) (envelope-from lwhsu.freebsd@gmail.com) Received: by mail-wr0-x22d.google.com with SMTP id v15so6992451wrb.8 for ; Mon, 22 Jan 2018 10:55:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=+sxocHCKJsWnBI8P3FENjOP2lMCxh+amWgE3QCnnmuE=; b=V7AA7g5w2PixT8vNDZLBNiZAGF/jtLWe+i/pEuKq/4RaYUREpWSh+PBJxxn0bohH9A LfxxwHSDO8tJJlT2W+Sy9wrMyN8lta86xyGB/6o/wNRepYGBEDFs6qHMyvHyTGQZrkbE xTVsGZv+/o8pj7dpN8TU2O6MhgLS5g6cNj/3KR0hSC0LJRjbWKlZ3gXuI8xgjTD718Lx yECIQBFjxNo/e5weIQNwoUDGcw6szUMxOUSpwV6XZbNX2VL3vN9QIDRaI/KoeEGhVw2W +fBfyGQOtYlgldMKfVAVDkigB4eKQ7qLw5rj0O1Uyxe0sohYSE/vUCKmN8dH8Lq2mtB/ vLlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=+sxocHCKJsWnBI8P3FENjOP2lMCxh+amWgE3QCnnmuE=; b=cQScpjAD9AbrHv6kxBbA6lT2B4IHfBj234+lxjEzof2NemwY1Kofz5RtPKJrA1QsMK QLFe0Tt09EPHnxgf8tgIhmp1MgiKEDtx2vmJkmzMCpPRYnOANheLQAnpPFKeuWtW88OD vesQnFgm+nhwO6z3kygN5QZzZNFLgrOdILZM6TRBJ6+NmAclbOwQN/PX/C0KKQQHLg8v 53jEbFKX+Nfc/9vb9cfsxbv3ms0czzuWHMbpKNnNm1L0kOmgnjrtdg6PXOuT04KaBbER UsyRCYae9fWJJfDATIjJ6UOJ2W3TXIXf/IaWA0Tcv4JNmVCx/Nht1ArScKbyfDXFI6ZR /ojg== X-Gm-Message-State: AKwxytdriWHNRNBC0da0eKrmG5qnmHZaOumaW0Ftce/y6Zlt+6+8+MZi ueZ3OhQffipEiXd0FbJA5sbwdOVN1wss5qzTGpA= X-Google-Smtp-Source: AH8x224AwNwSCo2Ul6jN15hd8nHvW9FK6/I/tWpdnM4XrTy+d85zhyu7ltHB/x0/PgyJn4V+heNuZMVoLXxY5JNqnNI= X-Received: by 10.223.129.67 with SMTP id 61mr7219365wrm.271.1516647325534; Mon, 22 Jan 2018 10:55:25 -0800 (PST) MIME-Version: 1.0 Sender: lwhsu.freebsd@gmail.com Received: by 10.28.124.11 with HTTP; Mon, 22 Jan 2018 10:55:24 -0800 (PST) In-Reply-To: <20180122154709.GF55707@kib.kiev.ua> References: <8c6dc5b5-7640-61fc-b687-08efd1e621ee@icloud.com> <20180122154709.GF55707@kib.kiev.ua> From: Li-Wen Hsu Date: Tue, 23 Jan 2018 02:55:24 +0800 X-Google-Sender-Auth: FECnlbNzvbPRYIg4IZhkz0OuPZ4 Message-ID: Subject: Re: Calling getaddrinfo(3) in 32-bit binary on 64-bit host To: Konstantin Belousov Cc: Yuri Pankov , freebsd-hackers@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.25 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Jan 2018 18:55:27 -0000 On Mon, Jan 22, 2018 at 11:47 PM, Konstantin Belousov 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 https://lwhsu.org