Skip to contentSkip to conversation

can: raw: fix getsockopt() for new CAN_RAW_XL_VCID_OPTS

PATCH Applied Oliver Hartkopp 2 participants 3 messages Feb 19, 2024 – Feb 20, 2024

Subsystems (4)
lore
Share & tools
lore

Oliver Hartkopp

author maintainer
#0 lore raw

PATCH 1/1 can: raw: fix getsockopt() for new CAN_RAW_XL_VCID_OPTS

The code for the CAN_RAW_XL_VCID_OPTS getsockopt() was incompletely adopted from the CAN_RAW_FILTER getsockopt().

Add the missing put_user() and return statements.

Flagged by Smatch.

Fixes c83c22ec1493 ("can: canxl: add virtual CAN network identifier support")
---
 net/can/raw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/can/raw.c +3 -1
index cb8e6f788af8..897ffc17d850 100644
@@ -833,11 +833,13 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
 			if (len > sizeof(ro->raw_vcid_opts))
 				len = sizeof(ro->raw_vcid_opts);
 			if (copy_to_user(optval, &ro->raw_vcid_opts, len))
 				err = -EFAULT;
 		}
-		break;
+		if (!err)
+			err = put_user(len, optlen);
+		return err;
 
 	case CAN_RAW_JOIN_FILTERS:
 		if (len > sizeof(int))
 			len = sizeof(int);
 		val = &ro->join_filters;
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

Sorry. Of course it is a [PATCH net-next] where the referenced commit has been applied.

Best regards,
Oliver

Quoted 32 lines · Oliver Hartkopp

The code for the CAN_RAW_XL_VCID_OPTS getsockopt() was incompletely adopted from the CAN_RAW_FILTER getsockopt().

Add the missing put_user() and return statements.

Flagged by Smatch.

Fixes c83c22ec1493 ("can: canxl: add virtual CAN network identifier support")
---
  net/can/raw.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
net/can/raw.c +3 -1
index cb8e6f788af8..897ffc17d850 100644
@@ -833,11 +833,13 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
  			if (len > sizeof(ro->raw_vcid_opts))
  				len = sizeof(ro->raw_vcid_opts);
  			if (copy_to_user(optval, &ro->raw_vcid_opts, len))
  				err = -EFAULT;
  		}
-		break;
+		if (!err)
+			err = put_user(len, optlen);
+		return err;
 
  	case CAN_RAW_JOIN_FILTERS:
  		if (len > sizeof(int))
  			len = sizeof(int);
  		val = &ro->join_filters;
maintainer Applied
#2 lore raw
In reply to Oliver Hartkopp
Quoted 9 lines · Oliver Hartkopp

The code for the CAN_RAW_XL_VCID_OPTS getsockopt() was incompletely adopted from the CAN_RAW_FILTER getsockopt().

Add the missing put_user() and return statements.

Flagged by Smatch.

Fixes c83c22ec1493 ("can: canxl: add virtual CAN network identifier support")

Applied to linux-can-next

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |