public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc
@ 2013-11-20 21:31 luto at mit dot edu
  2013-11-21  0:26 ` [Bug libc/16197] " bugdal at aerifal dot cx
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: luto at mit dot edu @ 2013-11-20 21:31 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16197

            Bug ID: 16197
           Summary: CMSG_DATA results in (possibly correct) string
                    aliasing warnings on gcc
           Product: glibc
           Version: 2.17
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: luto at mit dot edu
                CC: drepper.fsp at gmail dot com

Using CMSG_DATA on most gcc configurations gives a string aliasing warning. 
This happens because struct cmsg_hdr is:

struct cmsghdr
{
    size_t cmsg_len;
    int cmsg_level;
    int cmsg_type;
    __extension__ unsigned char __cmsg_data [];
};

GCC thinks that __cmsg_data is an array of objects of type unsigned char, in
which case it's illegal to access them through a pointer to anything else (as
CMSG_DATA does).  I'm not sure whether it's legal to put objects of, for
example, type int into storage defined by an array of type unsigned char, but
I'm not particularly surprised that gcc warns.

Anything like this:

    struct cmsghdr *cmsg = CMSG_FIRSTHDR(&hdr);
    if (cmsg) {
        /* This is IPPROTO_IP / IP_TTL */
        if (cmsg->cmsg_level == 0 && cmsg->cmsg_type == 2) {
            use(*(int *)CMSG_DATA(cmsg));
        }
    }

will trigger the warning if built with -Wall -O2.

There's a trivial fix: stop using flexible arrays.  The pre-C99
non-gcc-extension-using variant (which is already in bits/socket.h) is fine.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/16197] CMSG_DATA results in (possibly correct) string aliasing warnings on gcc
  2013-11-20 21:31 [Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc luto at mit dot edu
@ 2013-11-21  0:26 ` bugdal at aerifal dot cx
  2013-11-21  5:32 ` luto at mit dot edu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: bugdal at aerifal dot cx @ 2013-11-21  0:26 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16197

Rich Felker <bugdal at aerifal dot cx> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugdal at aerifal dot cx

--- Comment #1 from Rich Felker <bugdal at aerifal dot cx> ---
This is actually a complicated issue and unfortunately I think GCC is stuck in
the middle of an inconsistency in the standard. Per the standard, it's legal to
step around the representation of an object (an overlaid char-type array) using
offsets (e.g. obtained from offsetof()) and char pointers. For example, this
would *clearly* be valid:

*(T *)((char *)pmsg + offsetof(struct cmsghdr, __cmsg_data) + N)

(assuming there's an object of type T at offset N from the end of the message
header, which is plausible if pmsg points to storage obtained by malloc). But
(char *)pmsg + offsetof(struct cmsghdr, __cmsg_data) evaluates to the same
thing as pmsg->__cmsg_data (after array decay). So it's not clear how the
former can be valid and the latter an aliasing violation.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/16197] CMSG_DATA results in (possibly correct) string aliasing warnings on gcc
  2013-11-20 21:31 [Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc luto at mit dot edu
  2013-11-21  0:26 ` [Bug libc/16197] " bugdal at aerifal dot cx
@ 2013-11-21  5:32 ` luto at mit dot edu
  2013-12-02  6:45 ` crrodriguez at opensuse dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: luto at mit dot edu @ 2013-11-21  5:32 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16197

--- Comment #2 from Andy Lutomirski <luto at mit dot edu> ---
I suspect that glibc's code is fine, insofar programs using it aren't invoking
undefined behavior.  That being said, I'm not sure I can blame gcc for warning.
 glibc is doing something roughly equivalent to:

struct foo { unsigned char array[10]; };

void func(struct foo *foo)
{
   int x = *(int*)foo->array;
}

There's no actual aliasing violation there (the object is of type int, not
char), but the code sure *looks* like an aliasing violation.

