USB gadget rndis: fix bug skb_push function may return an unaligned pointer bug
PATCH 1/1 USB gadget rndis: fix bug skb_push function may return an unaligned pointer bug
USB gadget rndis: skb_push function may return a pointer which is not aligned as required by struct rndis_packet_msg_type.
--- drivers/usb/gadget/rndis.c | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-)
drivers/usb/gadget/rndis.c +12 -7
@@ -1211,18 +1211,23 @@ int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)return 0 ; } +/* The pointer of header is not aligned, it will cause alignment exception. +* Use a temporary variable to avoid it. +*/ void rndis_add_hdr (struct sk_buff *skb) { -struct rndis_packet_msg_type *header; +void *buf; +struct rndis_packet_msg_type *header;if (!skb)return ; - header = (void *)skb_push (skb,sizeof *header); -memset (header,0 ,sizeof *header); - header->MessageType =__constant_cpu_to_le32 (REMOTE_NDIS_PACKET_MSG ); - header->MessageLength =cpu_to_le32 (skb->len); - header->DataOffset =__constant_cpu_to_le32 (36 ); - header->DataLength =cpu_to_le32 (skb->len -sizeof *header); + buf = (void *)skb_push (skb,sizeof *header); +memset (buf,0 ,sizeof *header); + header = (struct rndis_packet_msg_type *)buf; +put_unaligned (__constant_cpu_to_le32 (REMOTE_NDIS_PACKET_MSG ), &header->MessageType); +put_unaligned (cpu_to_le32 (skb->len), &header->MessageLength); +put_unaligned (__constant_cpu_to_le32 (36 ), &header->DataOffset); +put_unaligned (cpu_to_le32 (skb->len -sizeof *header), &header->DataLength); }void rndis_free_response (int configNr,u8 *buf)
Signature · 1 line
1.5.0.5
Quoted 2 lines · Bryan
USB gadget rndis:
skb_pushfunction may return a pointer which is not aligned as required by structrndis_packet_msg_type.
Can you instead try to update the declaration of that struct so that it's "__attribute__((packed))"? That's less invasive, and will address similar issues elsewhere ...
- Dave
Quoted 9 lines · David Brownell
Quoted 2 lines · Bryan
USB gadget rndis:
skb_pushfunction may return a pointer which is not aligned as required by structrndis_packet_msg_type.Can you instead try to update the declaration of that struct so that it's "__attribute__((packed))"? That's less invasive, and will address similar issues elsewhere ...
- Dave
OK, Jie and Roy will try to use this __attribute__ method and test it on blackfin platform. Sorry for missing their "Signed-off-by". I will resend a patch later for review.
Thanks
-Bryan
PATCH 1/1 USB gadget rndis: fix struct rndis_packet_msg_type unaligned bug
[PATCH] usb gadget rndis:skb_push function may return a pointer which is not aligned as required by struct rndis_packet_msg_type. Using attribute trick to fix this bug.
--- drivers/usb/gadget/rndis.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/usb/gadget/rndis.h +1 -1
@@ -195,7 +195,7 @@ struct rndis_packet_msg_type__le32 PerPacketInfoLength;__le32 VcHandle;__le32 Reserved; -}; +} __attribute__ ((packed));struct rndis_config_parameter {
Signature · 1 line
1.5.0.5