* usbip tools from 5.4 fail to build due to unaligned pointer value warning
@ 2019-11-29 12:24 Vadim Troshchinskiy
2019-11-29 13:33 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Vadim Troshchinskiy @ 2019-11-29 12:24 UTC (permalink / raw)
To: linux-usb
Hello,
Building the usbip tools from 4.15 is failing under Fedora 30, gcc version
9.2.1:
$ make
make all-recursive
make[1]: Entering directory '/home/vadim/git/linux-orig/tools/usb/usbip'
Making all in libsrc
make[2]: Entering directory '/home/vadim/git/linux-orig/tools/usb/usbip/
libsrc'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/vadim/git/linux-orig/tools/usb/usbip/libsrc'
Making all in src
make[2]: Entering directory '/home/vadim/git/linux-orig/tools/usb/usbip/src'
CC usbip_network.o
usbip_network.c: In function ‘usbip_net_pack_usb_device’:
usbip_network.c:79:32: error: taking address of packed member of ‘struct
usbip_usb_device’ may result in an unaligned pointer value [-Werror=address-
of-packed-member]
79 | usbip_net_pack_uint32_t(pack, &udev->busnum);
| ^~~~~~~~~~~~~
usbip_network.c:80:32: error: taking address of packed member of ‘struct
usbip_usb_device’ may result in an unaligned pointer value [-Werror=address-
of-packed-member]
80 | usbip_net_pack_uint32_t(pack, &udev->devnum);
| ^~~~~~~~~~~~~
usbip_network.c:81:32: error: taking address of packed member of ‘struct
usbip_usb_device’ may result in an unaligned pointer value [-Werror=address-
of-packed-member]
81 | usbip_net_pack_uint32_t(pack, &udev->speed);
| ^~~~~~~~~~~~
usbip_network.c:83:32: error: taking address of packed member of ‘struct
usbip_usb_device’ may result in an unaligned pointer value [-Werror=address-
of-packed-member]
83 | usbip_net_pack_uint16_t(pack, &udev->idVendor);
| ^~~~~~~~~~~~~~~
usbip_network.c:84:32: error: taking address of packed member of ‘struct
usbip_usb_device’ may result in an unaligned pointer value [-Werror=address-
of-packed-member]
84 | usbip_net_pack_uint16_t(pack, &udev->idProduct);
| ^~~~~~~~~~~~~~~~
usbip_network.c:85:32: error: taking address of packed member of ‘struct
usbip_usb_device’ may result in an unaligned pointer value [-Werror=address-
of-packed-member]
85 | usbip_net_pack_uint16_t(pack, &udev->bcdDevice);
| ^~~~~~~~~~~~~~~~
In file included from usbip_network.c:21:
usbip_network.c: In function ‘usbip_net_send_op_common’:
usbip_network.h:36:32: error: taking address of packed member of ‘struct
op_common’ may result in an unaligned pointer value [-Werror=address-of-
packed-member]
36 | usbip_net_pack_uint16_t(pack, &(op_common)->version);\
| ^~~~~~~~~~~~~~~~~~~~~
usbip_network.c:143:2: note: in expansion of macro ‘PACK_OP_COMMON’
143 | PACK_OP_COMMON(1, &op_common);
| ^~~~~~~~~~~~~~
usbip_network.h:37:32: error: taking address of packed member of ‘struct
op_common’ may result in an unaligned pointer value [-Werror=address-of-
packed-member]
37 | usbip_net_pack_uint16_t(pack, &(op_common)->code);\
| ^~~~~~~~~~~~~~~~~~
usbip_network.c:143:2: note: in expansion of macro ‘PACK_OP_COMMON’
143 | PACK_OP_COMMON(1, &op_common);
| ^~~~~~~~~~~~~~
usbip_network.h:38:32: error: taking address of packed member of ‘struct
op_common’ may result in an unaligned pointer value [-Werror=address-of-
packed-member]
38 | usbip_net_pack_uint32_t(pack, &(op_common)->status);\
| ^~~~~~~~~~~~~~~~~~~~
usbip_network.c:143:2: note: in expansion of macro ‘PACK_OP_COMMON’
143 | PACK_OP_COMMON(1, &op_common);
| ^~~~~~~~~~~~~~
usbip_network.c: In function ‘usbip_net_recv_op_common’:
usbip_network.h:36:32: error: taking address of packed member of ‘struct
op_common’ may result in an unaligned pointer value [-Werror=address-of-
packed-member]
36 | usbip_net_pack_uint16_t(pack, &(op_common)->version);\
| ^~~~~~~~~~~~~~~~~~~~~
usbip_network.c:167:2: note: in expansion of macro ‘PACK_OP_COMMON’
167 | PACK_OP_COMMON(0, &op_common);
| ^~~~~~~~~~~~~~
usbip_network.h:37:32: error: taking address of packed member of ‘struct
op_common’ may result in an unaligned pointer value [-Werror=address-of-
packed-member]
37 | usbip_net_pack_uint16_t(pack, &(op_common)->code);\
| ^~~~~~~~~~~~~~~~~~
usbip_network.c:167:2: note: in expansion of macro ‘PACK_OP_COMMON’
167 | PACK_OP_COMMON(0, &op_common);
| ^~~~~~~~~~~~~~
usbip_network.h:38:32: error: taking address of packed member of ‘struct
op_common’ may result in an unaligned pointer value [-Werror=address-of-
packed-member]
38 | usbip_net_pack_uint32_t(pack, &(op_common)->status);\
| ^~~~~~~~~~~~~~~~~~~~
usbip_network.c:167:2: note: in expansion of macro ‘PACK_OP_COMMON’
167 | PACK_OP_COMMON(0, &op_common);
| ^~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:430: usbip_network.o] Error 1
make[2]: Leaving directory '/home/vadim/git/linux-orig/tools/usb/usbip/src'
make[1]: *** [Makefile:497: all-recursive] Error 1
make[1]: Leaving directory '/home/vadim/git/linux-orig/tools/usb/usbip'
make: *** [Makefile:365: all] Error 2
It looks like this is due to gcc having added new warnings. For now I've
worked around it with -Wno-error=address-of-packed-member as I understand this
isn't a problem on x86.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: usbip tools from 5.4 fail to build due to unaligned pointer value warning
2019-11-29 12:24 usbip tools from 5.4 fail to build due to unaligned pointer value warning Vadim Troshchinskiy
@ 2019-11-29 13:33 ` Greg KH
2019-11-29 13:49 ` Vadim Troshchinskiy
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2019-11-29 13:33 UTC (permalink / raw)
To: Vadim Troshchinskiy; +Cc: linux-usb
On Fri, Nov 29, 2019 at 01:24:30PM +0100, Vadim Troshchinskiy wrote:
> Hello,
>
> Building the usbip tools from 4.15 is failing under Fedora 30, gcc version
> 9.2.1:
When 4.15 was released, there was no such gcc version :)
4.15 is long end-of-life, please use a more modern kernel release with
newer versions of gcc.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: usbip tools from 5.4 fail to build due to unaligned pointer value warning
2019-11-29 13:33 ` Greg KH
@ 2019-11-29 13:49 ` Vadim Troshchinskiy
2019-11-29 14:17 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Vadim Troshchinskiy @ 2019-11-29 13:49 UTC (permalink / raw)
To: Greg KH; +Cc: linux-usb
В письме от пятница, 29 ноября 2019 г. 14:33:27 CET пользователь Greg KH
написал:
> On Fri, Nov 29, 2019 at 01:24:30PM +0100, Vadim Troshchinskiy wrote:
> > Hello,
> >
> > Building the usbip tools from 4.15 is failing under Fedora 30, gcc version
>
> > 9.2.1:
> When 4.15 was released, there was no such gcc version :)
>
> 4.15 is long end-of-life, please use a more modern kernel release with
> newer versions of gcc.
Ah, my apologies, had a bit of a mix-up here. This compilation problem was on
v5.4 as it says in the title, I'm working on porting something from 4.15 and
accidentally put that there.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: usbip tools from 5.4 fail to build due to unaligned pointer value warning
2019-11-29 13:49 ` Vadim Troshchinskiy
@ 2019-11-29 14:17 ` Greg KH
2019-12-03 9:41 ` Vadim Troshchinskiy
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2019-11-29 14:17 UTC (permalink / raw)
To: Vadim Troshchinskiy; +Cc: linux-usb
On Fri, Nov 29, 2019 at 02:49:45PM +0100, Vadim Troshchinskiy wrote:
> В письме от пятница, 29 ноября 2019 г. 14:33:27 CET пользователь Greg KH
> написал:
> > On Fri, Nov 29, 2019 at 01:24:30PM +0100, Vadim Troshchinskiy wrote:
> > > Hello,
> > >
> > > Building the usbip tools from 4.15 is failing under Fedora 30, gcc version
> >
> > > 9.2.1:
> > When 4.15 was released, there was no such gcc version :)
> >
> > 4.15 is long end-of-life, please use a more modern kernel release with
> > newer versions of gcc.
>
> Ah, my apologies, had a bit of a mix-up here. This compilation problem was on
> v5.4 as it says in the title, I'm working on porting something from 4.15 and
> accidentally put that there.
Ah, sorry about that.
Send patches on, odds are no one has tried this yet.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: usbip tools from 5.4 fail to build due to unaligned pointer value warning
2019-11-29 14:17 ` Greg KH
@ 2019-12-03 9:41 ` Vadim Troshchinskiy
2019-12-10 10:25 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Vadim Troshchinskiy @ 2019-12-03 9:41 UTC (permalink / raw)
To: Greg KH; +Cc: linux-usb
В письме от пятница, 29 ноября 2019 г. 15:17:13 CET пользователь Greg KH написал:
> On Fri, Nov 29, 2019 at 02:49:45PM +0100, Vadim Troshchinskiy wrote:
> > В письме от пятница, 29 ноября 2019 г. 14:33:27 CET пользователь Greg KH
> >
> > написал:
> > > On Fri, Nov 29, 2019 at 01:24:30PM +0100, Vadim Troshchinskiy wrote:
> > > > Hello,
> > > >
> > > > Building the usbip tools from 4.15 is failing under Fedora 30, gcc
> > > > version
> > >
> > > > 9.2.1:
> > > When 4.15 was released, there was no such gcc version :)
> > >
> > > 4.15 is long end-of-life, please use a more modern kernel release with
> > > newer versions of gcc.
> >
> > Ah, my apologies, had a bit of a mix-up here. This compilation problem was
> > on v5.4 as it says in the title, I'm working on porting something from
> > 4.15 and accidentally put that there.
>
> Ah, sorry about that.
>
> Send patches on, odds are no one has tried this yet.
Okay, how does this look?
From db04ae3c88f605f900cf4e9d7a27a849bf6222a3 Mon Sep 17 00:00:00 2001
From: Vadim Troshchinskiy <vtroshchinskiy@qindel.com>
Date: Tue, 3 Dec 2019 10:31:25 +0100
Subject: [PATCH] Remove unaligned pointer usage from usbip tools.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The usbip tools use packed structs for network communication. Taking the
address of a packed member of a struct can crash the program with SIGBUS
on architectures with strict alignment requirements.
Also, recent versions of GCC detect this situation and emit a warning that
is fatal due to -Werror being used.
error: taking address of packed member of ‘struct
usbip_usb_device’ may result in an unaligned pointer value [-Werror=address-
of-packed-member]
Fix this by copying the data to an aligned location and operating there.
---
tools/usb/usbip/src/usbip_network.c | 30 +++++++++++++++--------------
tools/usb/usbip/src/usbip_network.h | 12 ++++++------
2 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/tools/usb/usbip/src/usbip_network.c b/tools/usb/usbip/src/usbip_network.c
index d595d72693fb..1c0038ee0abd 100644
--- a/tools/usb/usbip/src/usbip_network.c
+++ b/tools/usb/usbip/src/usbip_network.c
@@ -50,39 +50,41 @@ void usbip_setup_port_number(char *arg)
info("using port %d (\"%s\")", usbip_port, usbip_port_string);
}
-void usbip_net_pack_uint32_t(int pack, uint32_t *num)
+void usbip_net_pack_uint32_t(int pack, uint8_t *num)
{
uint32_t i;
+ memcpy(&i, num, sizeof(i));
if (pack)
- i = htonl(*num);
+ i = htonl(i);
else
- i = ntohl(*num);
+ i = ntohl(i);
- *num = i;
+ memcpy(num, &i, sizeof(i));
}
-void usbip_net_pack_uint16_t(int pack, uint16_t *num)
+void usbip_net_pack_uint16_t(int pack, uint8_t *num)
{
uint16_t i;
+ memcpy(&i, num, sizeof(i));
if (pack)
- i = htons(*num);
+ i = htons(i);
else
- i = ntohs(*num);
+ i = ntohs(i);
- *num = i;
+ memcpy(num, &i, sizeof(i));
}
void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev)
{
- usbip_net_pack_uint32_t(pack, &udev->busnum);
- usbip_net_pack_uint32_t(pack, &udev->devnum);
- usbip_net_pack_uint32_t(pack, &udev->speed);
+ usbip_net_pack_uint32_t(pack, (uint8_t*)&udev->busnum);
+ usbip_net_pack_uint32_t(pack, (uint8_t*)&udev->devnum);
+ usbip_net_pack_uint32_t(pack, (uint8_t*)&udev->speed);
- usbip_net_pack_uint16_t(pack, &udev->idVendor);
- usbip_net_pack_uint16_t(pack, &udev->idProduct);
- usbip_net_pack_uint16_t(pack, &udev->bcdDevice);
+ usbip_net_pack_uint16_t(pack, (uint8_t*)&udev->idVendor);
+ usbip_net_pack_uint16_t(pack, (uint8_t*)&udev->idProduct);
+ usbip_net_pack_uint16_t(pack, (uint8_t*)&udev->bcdDevice);
}
void usbip_net_pack_usb_interface(int pack __attribute__((unused)),
diff --git a/tools/usb/usbip/src/usbip_network.h b/tools/usb/usbip/src/usbip_network.h
index 555215eae43e..821dd65877cc 100644
--- a/tools/usb/usbip/src/usbip_network.h
+++ b/tools/usb/usbip/src/usbip_network.h
@@ -33,9 +33,9 @@ struct op_common {
} __attribute__((packed));
#define PACK_OP_COMMON(pack, op_common) do {\
- usbip_net_pack_uint16_t(pack, &(op_common)->version);\
- usbip_net_pack_uint16_t(pack, &(op_common)->code);\
- usbip_net_pack_uint32_t(pack, &(op_common)->status);\
+ usbip_net_pack_uint16_t(pack, (uint8_t*)&(op_common)->version);\
+ usbip_net_pack_uint16_t(pack, (uint8_t*)&(op_common)->code);\
+ usbip_net_pack_uint32_t(pack, (uint8_t*)&(op_common)->status);\
} while (0)
/* ---------------------------------------------------------------------- */
@@ -163,11 +163,11 @@ struct op_devlist_reply_extra {
} while (0)
#define PACK_OP_DEVLIST_REPLY(pack, reply) do {\
- usbip_net_pack_uint32_t(pack, &(reply)->ndev);\
+ usbip_net_pack_uint32_t(pack, (uint8_t*)&(reply)->ndev);\
} while (0)
-void usbip_net_pack_uint32_t(int pack, uint32_t *num);
-void usbip_net_pack_uint16_t(int pack, uint16_t *num);
+void usbip_net_pack_uint32_t(int pack, uint8_t *num);
+void usbip_net_pack_uint16_t(int pack, uint8_t *num);
void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev);
void usbip_net_pack_usb_interface(int pack, struct usbip_usb_interface *uinf);
--
2.21.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: usbip tools from 5.4 fail to build due to unaligned pointer value warning
2019-12-03 9:41 ` Vadim Troshchinskiy
@ 2019-12-10 10:25 ` Greg KH
0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2019-12-10 10:25 UTC (permalink / raw)
To: Vadim Troshchinskiy; +Cc: linux-usb
On Tue, Dec 03, 2019 at 10:41:41AM +0100, Vadim Troshchinskiy wrote:
> В письме от пятница, 29 ноября 2019 г. 15:17:13 CET пользователь Greg KH написал:
> > On Fri, Nov 29, 2019 at 02:49:45PM +0100, Vadim Troshchinskiy wrote:
> > > В письме от пятница, 29 ноября 2019 г. 14:33:27 CET пользователь Greg KH
> > >
> > > написал:
> > > > On Fri, Nov 29, 2019 at 01:24:30PM +0100, Vadim Troshchinskiy wrote:
> > > > > Hello,
> > > > >
> > > > > Building the usbip tools from 4.15 is failing under Fedora 30, gcc
> > > > > version
> > > >
> > > > > 9.2.1:
> > > > When 4.15 was released, there was no such gcc version :)
> > > >
> > > > 4.15 is long end-of-life, please use a more modern kernel release with
> > > > newer versions of gcc.
> > >
> > > Ah, my apologies, had a bit of a mix-up here. This compilation problem was
> > > on v5.4 as it says in the title, I'm working on porting something from
> > > 4.15 and accidentally put that there.
> >
> > Ah, sorry about that.
> >
> > Send patches on, odds are no one has tried this yet.
>
> Okay, how does this look?
>
>
> >From db04ae3c88f605f900cf4e9d7a27a849bf6222a3 Mon Sep 17 00:00:00 2001
> From: Vadim Troshchinskiy <vtroshchinskiy@qindel.com>
> Date: Tue, 3 Dec 2019 10:31:25 +0100
> Subject: [PATCH] Remove unaligned pointer usage from usbip tools.
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> The usbip tools use packed structs for network communication. Taking the
> address of a packed member of a struct can crash the program with SIGBUS
> on architectures with strict alignment requirements.
>
> Also, recent versions of GCC detect this situation and emit a warning that
> is fatal due to -Werror being used.
>
> error: taking address of packed member of ‘struct
> usbip_usb_device’ may result in an unaligned pointer value [-Werror=address-
> of-packed-member]
>
> Fix this by copying the data to an aligned location and operating there.
> ---
> tools/usb/usbip/src/usbip_network.c | 30 +++++++++++++++--------------
> tools/usb/usbip/src/usbip_network.h | 12 ++++++------
> 2 files changed, 22 insertions(+), 20 deletions(-)
Can you resend this in a format that I can apply it, with a correct
signed-off-by and copying the usbip maintainer as well?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-12-10 10:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29 12:24 usbip tools from 5.4 fail to build due to unaligned pointer value warning Vadim Troshchinskiy
2019-11-29 13:33 ` Greg KH
2019-11-29 13:49 ` Vadim Troshchinskiy
2019-11-29 14:17 ` Greg KH
2019-12-03 9:41 ` Vadim Troshchinskiy
2019-12-10 10:25 ` Greg KH
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).