From nobody Wed Apr 26 17:57:43 2023 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q666265fmz474h9 for ; Wed, 26 Apr 2023 17:57:46 +0000 (UTC) (envelope-from zirias@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q66625hJNz3vnV for ; Wed, 26 Apr 2023 17:57:46 +0000 (UTC) (envelope-from zirias@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682531866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=PFrw3aJWs6tqZSguG7kZQzJzH7zqXLLDPBjDlU/0ks8=; b=ItifaYH1+51zrD/qQc/LoEiuEkQEnNn9I5gpi2iphNeJpYcbnbIRG/zr1bd+QAuqjm/HN5 QoZLmMmS2hBCa5sbdipDNIyF85Bao4zmj5QJT3i3s0O+JiCsqYxVy6+7ZMKnmDuhDVi4VM OrJ74iZ30Zmd+IeavbipZvd59nYoteKEVl3Vxjpwqx+yyb3fji+L66tgc1O9jY+A/Q2gum 7A+qDSDufVXJMdZgBHBtjs/1SCpOZFxmNz3Gz9TT639+7FJ6PW70PU9Wo4K1yf/FTP+LxA lmE2BG+ihM9QwdXn3nukXpdWfMEF97lImkKW8ooP7hcpvfHlNf9D8e2lhLXK+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682531866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: dkim-signature; bh=PFrw3aJWs6tqZSguG7kZQzJzH7zqXLLDPBjDlU/0ks8=; b=ByrgvMgxI+BGvgJ3IVXbqfwqIXtNxGnRTuPV5Udfa0xSDxifBv1ca8sY9f2wtYiqEcLfPN LqbERuYF9IjUOhAw7Xn698aj920jqDDoPIVt/L3cvH15H1+AHTfy/xM1jqY58OIlYdLNfD yT0p2SbaxdQX3coOTW8NiGmTncjdx31v1VklExJAYXKZ2kNSw4A9NgBsKy7RBjXLZpHrBB p6hUXMHRok6DEt0949uf4e4C8Lt20UFMOBWHJheBI/wn6dc/uiUeIcno3z4PrrXvTpPyND VWmvEVXDhOn7TsUjAEWyVaBysdOMcYsOQfT7GBX9rAhKoilNK8TjLDvgaOvN5A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682531866; a=rsa-sha256; cv=none; b=CPjLGiIvOG7U3Ze9+My9w/YJ0Ciy0JjVHFzzhHlQn1yDmHGugGh9d4jWbCNtLWVrzCJqvY ty9DThpxfIa9fQd1Fq398MMTA/oBSon6mu5CB9GLzkeD4YvHcaDtVk71A/9R2rJ1HwnnaF da5s6s7vRQQeCU5uSR84kb2jk63W8yoWzjy4p5qS3gqoRyj7xXR1gIF6NWGzw9Zu/5s9AY /96hDPy07+KMa0vAVfemMKG4DdZ9CwdwFUTx4dhZRM4sb6Kc490e1buD5wDsC2IStYPtSo tN5+4pj5Af8swld+Js9F+LE4uuI17R30ZCXVk8HvtKKWRzwDx4hZfpchM1wQjw== Received: from stef.palmen-it.de (stef.palmen-it.de [IPv6:2001:470:1f0b:bbb:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: zirias/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4Q66624cr7zh2k for ; Wed, 26 Apr 2023 17:57:46 +0000 (UTC) (envelope-from zirias@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=palmen-it.de; s=20200414; h=Content-Type:MIME-Version:Message-ID:Subject:To :From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=PFrw3aJWs6tqZSguG7kZQzJzH7zqXLLDPBjDlU/0ks8=; b=zDsXYGFP6VPZMENTAPUxtoqle8 0xw6I5RHy0dqzoadeGPb/WOkTu/1Zw/+gqbqA9sMSUBBi6t703Z2kwlabhf8bhz9YjdzQn/jCynhX AJVEiXDNXVT3ehC57tF60g+6J5WS5fJ4gS9DGR4AtGP0jirXe2gD2ZVrd/jgMD7tb1qHo6OrDyLNK 1opnWsMMvqWkOaqUWqs2dteydO7su/Pk9grC/8B+esaEuDnTsHUeUDSemvOGlt2c3j4blnMc6JqPD VqphQmMq4Nki/XiMu+Xie3Vvy4kY9uORnvvEUuXbEImEbhxzikt22tMnu+zJSxFi3CFXSXPHZXWF3 NwL7s1Ew==; Received: from [192.168.71.101] (helo=mail.home.palmen-it.de) by stef.palmen-it.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1prjOi-006B1m-QQ for freebsd-hackers@FreeBSD.org; Wed, 26 Apr 2023 19:57:44 +0200 Received: from nexus.home.palmen-it.de ([192.168.99.2]) by mail.home.palmen-it.de with esmtpsa (TLS1.3) tls TLS_CHACHA20_POLY1305_SHA256 (Exim 4.95 (FreeBSD)) (envelope-from ) id 1prjOh-000CRY-IL for freebsd-hackers@FreeBSD.org; Wed, 26 Apr 2023 17:57:43 +0000 Date: Wed, 26 Apr 2023 19:57:43 +0200 From: Felix Palmen To: freebsd-hackers@FreeBSD.org Subject: Thread safety of getaddrinfo()/getnameinfo() Message-ID: Mail-Followup-To: freebsd-hackers@FreeBSD.org X-Face: /1K@t"h.}e~pR@]c7HorQ!T`F^RJCa'BCr#e>IKA{>C/9OTGB4|xh"y2{?1Z5M i2w"AH^pN_LlHR^{+f',_Np~;.B;!M/bL}*qk]p5*r7F5vW};{:@4u5S?T&f0$7BJ-71Q5SV]:v$`5 A0[DZ:=?S52x8HJ~5@^P_\T@MsjG{R( Organization: FreeBSD.org List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="d4ydqeqillcdqll3" Content-Disposition: inline User-Agent: NeoMutt/20230322 X-ThisMailContainsUnwantedMimeParts: N --d4ydqeqillcdqll3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi all, if I'm not mistaken, POSIX says getaddrinfo() and getnameinfo() should be thread-safe. Consider this silly test code: #v+ #include #include #include #include struct data { const char *hostname; struct addrinfo *res; }; struct data threaddat[5] =3D { { "www.freebsd.org", 0 }, { "www.google.com", 0 }, { "www.freshports.org", 0 }, { "www.github.com", 0 }, { "www.kernel.org", 0 } }; pthread_t threads[5]; void *resolve(void *d) { struct data *data =3D d; getaddrinfo(data->hostname, 0, 0, &data->res); return 0; } int main(void) { int i; for (i =3D 0; i < 5; ++i) { pthread_create(&threads[i], 0, resolve, &threaddat[i]); } for (i =3D 0; i < 5; ++i) { pthread_join(threads[i], 0); freeaddrinfo(threaddat[i].res); } return 0; } #v- Running it through `valgrind --tool=3Dhelgrind` on 13.2-RELEASE produces lots of these errors: #v+ =3D=3D60960=3D=3D Possible data race during write of size 4 at 0x4A757E4 by= thread #5 =3D=3D60960=3D=3D Locks held: none =3D=3D60960=3D=3D at 0x4993391: __h_errno_set (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x4968F9E: ??? (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x496854E: ??? (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x4978E1C: nsdispatch (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x496694C: ??? (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x49664EA: getaddrinfo (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x201A2E: resolve (resolvtest.c:23) =3D=3D60960=3D=3D by 0x485E066: ??? (in /usr/local/libexec/valgrind/vgpr= eload_helgrind-amd64-freebsd.so) =3D=3D60960=3D=3D by 0x4871A79: ??? (in /lib/libthr.so.3) =3D=3D60960=3D=3D=20 =3D=3D60960=3D=3D This conflicts with a previous write of size 4 by thread = #6 =3D=3D60960=3D=3D Locks held: none =3D=3D60960=3D=3D at 0x4993391: __h_errno_set (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x496841F: ??? (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x4978E1C: nsdispatch (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x496694C: ??? (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x49664EA: getaddrinfo (in /lib/libc.so.7) =3D=3D60960=3D=3D by 0x201A2E: resolve (resolvtest.c:23) =3D=3D60960=3D=3D by 0x485E066: ??? (in /usr/local/libexec/valgrind/vgpr= eload_helgrind-amd64-freebsd.so) =3D=3D60960=3D=3D by 0x4871A79: ??? (in /lib/libthr.so.3) =3D=3D60960=3D=3D Address 0x4a757e4 is 0 bytes inside data symbol "h_errno" #v- So, is there a thread-safety issue with these functions, or a bug in valgrind, or maybe just some false positive? Thanks, Felix --=20 Felix Palmen {private} felix@palmen-it.de -- ports committer (mentee) -- {web} http://palmen-it.de {pgp public key} http://palmen-it.de/pub.txt {pgp fingerprint} 6936 13D5 5BBF 4837 B212 3ACC 54AD E006 9879 F231 --d4ydqeqillcdqll3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iNUEABYKAH0WIQRpNhPVW79IN7ISOsxUreAGmHnyMQUCZElmF18UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0Njkz NjEzRDU1QkJGNDgzN0IyMTIzQUNDNTRBREUwMDY5ODc5RjIzMQAKCRBUreAGmHny MU5LAP41gbmgOQpfy5lmknXtjAtqdkTaXjHTaiP6LSyZoelhIwEA7Xb6tlT40aPg KdBxVc2eyMNi7hlkFio47Re/tDs3GAA= =jJP8 -----END PGP SIGNATURE----- --d4ydqeqillcdqll3--