aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2019-01-25 00:52:37 -0500
committerDavid S. Miller <davem@davemloft.net>2019-01-25 00:52:37 -0500
commit9620d6f6833e22b7168caf0665bd43478ef58cb5 (patch)
tree698072761b25edae08fae2858b7808e4da609cc3
parent21507dc46adc691098724775287a8855fb4c8fa3 (diff)
parenta55234dabe1f72cf22f9197980751d37e38ba020 (diff)
Merge tag 'linux-can-fixes-for-5.0-20190122' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2019-01-22 this is a pull request of 4 patches for net/master. The first patch by is by Manfred Schlaegl and reverts a patch that caused wrong warning messages in certain use cases. The next patch is by Oliver Hartkopp for the bcm that adds sanity checks for the timer value before using it to detect potential interger overflows. The last two patches are for the flexcan driver, YueHaibing's patch fixes the the return value in the error path of the flexcan_setup_stop_mode() function. The second patch is by Uwe Kleine-König and fixes a NULL pointer deref on older flexcan cores in flexcan_chip_start(). ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/can/dev.c27
-rw-r--r--drivers/net/can/flexcan.c4
-rw-r--r--net/can/bcm.c27
3 files changed, 42 insertions, 16 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 3b3f88ffab53..c05e4d50d43d 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -480,8 +480,6 @@ EXPORT_SYMBOL_GPL(can_put_echo_skb);
480struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr) 480struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr)
481{ 481{
482 struct can_priv *priv = netdev_priv(dev); 482 struct can_priv *priv = netdev_priv(dev);
483 struct sk_buff *skb = priv->echo_skb[idx];
484 struct canfd_frame *cf;
485 483
486 if (idx >= priv->echo_skb_max) { 484 if (idx >= priv->echo_skb_max) {
487 netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n", 485 netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n",
@@ -489,20 +487,21 @@ struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8
489 return NULL; 487 return NULL;
490 } 488 }
491 489
492 if (!skb) { 490 if (priv->echo_skb[idx]) {
493 netdev_err(dev, "%s: BUG! Trying to echo non existing skb: can_priv::echo_skb[%u]\n", 491 /* Using "struct canfd_frame::len" for the frame
494 __func__, idx); 492 * length is supported on both CAN and CANFD frames.
495 return NULL; 493 */
496 } 494 struct sk_buff *skb = priv->echo_skb[idx];
495 struct canfd_frame *cf = (struct canfd_frame *)skb->data;
496 u8 len = cf->len;
497 497
498 /* Using "struct canfd_frame::len" for the frame 498 *len_ptr = len;
499 * length is supported on both CAN and CANFD frames. 499 priv->echo_skb[idx] = NULL;
500 */
501 cf = (struct canfd_frame *)skb->data;
502 *len_ptr = cf->len;
503 priv->echo_skb[idx] = NULL;
504 500
505 return skb; 501 return skb;
502 }
503
504 return NULL;
506} 505}
507 506
508/* 507/*
diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 0f36eafe3ac1..1c66fb2ad76b 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -1106,7 +1106,7 @@ static int flexcan_chip_start(struct net_device *dev)
1106 } 1106 }
1107 } else { 1107 } else {
1108 /* clear and invalidate unused mailboxes first */ 1108 /* clear and invalidate unused mailboxes first */
1109 for (i = FLEXCAN_TX_MB_RESERVED_OFF_FIFO; i <= priv->mb_count; i++) { 1109 for (i = FLEXCAN_TX_MB_RESERVED_OFF_FIFO; i < priv->mb_count; i++) {
1110 mb = flexcan_get_mb(priv, i); 1110 mb = flexcan_get_mb(priv, i);
1111 priv->write(FLEXCAN_MB_CODE_RX_INACTIVE, 1111 priv->write(FLEXCAN_MB_CODE_RX_INACTIVE,
1112 &mb->can_ctrl); 1112 &mb->can_ctrl);
@@ -1432,7 +1432,7 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
1432 gpr_np = of_find_node_by_phandle(phandle); 1432 gpr_np = of_find_node_by_phandle(phandle);
1433 if (!gpr_np) { 1433 if (!gpr_np) {
1434 dev_dbg(&pdev->dev, "could not find gpr node by phandle\n"); 1434 dev_dbg(&pdev->dev, "could not find gpr node by phandle\n");
1435 return PTR_ERR(gpr_np); 1435 return -ENODEV;
1436 } 1436 }
1437 1437
1438 priv = netdev_priv(dev); 1438 priv = netdev_priv(dev);
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 0af8f0db892a..79bb8afa9c0c 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -67,6 +67,9 @@
67 */ 67 */
68#define MAX_NFRAMES 256 68#define MAX_NFRAMES 256
69 69
70/* limit timers to 400 days for sending/timeouts */
71#define BCM_TIMER_SEC_MAX (400 * 24 * 60 * 60)
72
70/* use of last_frames[index].flags */ 73/* use of last_frames[index].flags */
71#define RX_RECV 0x40 /* received data for this element */ 74#define RX_RECV 0x40 /* received data for this element */
72#define RX_THR 0x80 /* element not been sent due to throttle feature */ 75#define RX_THR 0x80 /* element not been sent due to throttle feature */
@@ -140,6 +143,22 @@ static inline ktime_t bcm_timeval_to_ktime(struct bcm_timeval tv)
140 return ktime_set(tv.tv_sec, tv.tv_usec * NSEC_PER_USEC); 143 return ktime_set(tv.tv_sec, tv.tv_usec * NSEC_PER_USEC);
141} 144}
142 145
146/* check limitations for timeval provided by user */
147static bool bcm_is_invalid_tv(struct bcm_msg_head *msg_head)
148{
149 if ((msg_head->ival1.tv_sec < 0) ||
150 (msg_head->ival1.tv_sec > BCM_TIMER_SEC_MAX) ||
151 (msg_head->ival1.tv_usec < 0) ||
152 (msg_head->ival1.tv_usec >= USEC_PER_SEC) ||
153 (msg_head->ival2.tv_sec < 0) ||
154 (msg_head->ival2.tv_sec > BCM_TIMER_SEC_MAX) ||
155 (msg_head->ival2.tv_usec < 0) ||
156 (msg_head->ival2.tv_usec >= USEC_PER_SEC))
157 return true;
158
159 return false;
160}
161
143#define CFSIZ(flags) ((flags & CAN_FD_FRAME) ? CANFD_MTU : CAN_MTU) 162#define CFSIZ(flags) ((flags & CAN_FD_FRAME) ? CANFD_MTU : CAN_MTU)
144#define OPSIZ sizeof(struct bcm_op) 163#define OPSIZ sizeof(struct bcm_op)
145#define MHSIZ sizeof(struct bcm_msg_head) 164#define MHSIZ sizeof(struct bcm_msg_head)
@@ -873,6 +892,10 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
873 if (msg_head->nframes < 1 || msg_head->nframes > MAX_NFRAMES) 892 if (msg_head->nframes < 1 || msg_head->nframes > MAX_NFRAMES)
874 return -EINVAL; 893 return -EINVAL;
875 894
895 /* check timeval limitations */
896 if ((msg_head->flags & SETTIMER) && bcm_is_invalid_tv(msg_head))
897 return -EINVAL;
898
876 /* check the given can_id */ 899 /* check the given can_id */
877 op = bcm_find_op(&bo->tx_ops, msg_head, ifindex); 900 op = bcm_find_op(&bo->tx_ops, msg_head, ifindex);
878 if (op) { 901 if (op) {
@@ -1053,6 +1076,10 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
1053 (!(msg_head->can_id & CAN_RTR_FLAG)))) 1076 (!(msg_head->can_id & CAN_RTR_FLAG))))
1054 return -EINVAL; 1077 return -EINVAL;
1055 1078
1079 /* check timeval limitations */
1080 if ((msg_head->flags & SETTIMER) && bcm_is_invalid_tv(msg_head))
1081 return -EINVAL;
1082
1056 /* check the given can_id */ 1083 /* check the given can_id */
1057 op = bcm_find_op(&bo->rx_ops, msg_head, ifindex); 1084 op = bcm_find_op(&bo->rx_ops, msg_head, ifindex);
1058 if (op) { 1085 if (op) {