aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorOliver Hartkopp <socketcan@hartkopp.net>2015-01-05 12:40:15 -0500
committerMarc Kleine-Budde <mkl@pengutronix.de>2015-01-15 10:57:59 -0500
commit9b1087aa5e86448fe6ad40a58964e35f3ba423d5 (patch)
tree8636f06d98c2e7c907e88ca91d1928ec9ea47279 /drivers/net
parent870482a4190007bb8aed45c6ebcbfc03369241d2 (diff)
can: dev: fix crtlmode_supported check
When changing flags in the CAN drivers ctrlmode the provided new content has to be checked whether the bits are allowed to be changed. The bits that are to be changed are given as a bitfield in cm->mask. Therefore checking against cm->flags is wrong as the content can hold any kind of values. The iproute2 tool sets the bits in cm->mask and cm->flags depending on the detected command line options. To be robust against bogus user space applications additionally sanitize the provided flags with the provided mask. Cc: Wolfgang Grandegger <wg@grandegger.com> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Cc: linux-stable <stable@vger.kernel.org> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/can/dev.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 3ec8f6f25e5f..847c1f813261 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -807,10 +807,14 @@ static int can_changelink(struct net_device *dev,
807 if (dev->flags & IFF_UP) 807 if (dev->flags & IFF_UP)
808 return -EBUSY; 808 return -EBUSY;
809 cm = nla_data(data[IFLA_CAN_CTRLMODE]); 809 cm = nla_data(data[IFLA_CAN_CTRLMODE]);
810 if (cm->flags & ~priv->ctrlmode_supported) 810
811 /* check whether changed bits are allowed to be modified */
812 if (cm->mask & ~priv->ctrlmode_supported)
811 return -EOPNOTSUPP; 813 return -EOPNOTSUPP;
814
815 /* clear bits to be modified and copy the flag values */
812 priv->ctrlmode &= ~cm->mask; 816 priv->ctrlmode &= ~cm->mask;
813 priv->ctrlmode |= cm->flags; 817 priv->ctrlmode |= (cm->flags & cm->mask);
814 818
815 /* CAN_CTRLMODE_FD can only be set when driver supports FD */ 819 /* CAN_CTRLMODE_FD can only be set when driver supports FD */
816 if (priv->ctrlmode & CAN_CTRLMODE_FD) 820 if (priv->ctrlmode & CAN_CTRLMODE_FD)