diff options
Diffstat (limited to 'net/can/bcm.c')
-rw-r--r-- | net/can/bcm.c | 27 |
1 files changed, 27 insertions, 0 deletions
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 */ | ||
147 | static 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) { |