Skip to content

Commit 96bfa38

Browse files
hartkoppgregkh
authored andcommitted
can: dev: fix crtlmode_supported check
commit 9b1087a 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: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 71745ce commit 96bfa38

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎drivers/net/can/dev.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,14 @@ static int can_changelink(struct net_device *dev,
729729
if (dev->flags & IFF_UP)
730730
return -EBUSY;
731731
cm = nla_data(data[IFLA_CAN_CTRLMODE]);
732-
if (cm->flags & ~priv->ctrlmode_supported)
732+
733+
/* check whether changed bits are allowed to be modified */
734+
if (cm->mask & ~priv->ctrlmode_supported)
733735
return -EOPNOTSUPP;
736+
737+
/* clear bits to be modified and copy the flag values */
734738
priv->ctrlmode &= ~cm->mask;
735-
priv->ctrlmode |= cm->flags;
739+
priv->ctrlmode |= (cm->flags & cm->mask);
736740

737741
/* CAN_CTRLMODE_FD can only be set when driver supports FD */
738742
if (priv->ctrlmode & CAN_CTRLMODE_FD)

0 commit comments

Comments
 (0)