From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id 83FC43858415; Tue, 12 Dec 2023 08:43:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83FC43858415 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1702370619; bh=4hzK51VkqfZ5tberGNhuynAmMSpocO0sX1oemU8jnug=; h=From:To:Subject:Date:From; b=i2vfEbe2YCKfIXHZHp2/riQ8x5zmV9Kn3TWqLsZxw4xr17FBolvTB0rGC/t4Zl+AG MbfRjaej8WjIl1XxIGAGchemBDCr4JGBOROHYuUYX3L47M1JbZ3U1qpTYzDwo3GSO3 paf6cN06FujMx/mT/qEtzsmGJtUy4bwNx0n3youM= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc] resolv: Fix a few unaligned accesses to fields in HEADER X-Act-Checkin: glibc X-Git-Author: Ludwig Rydberg X-Git-Refname: refs/heads/master X-Git-Oldrev: 4753e9286858a61d5fbe8742d48d8c9166143354 X-Git-Newrev: fc039ce8502d236f11074eb58468be24b4fa8cc7 Message-Id: <20231212084339.83FC43858415@sourceware.org> Date: Tue, 12 Dec 2023 08:43:39 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=fc039ce8502d236f11074eb58468be24b4fa8cc7 commit fc039ce8502d236f11074eb58468be24b4fa8cc7 Author: Ludwig Rydberg Date: Mon Dec 11 13:50:41 2023 +0100 resolv: Fix a few unaligned accesses to fields in HEADER After refactoring the alloca usage in 40c0add7d4 ("resolve: Remove __res_context_query alloca usage") a few unaligned accesses to HEADER fields surfaced. These unaligned accesses led to problems when running the resolv test suite on sparc32-linux (leon) as many tests failed due to SIGBUS crashes. The issue(s) occured during T_QUERY_A_AND_AAAA queries as the second query now can start on an unaligned address (previously it was explicitly aligned). With this patch the unaligned accesses are now fixed by using the UHEADER instead to ensure the fields are accessed with byte loads/stores. The patch has been verfied by running the resolv test suite on sparc32 and x86_64. Signed-off-by: Ludwig Rydberg Signed-off-by: Andreas Larsson Reviewed-by: Florian Weimer Diff: --- resolv/res_mkquery.c | 6 +++--- resolv/res_queriesmatch.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resolv/res_mkquery.c b/resolv/res_mkquery.c index e9316b3c37..a46a92432b 100644 --- a/resolv/res_mkquery.c +++ b/resolv/res_mkquery.c @@ -100,7 +100,7 @@ __res_context_mkquery (struct resolv_context *ctx, int op, const char *dname, int class, int type, const unsigned char *data, unsigned char *buf, int buflen) { - HEADER *hp; + UHEADER *hp; unsigned char *cp; int n; unsigned char *dnptrs[20], **dpp, **lastdnptr; @@ -112,7 +112,7 @@ __res_context_mkquery (struct resolv_context *ctx, int op, const char *dname, if ((buf == NULL) || (buflen < HFIXEDSZ)) return -1; memset (buf, 0, HFIXEDSZ); - hp = (HEADER *) buf; + hp = (UHEADER *) buf; /* We randomize the IDs every time. The old code just incremented by one after the initial randomization which still predictable if the application does multiple requests. */ @@ -250,7 +250,7 @@ __res_nopt (struct resolv_context *ctx, int n0, unsigned char *buf, int buflen, int anslen) { uint16_t flags = 0; - HEADER *hp = (HEADER *) buf; + UHEADER *hp = (UHEADER *) buf; unsigned char *cp = buf + n0; unsigned char *ep = buf + buflen; diff --git a/resolv/res_queriesmatch.c b/resolv/res_queriesmatch.c index ba1c1d0c0c..37db01a1b0 100644 --- a/resolv/res_queriesmatch.c +++ b/resolv/res_queriesmatch.c @@ -95,14 +95,14 @@ __libc_res_queriesmatch (const unsigned char *buf1, const unsigned char *eom1, /* Only header section present in replies to dynamic update packets. */ - if ((((HEADER *) buf1)->opcode == ns_o_update) && - (((HEADER *) buf2)->opcode == ns_o_update)) + if ((((UHEADER *) buf1)->opcode == ns_o_update) && + (((UHEADER *) buf2)->opcode == ns_o_update)) return 1; /* Note that we initially do not convert QDCOUNT to the host byte order. We can compare it with the second buffer's QDCOUNT value without doing this. */ - int qdcount = ((HEADER *) buf1)->qdcount; + int qdcount = ((UHEADER *) buf1)->qdcount; if (qdcount != ((UHEADER *) buf2)->qdcount) return 0;