lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANdKZ0eYSdPC2y5QxN1B7FshewXumrETQohbXrnvbovXMkSe9Q@mail.gmail.com>
Date:   Fri, 29 Nov 2019 12:04:47 +0800
From:   Pi-Hsun Shih <pihsun@...omium.org>
To:     Joe Perches <joe@...ches.com>
Cc:     linux-wireless@...r.kernel.org,
        Johannes Berg <johannes@...solutions.net>,
        open list <linux-kernel@...r.kernel.org>,
        "open list:CLANG/LLVM BUILD SUPPORT" 
        <clang-built-linux@...glegroups.com>
Subject: Re: [PATCH RESEND] wireless: Use offsetof instead of custom macro.

On Thu, Nov 28, 2019 at 11:54 AM Joe Perches <joe@...ches.com> wrote:
>
> On Thu, 2019-11-28 at 11:39 +0800, Pi-Hsun Shih wrote:
> > Use offsetof to calculate offset of a field to take advantage of
> > compiler built-in version when possible, and avoid UBSAN warning when
> > compiling with Clang:
> []
> > diff --git a/include/uapi/linux/wireless.h b/include/uapi/linux/wireless.h
> []
> > @@ -1090,8 +1090,7 @@ struct iw_event {
> >  /* iw_point events are special. First, the payload (extra data) come at
> >   * the end of the event, so they are bigger than IW_EV_POINT_LEN. Second,
> >   * we omit the pointer, so start at an offset. */
> > -#define IW_EV_POINT_OFF (((char *) &(((struct iw_point *) NULL)->length)) - \
> > -                       (char *) NULL)
> > +#define IW_EV_POINT_OFF offsetof(struct iw_point, length)
> >  #define IW_EV_POINT_LEN      (IW_EV_LCP_LEN + sizeof(struct iw_point) - \
> >                        IW_EV_POINT_OFF)
>
> This is uapi.  Is offsetof guaranteed to be available?

offsetof is already used in other uapi headers
(include/uapi/linux/fuse.h FUSE_NAME_OFFSET).

Also offsetof is also defined back in C89 standard (in stddef.h), so
it should be widely available and should be fine to use here?
(Should I add a #ifndef __KERNEL__ #include <stddef.h> to the file?)

>
> Perhaps this is better without using another macro
>
> #define IW_EV_POINT_OFF ((size_t)&((struct iw_point *)NULL)->length)

Clang UBSAN would still complain about this, since it's the same
pattern as the original one.

>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