]> git.baikalelectronics.ru Git - kernel.git/commit
can: raw: return -ERANGE when filterset does not fit into user space buffer
authorOliver Hartkopp <socketcan@hartkopp.net>
Wed, 16 Dec 2020 17:49:28 +0000 (18:49 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 6 Jan 2021 14:15:41 +0000 (15:15 +0100)
commitb6266f593c417cf2e3553c60c8527ee97282e6f6
tree6608e6eb6aa46b8595831985707b47c94c319dc8
parent035d5fdcb7595a0b64c6a8556f77662ed7874981
can: raw: return -ERANGE when filterset does not fit into user space buffer

Multiple filters (struct can_filter) can be set with the setsockopt()
function, which was originally intended as a write-only operation.

As getsockopt() also provides a CAN_RAW_FILTER option to read back the
given filters, the caller has to provide an appropriate user space buffer.
In the case this buffer is too small the getsockopt() silently truncates
the filter information and gives no information about the needed space.
This is safe but not convenient for the programmer.

In net/core/sock.c the SO_PEERGROUPS sockopt had a similar requirement
and solved it by returning -ERANGE in the case that the provided data
does not fit into the given user space buffer and fills the required size
into optlen, so that the caller can retry with a matching buffer length.

This patch adopts this approach for CAN_RAW_FILTER getsockopt().

Reported-by: Phillip Schichtel <phillip@schich.tel>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-By: Phillip Schichtel <phillip@schich.tel>
Link: https://lore.kernel.org/r/20201216174928.21663-1-socketcan@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
net/can/raw.c