Given that the other variant is already there in bits/socket.h, it seems to me
that glibc should just switch to using it and eliminate the warning.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/16197] CMSG_DATA results in (possibly correct) string aliasing warnings on gcc
  2013-11-20 21:31 [Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc luto at mit dot edu
  2013-11-21  0:26 ` [Bug libc/16197] " bugdal at aerifal dot cx
  2013-11-21  5:32 ` luto at mit dot edu
@ 2013-12-02  6:45 ` crrodriguez at opensuse dot org
  2014-06-13 11:59 ` fweimer at redhat dot com
  2015-08-27 22:18 ` [Bug network/16197] " jsm28 at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: crrodriguez at opensuse dot org @ 2013-12-02  6:45 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16197

Cristian Rodríguez <crrodriguez at opensuse dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |crrodriguez at opensuse dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.
>From glibc-bugs-return-20360-listarch-glibc-bugs=sources.redhat.com@sourceware.org Mon Dec 02 07:53:49 2013
Return-Path: <glibc-bugs-return-20360-listarch-glibc-bugs=sources.redhat.com@sourceware.org>
Delivered-To: listarch-glibc-bugs@sources.redhat.com
Received: (qmail 15595 invoked by alias); 2 Dec 2013 07:53:49 -0000
Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm
Precedence: bulk
List-Id: <glibc-bugs.sourceware.org>
List-Subscribe: <mailto:glibc-bugs-subscribe@sourceware.org>
List-Post: <mailto:glibc-bugs@sourceware.org>
List-Help: <mailto:glibc-bugs-help@sourceware.org>, <http://sourceware.org/lists.html#faqs>
Sender: glibc-bugs-owner@sourceware.org
Delivered-To: mailing list glibc-bugs@sourceware.org
Received: (qmail 15554 invoked by uid 48); 2 Dec 2013 07:53:45 -0000
From: "aj at suse dot de" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/16282] glibc needs to support the O_XATTR openat() flag on Solaris+Illumos kernels
Date: Mon, 02 Dec 2013 07:53:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: glibc
X-Bugzilla-Component: libc
X-Bugzilla-Version: unspecified
X-Bugzilla-Keywords:
X-Bugzilla-Severity: critical
X-Bugzilla-Who: aj at suse dot de
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P2
X-Bugzilla-Assigned-To: unassigned at sourceware dot org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cc resolution
Message-ID: <bug-16282-131-vCbENOfI0T@http.sourceware.org/bugzilla/>
In-Reply-To: <bug-16282-131@http.sourceware.org/bugzilla/>
References: <bug-16282-131@http.sourceware.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://sourceware.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-12/txt/msg00006.txt.bz2
Content-length: 649

https://sourceware.org/bugzilla/show_bug.cgi?id\x16282

Andreas Jaeger <aj at suse dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |aj at suse dot de
         Resolution|---                         |INVALID

--- Comment #1 from Andreas Jaeger <aj at suse dot de> ---
There is no support yet in glibc for the Solaris,  Illumos kernels, so no need
to support this.

--
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/16197] CMSG_DATA results in (possibly correct) string aliasing warnings on gcc
  2013-11-20 21:31 [Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc luto at mit dot edu
                   ` (2 preceding siblings ...)
  2013-12-02  6:45 ` crrodriguez at opensuse dot org
@ 2014-06-13 11:59 ` fweimer at redhat dot com
  2015-08-27 22:18 ` [Bug network/16197] " jsm28 at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13 11:59 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16197

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com
              Flags|                            |security-

--- Comment #3 from Florian Weimer <fweimer at redhat dot com> ---
Even though CMSG_DATA has security-related uses, I expect that the system call
serves as an optimization barrier, so that the practical impact from the
aliasing violation is hopefully minimal.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug network/16197] CMSG_DATA results in (possibly correct) string aliasing warnings on gcc
  2013-11-20 21:31 [Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc luto at mit dot edu
                   ` (3 preceding siblings ...)
  2014-06-13 11:59 ` fweimer at redhat dot com
@ 2015-08-27 22:18 ` jsm28 at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2015-08-27 22:18 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16197

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libc                        |network

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-08-27 22:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-20 21:31 [Bug libc/16197] New: CMSG_DATA results in (possibly correct) string aliasing warnings on gcc luto at mit dot edu
2013-11-21  0:26 ` [Bug libc/16197] " bugdal at aerifal dot cx
2013-11-21  5:32 ` luto at mit dot edu
2013-12-02  6:45 ` crrodriguez at opensuse dot org
2014-06-13 11:59 ` fweimer at redhat dot com
2015-08-27 22:18 ` [Bug network/16197] " jsm28 at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).