From patchwork Thu Jan 11 13:01:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 1885577 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=K+mh72Yw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T9lFL35d9z1yPp for ; Fri, 12 Jan 2024 00:02:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 473A23875425 for ; Thu, 11 Jan 2024 13:02:28 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 009973875DF2 for ; Thu, 11 Jan 2024 13:01:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 009973875DF2 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 009973875DF2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704978090; cv=none; b=QFdEvbpVx7Fdt2Si9Hae/ez7n/csP/O8nXDxhDRHb03RFyNZgwc/zUMNCWvIzWaxNHNzmH2SDLMY4deZBEp7bFtUgrrlGPyGSqPuKyouTkgfoys4uobm8EP1pWUYojvLNrL3fZQ7TlmIDn3fzYMguVFbMcdOvlUhsEqbmjXizUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704978090; c=relaxed/simple; bh=33nqMXyp2XTDHLJrLhAYLzTXJ1pNeKKjUpnJAIKnk+U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AT5mxYs97qUcPl0+Z+FttS4kBdpSK3tNtQlxRrtwm3/h/xFnFvngaSt3TpMCIDpmEg5Ebs2BZfh5fSotCnlxhOKCDuPCZtdPoBZcjamToRNAJ6giR0EnLv+lIKBV3y6xeW7w8Q9r/J4fo6EuZ/yAWea2J5ibHSG+0R4wQu9cbYI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40BD0677015954; Thu, 11 Jan 2024 13:01:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=ossxRt4AE80MHgs2uWRJjMn5uyUgxDE4fqeJtMp6V8E=; b=K+mh72YwZHDVjG9qsl8RBT4/E6TfEL8Lam03qH3pT4pD1Ero744db/UQzkRb3iwBwTYC WGdtf1mWg5qvmig0vLD0qtGdpTNDbeEx3nO8IEqfm/ykOOCsP1uMLc8KurhO4F1sPzqh 0SKyldOsgwk4lcqFfw4t+qCsLR/Y8hupYeFQ/ujvPfHNrQbTga8uDI4JFXaqYj8v76qd JrE/j/i8q+dAv7tQD/UuNVabJ1FObK+xTFkSlPI8RyGbbQ0O4jEgwFifyXHR67uD2SOQ yJmyVmfC/woV63/iZD2ebpbdCLgWdKJSFvZzMOWZGqkl318vUo0YZyjxVI1bhwnWJKSd 3Q== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vjgty023p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Jan 2024 13:01:25 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 40BC93P2004427; Thu, 11 Jan 2024 13:01:25 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vfjpm3c5d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Jan 2024 13:01:25 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40BD1MI435914032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Jan 2024 13:01:22 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1390D2004D; Thu, 11 Jan 2024 13:01:22 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB05820049; Thu, 11 Jan 2024 13:01:21 +0000 (GMT) Received: from a35lp68.lnxne.boe (unknown [9.152.108.100]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 11 Jan 2024 13:01:21 +0000 (GMT) From: Stefan Liebler To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, Stefan Liebler Subject: [PATCH] resolv: Fix endless loop in __res_context_query Date: Thu, 11 Jan 2024 14:01:18 +0100 Message-ID: <20240111130118.1483134-1-stli@linux.ibm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 8YnKiUF71dujhxg3-hMWsIcQobOf6QQq X-Proofpoint-GUID: 8YnKiUF71dujhxg3-hMWsIcQobOf6QQq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-11_07,2024-01-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 impostorscore=0 malwarescore=0 priorityscore=1501 bulkscore=0 mlxscore=0 phishscore=0 spamscore=0 mlxlogscore=809 adultscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401110103 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Starting with commit 40c0add7d48739f5d89ebba255c1df26629a76e2 "resolve: Remove __res_context_query alloca usage" there is an endless loop in __res_context_query if __res_context_mkquery fails e.g. if type is invalid. Then the scratch buffer is resized to MAXPACKET size and it is retried again. Before the mentioned commit, it was retried only once and with the mentioned commit, there is no check and it retries in an endless loop. This is observable with xtest resolv/tst-resolv-qtypes which times out after 300s. This patch retries mkquery only once as before the mentioned commit. Furthermore, scratch_buffer_set_array_size is now only called with nelem=2 if type is T_QUERY_A_AND_AAAA (also see mentioned commit). The test tst-resolv-qtypes is also adjusted to verify that is really returning with -1 in case of an invalid type. Reviewed-by: Adhemerval Zanella --- resolv/res_query.c | 8 +++++--- resolv/tst-resolv-qtypes.c | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/resolv/res_query.c b/resolv/res_query.c index 1b148a2a05..4bfba24c73 100644 --- a/resolv/res_query.c +++ b/resolv/res_query.c @@ -115,7 +115,7 @@ __res_context_query (struct resolv_context *ctx, const char *name, struct __res_state *statp = ctx->resp; UHEADER *hp = (UHEADER *) answer; UHEADER *hp2; - int n; + int n, retried = 0; /* It requires 2 times QUERYSIZE for type == T_QUERY_A_AND_AAAA. */ struct scratch_buffer buf; @@ -182,13 +182,15 @@ __res_context_query (struct resolv_context *ctx, const char *name, nquery1 = n; } - if (__glibc_unlikely (n <= 0)) { + if (__glibc_unlikely (n <= 0) && !retried) { /* Retry just in case res_nmkquery failed because of too short buffer. Shouldn't happen. */ if (scratch_buffer_set_array_size (&buf, - T_QUERY_A_AND_AAAA ? 2 : 1, + (type == T_QUERY_A_AND_AAAA) + ? 2 : 1, MAXPACKET)) { query1 = buf.data; + retried = 1; goto again; } } diff --git a/resolv/tst-resolv-qtypes.c b/resolv/tst-resolv-qtypes.c index 3fa566c7ea..973c4e15d3 100644 --- a/resolv/tst-resolv-qtypes.c +++ b/resolv/tst-resolv-qtypes.c @@ -154,8 +154,8 @@ test_function (const char *fname, } } - TEST_VERIFY (func (-1, buf, sizeof (buf) == -1)); - TEST_VERIFY (func (65536, buf, sizeof (buf) == -1)); + TEST_VERIFY (func (-1, buf, sizeof (buf)) == -1); + TEST_VERIFY (func (65536, buf, sizeof (buf)) == -1); } static int