Return-Path: Received: from mx2.suse.de ([195.135.220.15]:43388 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755765AbdABMpt (ORCPT ); Mon, 2 Jan 2017 07:45:49 -0500 From: Jiri Slaby To: stable@vger.kernel.org Cc: Marc Kleine-Budde , Jiri Slaby Subject: [patch added to 3.12-stable] can: raw: raw_setsockopt: limit number of can_filter that can be set Date: Mon, 2 Jan 2017 13:45:38 +0100 Message-Id: <20170102124541.18653-4-jslaby@suse.cz> In-Reply-To: <20170102124541.18653-1-jslaby@suse.cz> References: <20170102124541.18653-1-jslaby@suse.cz> Sender: stable-owner@vger.kernel.org List-ID: From: Marc Kleine-Budde This patch has been added to the 3.12 stable tree. If you have any objections, please let us know. =============== 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 Tested-by: Andrey Konovalov Signed-off-by: Marc Kleine-Budde Signed-off-by: Jiri Slaby --- include/uapi/linux/can.h | 1 + net/can/raw.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/uapi/linux/can.h b/include/uapi/linux/can.h index e52958d7c2d1..3018528bd1bf 100644 --- a/include/uapi/linux/can.h +++ b/include/uapi/linux/can.h @@ -158,5 +158,6 @@ struct can_filter { }; #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */ +#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */ #endif /* CAN_H */ diff --git a/net/can/raw.c b/net/can/raw.c index 641e1c895123..e10699cc72bd 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -470,6 +470,9 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, if (optlen % sizeof(struct can_filter) != 0) return -EINVAL; + if (optlen > CAN_RAW_FILTER_MAX * sizeof(struct can_filter)) + return -EINVAL; + count = optlen / sizeof(struct can_filter); if (count > 1) { -- 2.11.0