linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wireless: Use offsetof instead of custom macro.
@ 2019-04-18  7:50 Pi-Hsun Shih
  2019-05-02  7:56 ` Nicolas Boichat
  0 siblings, 1 reply; 3+ messages in thread
From: Pi-Hsun Shih @ 2019-04-18  7:50 UTC (permalink / raw)
  Cc: Pi-Hsun Shih, open list

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:

==================================================================
UBSAN: Undefined behaviour in net/wireless/wext-core.c:525:14
member access within null pointer of type 'struct iw_point'
CPU: 3 PID: 165 Comm: kworker/u16:3 Tainted: G S      W         4.19.23 #43
Workqueue: cfg80211 __cfg80211_scan_done [cfg80211]
Call trace:
 dump_backtrace+0x0/0x194
 show_stack+0x20/0x2c
 __dump_stack+0x20/0x28
 dump_stack+0x70/0x94
 ubsan_epilogue+0x14/0x44
 ubsan_type_mismatch_common+0xf4/0xfc
 __ubsan_handle_type_mismatch_v1+0x34/0x54
 wireless_send_event+0x3cc/0x470
 ___cfg80211_scan_done+0x13c/0x220 [cfg80211]
 __cfg80211_scan_done+0x28/0x34 [cfg80211]
 process_one_work+0x170/0x35c
 worker_thread+0x254/0x380
 kthread+0x13c/0x158
 ret_from_fork+0x10/0x18
===================================================================

Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
---
 include/uapi/linux/wireless.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/uapi/linux/wireless.h b/include/uapi/linux/wireless.h
index 86eca3208b6b..f259cca5cc2b 100644
--- 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)
 
-- 
2.21.0.392.gf8f6787159e-goog


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

* Re: [PATCH] wireless: Use offsetof instead of custom macro.
  2019-04-18  7:50 [PATCH] wireless: Use offsetof instead of custom macro Pi-Hsun Shih
@ 2019-05-02  7:56 ` Nicolas Boichat
  2019-11-27 23:39   ` Brian Norris
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Boichat @ 2019-05-02  7:56 UTC (permalink / raw)
  To: Pi-Hsun Shih; +Cc: open list

On Thu, Apr 18, 2019 at 3:50 PM Pi-Hsun Shih <pihsun@chromium.org> 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:
>
> ==================================================================
> UBSAN: Undefined behaviour in net/wireless/wext-core.c:525:14
> member access within null pointer of type 'struct iw_point'
> CPU: 3 PID: 165 Comm: kworker/u16:3 Tainted: G S      W         4.19.23 #43
> Workqueue: cfg80211 __cfg80211_scan_done [cfg80211]
> Call trace:
>  dump_backtrace+0x0/0x194
>  show_stack+0x20/0x2c
>  __dump_stack+0x20/0x28
>  dump_stack+0x70/0x94
>  ubsan_epilogue+0x14/0x44
>  ubsan_type_mismatch_common+0xf4/0xfc
>  __ubsan_handle_type_mismatch_v1+0x34/0x54
>  wireless_send_event+0x3cc/0x470
>  ___cfg80211_scan_done+0x13c/0x220 [cfg80211]
>  __cfg80211_scan_done+0x28/0x34 [cfg80211]
>  process_one_work+0x170/0x35c
>  worker_thread+0x254/0x380
>  kthread+0x13c/0x158
>  ret_from_fork+0x10/0x18
> ===================================================================
>
> Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>

The warning from clang is spurious, but in another case, we felt that
the cleanup was worth it, nevertheless
(https://lore.kernel.org/patchwork/patch/1050040/).

Reviewed-By: Nicolas Boichat <drinkcat@chromium.org>

> ---
>  include/uapi/linux/wireless.h | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/include/uapi/linux/wireless.h b/include/uapi/linux/wireless.h
> index 86eca3208b6b..f259cca5cc2b 100644
> --- 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)
>
> --
> 2.21.0.392.gf8f6787159e-goog
>

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

* Re: [PATCH] wireless: Use offsetof instead of custom macro.
  2019-05-02  7:56 ` Nicolas Boichat
@ 2019-11-27 23:39   ` Brian Norris
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Norris @ 2019-11-27 23:39 UTC (permalink / raw)
  To: Nicolas Boichat; +Cc: Pi-Hsun Shih, open list, linux-wireless

+ linux-wireless

[Top-posting because the important stuff is up here, and the rest is
missing from linux-wireless]

Hey Pi-Hsun, Nicolas: you failed to copy linux-wireless, so no one's
going to pick this patch up. Please re-send if you care.

Regards,
Brian

On Thu, May 02, 2019 at 03:56:33PM +0800, Nicolas Boichat wrote:
> On Thu, Apr 18, 2019 at 3:50 PM Pi-Hsun Shih <pihsun@chromium.org> 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:
> >
> > ==================================================================
> > UBSAN: Undefined behaviour in net/wireless/wext-core.c:525:14
> > member access within null pointer of type 'struct iw_point'
> > CPU: 3 PID: 165 Comm: kworker/u16:3 Tainted: G S      W         4.19.23 #43
> > Workqueue: cfg80211 __cfg80211_scan_done [cfg80211]
> > Call trace:
> >  dump_backtrace+0x0/0x194
> >  show_stack+0x20/0x2c
> >  __dump_stack+0x20/0x28
> >  dump_stack+0x70/0x94
> >  ubsan_epilogue+0x14/0x44
> >  ubsan_type_mismatch_common+0xf4/0xfc
> >  __ubsan_handle_type_mismatch_v1+0x34/0x54
> >  wireless_send_event+0x3cc/0x470
> >  ___cfg80211_scan_done+0x13c/0x220 [cfg80211]
> >  __cfg80211_scan_done+0x28/0x34 [cfg80211]
> >  process_one_work+0x170/0x35c
> >  worker_thread+0x254/0x380
> >  kthread+0x13c/0x158
> >  ret_from_fork+0x10/0x18
> > ===================================================================
> >
> > Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
> 
> The warning from clang is spurious, but in another case, we felt that
> the cleanup was worth it, nevertheless
> (https://lore.kernel.org/patchwork/patch/1050040/).
> 
> Reviewed-By: Nicolas Boichat <drinkcat@chromium.org>
> 
> > ---
> >  include/uapi/linux/wireless.h | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/include/uapi/linux/wireless.h b/include/uapi/linux/wireless.h
> > index 86eca3208b6b..f259cca5cc2b 100644
> > --- 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)
> >
> > --
> > 2.21.0.392.gf8f6787159e-goog
> >

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

end of thread, other threads:[~2019-11-27 23:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-18  7:50 [PATCH] wireless: Use offsetof instead of custom macro Pi-Hsun Shih
2019-05-02  7:56 ` Nicolas Boichat
2019-11-27 23:39   ` Brian Norris

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 NNTP newsgroup(s).