Commit b9c03b60 authored by Oliver Hartkopp's avatar Oliver Hartkopp Committed by Jiri Slaby

can: dev: fix crtlmode_supported check

commit 9b1087aa upstream.

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: default avatarOliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent e02941b0
...@@ -643,10 +643,14 @@ static int can_changelink(struct net_device *dev, ...@@ -643,10 +643,14 @@ static int can_changelink(struct net_device *dev,
if (dev->flags & IFF_UP) if (dev->flags & IFF_UP)
return -EBUSY; return -EBUSY;
cm = nla_data(data[IFLA_CAN_CTRLMODE]); cm = nla_data(data[IFLA_CAN_CTRLMODE]);
if (cm->flags & ~priv->ctrlmode_supported)
/* check whether changed bits are allowed to be modified */
if (cm->mask & ~priv->ctrlmode_supported)
return -EOPNOTSUPP; return -EOPNOTSUPP;
/* clear bits to be modified and copy the flag values */
priv->ctrlmode &= ~cm->mask; priv->ctrlmode &= ~cm->mask;
priv->ctrlmode |= cm->flags; priv->ctrlmode |= (cm->flags & cm->mask);
} }
if (data[IFLA_CAN_BITTIMING]) { if (data[IFLA_CAN_BITTIMING]) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment