From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20639 invoked from network); 23 Nov 2021 14:48:15 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 23 Nov 2021 14:48:15 -0000 Received: (qmail 31904 invoked by uid 550); 23 Nov 2021 14:48:11 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 31868 invoked from network); 23 Nov 2021 14:48:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dynatrace.com; s=mimecast20180117; t=1637678878; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ej+HZk2YvCfx5AjvtENsjFJAjBKLbPVu9l/IOUk+9QE=; b=Y+JGTqf4VJx/R0P2wgxgeQDcQtez+DRQZJ7pYvPl3riTSZ4Fv2by1rV+u1AGC0v5jXIHM5 VD8czfWYCH0PVqEA6freoDJjyVgC6RncOT9Ynk+EgA+Mks+C1QBf0N6WGp3W8odOfx0eE+ xBO0en4cH03dqkSKQjtI7eHv7xI8ytk= X-MC-Unique: mhAj3aX3OnKSDzprXZEU0w-1 From: "Nieminen, Jussi" To: "musl@lists.openwall.com" Thread-Topic: Bug in getaddrinfo causing spurious returns with wrong error values Thread-Index: AQHX4Hawq8yTCmUKe0uhLrHWIssU6Q== Date: Tue, 23 Nov 2021 14:47:49 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: f04c147c-9150-3440-5b32-b781429d2e75 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d86eebb1-47c3-48fb-1047-08d9ae9038c3 x-ms-traffictypediagnostic: DM6PR13MB4300: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0 x-microsoft-antispam-message-info: YlWzhk+Xj5xyxLb43UqhnvMdpFC3rrgGNFtmgDuCda6b5gDL6BnBbXvhsod4p5zi4WEwfIHINmsDEzke6Ji6hRZu1FkjaNNAPGn1yYPSmE4RPl5zuzhY/22xwTGIDc/ujNXriaJLp7XOXoRe1YzAWzKks284tDtNuWSjoxbsoNCIwxVd276V196A+q0d3v3qzbOwHX8wG24lVur8EzmsE+MpbS6dyIHMywRV7CSg3AZRNNzN/C4WDneK9i3XrfD2V1YFREewX0iYNIFZhalc1BRsNcoSmi2UdrSJodV7YZ0rRQNIN3dLWw9vEe2FD28mU2u4idLPJTKqn9bWKRD8YHihJprdjlJVHIOY14iBZyCZpH/lwKjHiiD1uuTR7QbdpJH3DNFcTugOFYtqyxeNhkgKeXMPH8UUu7nqO8aSB3p7+MAGcpMZ78Kbk4TKsX27ZrLmIAEG/gF7clD7DwCM4Au/JhkG99LhJc11kf+77yFuwzDxnD5U8Yq13XS9ZkeGTGIxUh5XvuH81cBXzo3F6FdX9Vl2Phz0CnAgyYr2QtehjK9a0g/vhHcitCprLFnfWj6d2wV1IUSR5vgiyJuGG51iJe6SY6FPyIOy53dLoFzwsyFx3zDjy4ZDRoFXBysH2Y31tGayn28X3seA8xCb8Ecl3Z/KeykwsCZu4o3s59oAlWLD6uH7KuIxKF/zw5KKCWD91bKsPe/w4CTWOSGYRcS5BJfjk87URpDPMWewhmIDV7tURh3VTb3oGGg+mMAa x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR13MB4214.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(8676002)(2906002)(71200400001)(64756008)(66476007)(66574015)(66446008)(91956017)(55016003)(66946007)(9686003)(66556008)(122000001)(5660300002)(38100700002)(83380400001)(76116006)(186003)(6916009)(33656002)(316002)(26005)(52536014)(7696005)(508600001)(86362001)(8936002)(38070700005)(6506007)(108600200003);DIR:OUT;SFP:1101 x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?aDZwDzW9goWTaCca7pFdmUloPEnHKsLClwpAFvPqTAqy61ba28y1y7XbSs?= =?iso-8859-1?Q?rLJa6h7RsK6Sgb4IpsPmy6T5RIi+M4BK6z5PJpzj4nPyKUmH1VagBpNiQO?= =?iso-8859-1?Q?iBGW7g4vbNEpcwSl2IOIzdId/1/hqJhKobmo54OJo+asuEh/9mVoyOJwhQ?= =?iso-8859-1?Q?2TwgeBwxSSX+cXGVY3b0muQQbWWZhiS7ZaPkfTFuvVK5+u8c7DhS6Ka6wd?= =?iso-8859-1?Q?Gvhj2+ACHmtjoeLYPem4zRIFrpgZU4U/YGAh0efs+uzXZxc4ZrkULBRuUc?= =?iso-8859-1?Q?l/ohW0PAkl3W7SFrjvWSrFKr2h8K2z3qnJMglX3dddFLnw3+d+xXpHKQXn?= =?iso-8859-1?Q?UA05e9slu/rWcGqw6aYRPPNWiMniPinok1TAG/lJRi+LwdE/dV+7xYxbx0?= =?iso-8859-1?Q?Cak5IlvPJLlOcQk+ffD5HrshiNEfnEllzMgLlaU/HxqzGqinGAqPp9UZU/?= =?iso-8859-1?Q?t7R+Rpl4gupcFg6dnOZJxBqEJvrcuJW/f/lJ77xaSNPqr9uG+nGWSGvipU?= =?iso-8859-1?Q?X+kj42VjbmqGy1KfEecGidxabUtjgAAr42TBQ4PMvypFbTMKCW1Xe+pFCN?= =?iso-8859-1?Q?FZmNA9W+91sDYlgcDszQ1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Q?qxFlYV0gKw4XIu3x24pRSoHXFAKT/TmD/AaLi/w+4ud2yC+mYqdCwSJL3Z?= =?iso-8859-1?Q?MrD1GY0Ai3f5TTd/ErjheL/7/QoO45B30RDNYkrlm6kdbx7v5jCqH1oUK9?= =?iso-8859-1?Q?2McULgHk7wrW9mzBSAdsVHzHRVBrsUt9hiS1yNFBz7J+3IkWgwSL8fBCez?= =?iso-8859-1?Q?/yXgqliwnB/duXHxWfRnKsWf3fFR6l7129od5bfzGJgXfsIgVyuO5m+Aao?= =?iso-8859-1?Q?eLaA=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: dynatrace.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM5PR13MB4214.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d86eebb1-47c3-48fb-1047-08d9ae9038c3 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Nov 2021 14:47:49.8488 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70ebe3a3-5b30-435d-9d67-7716d74ca190 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SDz3ph3XZBm+tgCtBQwrTJHjKGoy2RI9NY64uOFV9HcTD7Bd3wrj1WYR6z0LPA+VrLVpUL6egKr6yGYFGj2EjhlIFRc4UH3C/TxUhIqVUec= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR13MB4300 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA103A348 smtp.mailfrom=jussi.nieminen@dynatrace.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: dynatrace.com Content-Language: en-US Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Subject: [musl] Bug in getaddrinfo causing spurious returns with wrong error values Hi, I'm a developer from the performance monitoring company Dynatrace, and I've= been recently investigating curious problems at our customers' environments wher= e a call to musl's getaddrinfo appears to spuriously return ENOENT when called = from a node.js application that is being monitored with the Dynatrace agent. I managed to pinpoint the problem to the code that performs the AI_ADDRCONF= IG check. If an address family that is not enabled on the host is specified, a= call to "connect" in that code fails, the socket fd is closed, and the value of "errno" is then evaluated. The problem is that the call to "close" can change the value of errno, whic= h will break the switch-case that follows it. Especially if aio is used (whic= h is the case when the Dynatrace agent is included in the application), the call= to close will end up setting errno to ENOENT by default (even without a failur= e) within the "aio_cancel" function if an aio operation is active. In such a c= ase getaddrinfo will then incorrectly return EAI_SYSTEM with errno set to ENOEN= T. (After some error code translations within libuv, node.js will then print a= n error message claiming that getaddrinfo failed with ENOENT which is rather confusing.) Even if aio is not used, the code might fail whenever "close" gets interrup= ted and returns with errno set to EINTR. As the return value of close is not checked, the errno might thus "silently" change before getting evaluated wi= th the assumption that it still contains the value set when "connect" failed. Below is a simple patch that should take care of this problem. Let me know = if I can provide any more information or if there is anything else I can help wi= th. Thanks, Jussi ---------------------------------------------------------------------------= ---- diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c index efaab306..71809856 100644 --- a/src/network/getaddrinfo.c +++ b/src/network/getaddrinfo.c @@ -16,6 +16,7 @@ int getaddrinfo(const char *restrict host, const char *re= strict serv, const stru char canon[256], *outcanon; int nservs, naddrs, nais, canon_len, i, j, k; int family =3D AF_UNSPEC, flags =3D 0, proto =3D 0, socktype =3D 0; + int saved_errno =3D 0; struct aibuf *out; if (!host && !serv) return EAI_NONAME; @@ -66,11 +67,14 @@ int getaddrinfo(const char *restrict host, const char *= restrict serv, const stru pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &cs); int r =3D connect(s, ta[i], tl[i]); + /* The call to "close" might change errno, = especially if aio is in use; + * save the value set by "connect" for the = later comparison. */ + if (r < 0) saved_errno =3D errno; pthread_setcancelstate(cs, 0); close(s); if (!r) continue; } - switch (errno) { + switch (saved_errno) { case EADDRNOTAVAIL: case EAFNOSUPPORT: case EHOSTUNREACH: ---------------------------------------------------------------------------= ---- This email may contain confidential information. If it appears this message= was sent to you by mistake, please let us know of the error. In this case,= we also ask that you do not further forward the content and delete it. Tha= nk you for your cooperation and understanding. Dynatrace Austria GmbH (regi= stration number FN 91482h) is a company registered in Linz whose registered= office is at 4020 Linz, Austria, Am F=FCnfundzwanziger Turm 20.