linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH stable] can_dev: fix crtlmode_supported check
@ 2015-01-05 17:40 Oliver Hartkopp
  2015-01-07 13:01 ` Marc Kleine-Budde
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Hartkopp @ 2015-01-05 17:40 UTC (permalink / raw)
  To: Marc Kleine-Budde, Wolfgang Grandegger; +Cc: linux-can@vger.kernel.org

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.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
CC: Wolfgang Grandegger <wg@grandegger.com>

---

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 3ec8f6f..847c1f8 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,
  		if (dev->flags & IFF_UP)
  			return -EBUSY;
  		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;
+
+		/* clear bits to be modified and copy the flag values */
  		priv->ctrlmode &= ~cm->mask;
-		priv->ctrlmode |= cm->flags;
+		priv->ctrlmode |= (cm->flags & cm->mask);

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




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH stable] can_dev: fix crtlmode_supported check
  2015-01-05 17:40 [PATCH stable] can_dev: fix crtlmode_supported check Oliver Hartkopp
@ 2015-01-07 13:01 ` Marc Kleine-Budde
  2015-01-07 13:11   ` Marc Kleine-Budde
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2015-01-07 13:01 UTC (permalink / raw)
  To: Oliver Hartkopp, Wolfgang Grandegger; +Cc: linux-can@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1073 bytes --]

On 01/05/2015 06:40 PM, Oliver Hartkopp wrote:
> 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.
> 
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> CC: Wolfgang Grandegger <wg@grandegger.com>

Does not apply to net/master. However I've applied it by hand. v2 will
follow.

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH stable] can_dev: fix crtlmode_supported check
  2015-01-07 13:01 ` Marc Kleine-Budde
@ 2015-01-07 13:11   ` Marc Kleine-Budde
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2015-01-07 13:11 UTC (permalink / raw)
  To: Oliver Hartkopp, Wolfgang Grandegger; +Cc: linux-can@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1323 bytes --]

On 01/07/2015 02:01 PM, Marc Kleine-Budde wrote:
> On 01/05/2015 06:40 PM, Oliver Hartkopp wrote:
>> 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.
>>
>> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
>> CC: Wolfgang Grandegger <wg@grandegger.com>
> 
> Does not apply to net/master. However I've applied it by hand. v2 will
> follow.

> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0

You should consider to use git send-email instead of thunderbird to post
your patches :)

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-07 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-05 17:40 [PATCH stable] can_dev: fix crtlmode_supported check Oliver Hartkopp
2015-01-07 13:01 ` Marc Kleine-Budde
2015-01-07 13:11   ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).