Skip to content

Commit 083021b

Browse files
marckleinebuddegregkh
authored andcommitted
can: raw: raw_setsockopt: limit number of can_filter that can be set
commit 332b05ca7a438f857c61a3c21a88489a21532364 upstream. This patch adds a check to limit the number of can_filters that can be set via setsockopt on CAN_RAW sockets. Otherwise allocations > MAX_ORDER are not prevented resulting in a warning. Reference: https://lkml.org/lkml/2016/12/2/230 Reported-by: Andrey Konovalov <andreyknvl@google.com> Tested-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9a3baed commit 083021b

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

include/uapi/linux/can.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,6 @@ struct can_filter {
196196
};
197197

198198
#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
199+
#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */
199200

200201
#endif /* !_UAPI_CAN_H */

net/can/raw.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
499499
if (optlen % sizeof(struct can_filter) != 0)
500500
return -EINVAL;
501501

502+
if (optlen > CAN_RAW_FILTER_MAX * sizeof(struct can_filter))
503+
return -EINVAL;
504+
502505
count = optlen / sizeof(struct can_filter);
503506

504507
if (count > 1) {

0 commit comments

Comments
 (0)