Message ID | 5E7CF115-219A-4260-BE53-19B5A8D1D7F3@bell.net |
---|---|
State | New, archived |
Headers |
Received: (qmail 118144 invoked by alias); 15 Jun 2016 11:43:12 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <libc-alpha.sourceware.org> List-Unsubscribe: <mailto:libc-alpha-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:libc-alpha-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 118133 invoked by uid 89); 15 Jun 2016 11:43:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.2 spammy=H*c:sk:Apple-M, 20160616, 2016-06-16 X-HELO: mtlfep01.bell.net From: John David Anglin <dave.anglin@bell.net> Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: multipart/mixed; boundary=Apple-Mail-6-204990431 Date: Wed, 15 Jun 2016 07:42:58 -0400 Subject: [PATCH] Fix misaligned access accessing HEADER struct in res_query.c Cc: Carlos O'Donell <carlos@redhat.com>, Mike Frysinger <vapier@gentoo.org> To: GNU C Library <libc-alpha@sourceware.org> Message-Id: <5E7CF115-219A-4260-BE53-19B5A8D1D7F3@bell.net> X-Opwv-CommTouchExtSvcRefID: str=0001.0A020202.57613F42.0183, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 |
Commit Message
John David Anglin
June 15, 2016, 11:42 a.m. UTC
The attached patch fixes BZ 20243. The HEADER struct needs to be packed so that byte accesses are used. Tested using glibc 2.22-11on hppa. Please install if okay. Dave -- John David Anglin dave.anglin@bell.net 2016-06-16 John David Anglin <danglin@gcc.gnu.org> [BZ 20243] * resolv/arpa/nameser_compat.h (HEADER): Use attribute packed.
Comments
On 06/15/2016 01:42 PM, John David Anglin wrote: > The attached patch fixes BZ 20243. The HEADER struct needs to be packed so that > byte accesses are used. Tested using glibc 2.22-11on hppa. Please install if okay. > -} HEADER; > +} __attribute__ ((packed)) HEADER; Unfortunately, we cannot apply this simple fix because this is a public header, and the above changes alignment of the struct. It would also have to be __attribute__ ((__packed__)). Florian
Florian Weimer <fweimer@redhat.com> writes: > On 06/15/2016 01:42 PM, John David Anglin wrote: >> The attached patch fixes BZ 20243. The HEADER struct needs to be packed so that >> byte accesses are used. Tested using glibc 2.22-11on hppa. Please install if okay. > >> -} HEADER; >> +} __attribute__ ((packed)) HEADER; > > Unfortunately, we cannot apply this simple fix because this is a public > header, and the above changes alignment of the struct. It would also have > to be __attribute__ ((__packed__)). It also needs to work with other compilers. Andreas.
On 2016-06-15 8:16 AM, Andreas Schwab wrote: > Florian Weimer<fweimer@redhat.com> writes: > >> >On 06/15/2016 01:42 PM, John David Anglin wrote: >>> >>The attached patch fixes BZ 20243. The HEADER struct needs to be packed so that >>> >>byte accesses are used. Tested using glibc 2.22-11on hppa. Please install if okay. >> > >>> >>-} HEADER; >>> >>+} __attribute__ ((packed)) HEADER; >> > >> >Unfortunately, we cannot apply this simple fix because this is a public >> >header, and the above changes alignment of the struct. It would also have >> >to be __attribute__ ((__packed__)). > It also needs to work with other compilers. The packed attribute is used in several places in glibc. Maybe a packed derivative of HEADER can be used in res_query.c to avoid the above issue? I don't think the packed derivative affects the layout of HEADER given the way the fields are arranged. Dave
On 06/15/2016 04:40 PM, John David Anglin wrote: > On 2016-06-15 8:16 AM, Andreas Schwab wrote: >> Florian Weimer<fweimer@redhat.com> writes: >> >>> >On 06/15/2016 01:42 PM, John David Anglin wrote: >>>> >>The attached patch fixes BZ 20243. The HEADER struct needs to be >>>> packed so that >>>> >>byte accesses are used. Tested using glibc 2.22-11on hppa. >>>> Please install if okay. >>> > >>>> >>-} HEADER; >>>> >>+} __attribute__ ((packed)) HEADER; > I don't think the packed derivative affects the layout of HEADER given > the way the fields are > arranged. I verified that it changes alignment, even on x86_64. That's the intent, and it results in a layout change (if this struct is used as a part of other structs, for example). Florian
On 2016-06-15 10:43 AM, Florian Weimer wrote: >> I don't think the packed derivative affects the layout of HEADER given >> the way the fields are >> arranged. > > I verified that it changes alignment, even on x86_64. That's the > intent, and it results in a layout change (if this struct is used as a > part of other structs, for example). I'm suggesting this be done in res_query.c where we we need byte alignment. Nothing else would have access to this typedef, so it couldn't affect the layout of any other structs. Dave
diff --git a/resolv/arpa/nameser_compat.h b/resolv/arpa/nameser_compat.h index d59c9e4..6c0f69c 100644 --- a/resolv/arpa/nameser_compat.h +++ b/resolv/arpa/nameser_compat.h @@ -80,7 +80,7 @@ typedef struct { unsigned ancount :16; /*%< number of answer entries */ unsigned nscount :16; /*%< number of authority entries */ unsigned arcount :16; /*%< number of resource entries */ -} HEADER; +} __attribute__ ((packed)) HEADER; #define PACKETSZ NS_PACKETSZ #define MAXDNAME NS_MAXDNAME