can: isotp: isotp_setsockopt(): block setsockopt on bound sockets
authorOliver Hartkopp <socketcan@hartkopp.net>
Fri, 4 Dec 2020 13:35:07 +0000 (14:35 +0100)
committerJakub Kicinski <kuba@kernel.org>
Wed, 9 Dec 2020 16:44:15 +0000 (08:44 -0800)
The isotp socket can be widely configured in its behaviour regarding addressing
types, fill-ups, receive pattern tests and link layer length. Usually all
these settings need to be fixed before bind() and can not be changed
afterwards.

This patch adds a check to enforce the common usage pattern.

Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Thomas Wagner <thwa1@web.de>
Link: https://lore.kernel.org/r/20201203140604.25488-2-socketcan@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://lore.kernel.org/r/20201204133508.742120-3-mkl@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/can/isotp.c

index d78ab13bd8be99554a5d4873e4d6b7081cf289d3..26bdc3c20b7e4863da9afd099cb07939f3d1d549 100644 (file)
@@ -1157,6 +1157,9 @@ static int isotp_setsockopt(struct socket *sock, int level, int optname,
        if (level != SOL_CAN_ISOTP)
                return -EINVAL;
 
+       if (so->bound)
+               return -EISCONN;
+
        switch (optname) {
        case CAN_ISOTP_OPTS:
                if (optlen != sizeof(struct can_isotp_options))