usbip: Fix unsafe unaligned pointer usage
[ Upstream commit 585c91f40d201bc564d4e76b83c05b3b5363fe7e ] Fix unsafe unaligned pointer usage in usbip network interfaces. usbip tool build fails with new gcc -Werror=address-of-packed-member checks. 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); Fix with minor changes to pass by value instead of by address. Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Link: https://lore.kernel.org/r/20200109012416.2875-1-skhan@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
26259921a2
commit
b957a310c9
2 changed files with 27 additions and 25 deletions
|
@ -62,39 +62,39 @@ void usbip_setup_port_number(char *arg)
|
||||||
info("using port %d (\"%s\")", usbip_port, usbip_port_string);
|
info("using port %d (\"%s\")", usbip_port, usbip_port_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbip_net_pack_uint32_t(int pack, uint32_t *num)
|
uint32_t usbip_net_pack_uint32_t(int pack, uint32_t num)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
if (pack)
|
if (pack)
|
||||||
i = htonl(*num);
|
i = htonl(num);
|
||||||
else
|
else
|
||||||
i = ntohl(*num);
|
i = ntohl(num);
|
||||||
|
|
||||||
*num = i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbip_net_pack_uint16_t(int pack, uint16_t *num)
|
uint16_t usbip_net_pack_uint16_t(int pack, uint16_t num)
|
||||||
{
|
{
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
||||||
if (pack)
|
if (pack)
|
||||||
i = htons(*num);
|
i = htons(num);
|
||||||
else
|
else
|
||||||
i = ntohs(*num);
|
i = ntohs(num);
|
||||||
|
|
||||||
*num = i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev)
|
void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev)
|
||||||
{
|
{
|
||||||
usbip_net_pack_uint32_t(pack, &udev->busnum);
|
udev->busnum = usbip_net_pack_uint32_t(pack, udev->busnum);
|
||||||
usbip_net_pack_uint32_t(pack, &udev->devnum);
|
udev->devnum = usbip_net_pack_uint32_t(pack, udev->devnum);
|
||||||
usbip_net_pack_uint32_t(pack, &udev->speed);
|
udev->speed = usbip_net_pack_uint32_t(pack, udev->speed);
|
||||||
|
|
||||||
usbip_net_pack_uint16_t(pack, &udev->idVendor);
|
udev->idVendor = usbip_net_pack_uint16_t(pack, udev->idVendor);
|
||||||
usbip_net_pack_uint16_t(pack, &udev->idProduct);
|
udev->idProduct = usbip_net_pack_uint16_t(pack, udev->idProduct);
|
||||||
usbip_net_pack_uint16_t(pack, &udev->bcdDevice);
|
udev->bcdDevice = usbip_net_pack_uint16_t(pack, udev->bcdDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbip_net_pack_usb_interface(int pack __attribute__((unused)),
|
void usbip_net_pack_usb_interface(int pack __attribute__((unused)),
|
||||||
|
@ -141,6 +141,14 @@ ssize_t usbip_net_send(int sockfd, void *buff, size_t bufflen)
|
||||||
return usbip_net_xmit(sockfd, buff, bufflen, 1);
|
return usbip_net_xmit(sockfd, buff, bufflen, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void usbip_net_pack_op_common(int pack,
|
||||||
|
struct op_common *op_common)
|
||||||
|
{
|
||||||
|
op_common->version = usbip_net_pack_uint16_t(pack, op_common->version);
|
||||||
|
op_common->code = usbip_net_pack_uint16_t(pack, op_common->code);
|
||||||
|
op_common->status = usbip_net_pack_uint32_t(pack, op_common->status);
|
||||||
|
}
|
||||||
|
|
||||||
int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status)
|
int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status)
|
||||||
{
|
{
|
||||||
struct op_common op_common;
|
struct op_common op_common;
|
||||||
|
@ -152,7 +160,7 @@ int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status)
|
||||||
op_common.code = code;
|
op_common.code = code;
|
||||||
op_common.status = status;
|
op_common.status = status;
|
||||||
|
|
||||||
PACK_OP_COMMON(1, &op_common);
|
usbip_net_pack_op_common(1, &op_common);
|
||||||
|
|
||||||
rc = usbip_net_send(sockfd, &op_common, sizeof(op_common));
|
rc = usbip_net_send(sockfd, &op_common, sizeof(op_common));
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
@ -176,7 +184,7 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code, int *status)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
PACK_OP_COMMON(0, &op_common);
|
usbip_net_pack_op_common(0, &op_common);
|
||||||
|
|
||||||
if (op_common.version != USBIP_VERSION) {
|
if (op_common.version != USBIP_VERSION) {
|
||||||
err("USBIP Kernel and tool version mismatch: %d %d:",
|
err("USBIP Kernel and tool version mismatch: %d %d:",
|
||||||
|
|
|
@ -32,12 +32,6 @@ struct op_common {
|
||||||
|
|
||||||
} __attribute__((packed));
|
} __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);\
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
/* Dummy Code */
|
/* Dummy Code */
|
||||||
#define OP_UNSPEC 0x00
|
#define OP_UNSPEC 0x00
|
||||||
|
@ -163,11 +157,11 @@ struct op_devlist_reply_extra {
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define PACK_OP_DEVLIST_REPLY(pack, reply) do {\
|
#define PACK_OP_DEVLIST_REPLY(pack, reply) do {\
|
||||||
usbip_net_pack_uint32_t(pack, &(reply)->ndev);\
|
(reply)->ndev = usbip_net_pack_uint32_t(pack, (reply)->ndev);\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
void usbip_net_pack_uint32_t(int pack, uint32_t *num);
|
uint32_t usbip_net_pack_uint32_t(int pack, uint32_t num);
|
||||||
void usbip_net_pack_uint16_t(int pack, uint16_t *num);
|
uint16_t usbip_net_pack_uint16_t(int pack, uint16_t num);
|
||||||
void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev);
|
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);
|
void usbip_net_pack_usb_interface(int pack, struct usbip_usb_interface *uinf);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue