diff options
author | Oliver Hartkopp <socketcan@hartkopp.net> | 2016-11-23 08:33:25 -0500 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2016-11-23 09:22:18 -0500 |
commit | 5499a6b22e5508b921c447757685b0a5e40a07ed (patch) | |
tree | 7beb90dee5e614fd6b29068b045f778eac11d7d1 | |
parent | c9b8af1330198ae241cd545e1f040019010d44d9 (diff) |
can: bcm: fix support for CAN FD frames
Since commit 6f3b911d5f29b98 ("can: bcm: add support for CAN FD frames") the
CAN broadcast manager supports CAN and CAN FD data frames.
As these data frames are embedded in struct can[fd]_frames which have a
different length the access to the provided array of CAN frames became
dependend of op->cfsiz. By using a struct canfd_frame pointer for the array of
CAN frames the new offset calculation based on op->cfsiz was accidently applied
to CAN FD frame element lengths.
This fix makes the pointer to the arrays of the different CAN frame types a
void pointer so that the offset calculation in bytes accesses the correct CAN
frame elements.
Reference: http://marc.info/?l=linux-netdev&m=147980658909653
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Andrey Konovalov <andreyknvl@google.com>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | net/can/bcm.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/net/can/bcm.c b/net/can/bcm.c index 8af9d25ff988..436a7537e6a9 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c | |||
@@ -77,7 +77,7 @@ | |||
77 | (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \ | 77 | (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \ |
78 | (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG)) | 78 | (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG)) |
79 | 79 | ||
80 | #define CAN_BCM_VERSION "20160617" | 80 | #define CAN_BCM_VERSION "20161123" |
81 | 81 | ||
82 | MODULE_DESCRIPTION("PF_CAN broadcast manager protocol"); | 82 | MODULE_DESCRIPTION("PF_CAN broadcast manager protocol"); |
83 | MODULE_LICENSE("Dual BSD/GPL"); | 83 | MODULE_LICENSE("Dual BSD/GPL"); |
@@ -109,8 +109,9 @@ struct bcm_op { | |||
109 | u32 count; | 109 | u32 count; |
110 | u32 nframes; | 110 | u32 nframes; |
111 | u32 currframe; | 111 | u32 currframe; |
112 | struct canfd_frame *frames; | 112 | /* void pointers to arrays of struct can[fd]_frame */ |
113 | struct canfd_frame *last_frames; | 113 | void *frames; |
114 | void *last_frames; | ||
114 | struct canfd_frame sframe; | 115 | struct canfd_frame sframe; |
115 | struct canfd_frame last_sframe; | 116 | struct canfd_frame last_sframe; |
116 | struct sock *sk; | 117 | struct sock *sk; |
@@ -681,7 +682,7 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data) | |||
681 | 682 | ||
682 | if (op->flags & RX_FILTER_ID) { | 683 | if (op->flags & RX_FILTER_ID) { |
683 | /* the easiest case */ | 684 | /* the easiest case */ |
684 | bcm_rx_update_and_send(op, &op->last_frames[0], rxframe); | 685 | bcm_rx_update_and_send(op, op->last_frames, rxframe); |
685 | goto rx_starttimer; | 686 | goto rx_starttimer; |
686 | } | 687 | } |
687 | 688 | ||
@@ -1068,7 +1069,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1068 | 1069 | ||
1069 | if (msg_head->nframes) { | 1070 | if (msg_head->nframes) { |
1070 | /* update CAN frames content */ | 1071 | /* update CAN frames content */ |
1071 | err = memcpy_from_msg((u8 *)op->frames, msg, | 1072 | err = memcpy_from_msg(op->frames, msg, |
1072 | msg_head->nframes * op->cfsiz); | 1073 | msg_head->nframes * op->cfsiz); |
1073 | if (err < 0) | 1074 | if (err < 0) |
1074 | return err; | 1075 | return err; |
@@ -1118,7 +1119,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1118 | } | 1119 | } |
1119 | 1120 | ||
1120 | if (msg_head->nframes) { | 1121 | if (msg_head->nframes) { |
1121 | err = memcpy_from_msg((u8 *)op->frames, msg, | 1122 | err = memcpy_from_msg(op->frames, msg, |
1122 | msg_head->nframes * op->cfsiz); | 1123 | msg_head->nframes * op->cfsiz); |
1123 | if (err < 0) { | 1124 | if (err < 0) { |
1124 | if (op->frames != &op->sframe) | 1125 | if (op->frames != &op->sframe) |
@@ -1163,6 +1164,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1163 | /* check flags */ | 1164 | /* check flags */ |
1164 | 1165 | ||
1165 | if (op->flags & RX_RTR_FRAME) { | 1166 | if (op->flags & RX_RTR_FRAME) { |
1167 | struct canfd_frame *frame0 = op->frames; | ||
1166 | 1168 | ||
1167 | /* no timers in RTR-mode */ | 1169 | /* no timers in RTR-mode */ |
1168 | hrtimer_cancel(&op->thrtimer); | 1170 | hrtimer_cancel(&op->thrtimer); |
@@ -1174,8 +1176,8 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1174 | * prevent a full-load-loopback-test ... ;-] | 1176 | * prevent a full-load-loopback-test ... ;-] |
1175 | */ | 1177 | */ |
1176 | if ((op->flags & TX_CP_CAN_ID) || | 1178 | if ((op->flags & TX_CP_CAN_ID) || |
1177 | (op->frames[0].can_id == op->can_id)) | 1179 | (frame0->can_id == op->can_id)) |
1178 | op->frames[0].can_id = op->can_id & ~CAN_RTR_FLAG; | 1180 | frame0->can_id = op->can_id & ~CAN_RTR_FLAG; |
1179 | 1181 | ||
1180 | } else { | 1182 | } else { |
1181 | if (op->flags & SETTIMER) { | 1183 | if (op->flags & SETTIMER) { |