From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by sourceware.org (Postfix) with ESMTPS id 354B03858408 for ; Tue, 28 Sep 2021 14:36:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 354B03858408 Received: by mail-qk1-x732.google.com with SMTP id i132so41025633qke.1 for ; Tue, 28 Sep 2021 07:36:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5AhJ4ad+ktIdhqEV0UJxLgVKIwwC8L6aONXyjZ6IEbw=; b=2bT3wlJHx6/p0+lMdpehl0KIBOkHGOaHFBt3el1qFw0rb7d11aOCXT/jyl+/0jZO7t bEbem898RtKOPoSU+DWfeJDAhwOoOKtMGBiFiGI21BlmaCiUi6XSK6tuHPT6f0sNaRrN 5V+V+Aa3Ns8MqzkWnYdoLw+yIn0doZ3ESocWKFS6g1ZgMrkJ8uHtDPrjZ6sdc6I5k04o H/QcIUHWbgtEexCcmIa7Cl0QZdzIW3IQyF7o7WSdjckoTINKv1+jp6S/Ai3AIUvth7Zz LkFtE+o6wUxvBJKsFVXhxXZZ9Ti6WYHSt2JYytmv96ycpsooCgJ8TF10FXVpNpf7rhob XFHw== X-Gm-Message-State: AOAM5324i4thL+557H80S9HJRVgBVcz6FFtNBgc8uLF+L/lK8zG4cBl+ zOHLgPBvhqCmWCjt0KAhzmEUIOxwHFtlgw== X-Google-Smtp-Source: ABdhPJwnUF1O1ofUMm8LqhiocJF+E2MC79+FaFqJwPZhS4HNvkeMEUZjwzavjqbiVe+OO614DnwIiw== X-Received: by 2002:a37:670d:: with SMTP id b13mr300733qkc.420.1632839764567; Tue, 28 Sep 2021 07:36:04 -0700 (PDT) Received: from ?IPv6:2804:431:c7cb:b338:e093:b762:10f5:43e5? ([2804:431:c7cb:b338:e093:b762:10f5:43e5]) by smtp.gmail.com with ESMTPSA id j14sm13436625qtv.36.2021.09.28.07.36.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Sep 2021 07:36:04 -0700 (PDT) Subject: Re: [PATCH] resolv: Fix tests by aligning hand crafted queries To: Stafford Horne , GLIBC patches References: <20210614234011.2215641-1-shorne@gmail.com> From: Adhemerval Zanella Message-ID: <4da1fbe0-e1ac-09c2-de8b-2179344cf59b@linaro.org> Date: Tue, 28 Sep 2021 11:36:02 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210614234011.2215641-1-shorne@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2021 14:36:07 -0000 On 14/06/2021 20:40, Stafford Horne via Libc-alpha wrote: > When testing OpenRISC I get a bus error in res_send. This is due to the > buf being cast to a (HEADER *) and trying the res_send code trying to read > different bits of the HEADER struct including 16-bit id etc. > > On OpenRISC reads of 16-bits and 32-bits from structures need to be 2 > byte and 4 byte aligned, respectively. > > To fix this we can align the hand crafted queries. But the res_send() interface does specify that buffer is an 'unsigned char', so I think the problem is in fact send_vc() (any any other code that consume the buffer) where the cast is in fact undefined. I am not sure why it has not show any issue on architecture that trap on unaligned access, may guess is the stack buffer alignment is the same as the HEADER. The issue is resolv code seems to abuse this... > --- > resolv/tst-resolv-binary.c | 2 +- > resolv/tst-resolv-trustad.c | 3 ++- > 2 files changed, 3 insertions(+), 2 deletions(-) > > diff --git a/resolv/tst-resolv-binary.c b/resolv/tst-resolv-binary.c > index 44895a1baa..f76ae057c4 100644 > --- a/resolv/tst-resolv-binary.c > +++ b/resolv/tst-resolv-binary.c > @@ -52,7 +52,7 @@ do_test (void) > > for (int b = 0; b <= 255; ++b) > { > - unsigned char query[] = > + unsigned char query[] __attribute__ ((aligned)) = > { > b, b, /* Transaction ID. */ > 1, 0, /* Query with RD flag. */ > diff --git a/resolv/tst-resolv-trustad.c b/resolv/tst-resolv-trustad.c > index 74ee5db735..8d6989adb4 100644 > --- a/resolv/tst-resolv-trustad.c > +++ b/resolv/tst-resolv-trustad.c > @@ -93,7 +93,8 @@ do_test (void) > /* By default, the resolver is not trusted, and the AD bit is > cleared. */ > > - static const unsigned char hand_crafted_query[] = > + static const unsigned char hand_crafted_query[] > + __attribute__ ((aligned)) = > { > 10, 11, /* Transaction ID. */ > 1, 0x20, /* Query with RD, AD flags. */ >