diff mbox series

can: raw: fix getsockopt() for new CAN_RAW_XL_VCID_OPTS

Message ID 20240219200021.12113-1-socketcan@hartkopp.net (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series can: raw: fix getsockopt() for new CAN_RAW_XL_VCID_OPTS | expand

Checks

Context Check Description
netdev/tree_selection success Series ignored based on subject

Commit Message

Oliver Hartkopp Feb. 19, 2024, 8 p.m. UTC
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")
Reported-by: Simon Horman <horms@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 net/can/raw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Oliver Hartkopp Feb. 19, 2024, 8:23 p.m. UTC | #1
Sorry. Of course it is a [PATCH net-next] where the referenced commit 
has been applied.

Best regards,
Oliver

On 2024-02-19 21:00, Oliver Hartkopp wrote:
> 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")
> Reported-by: Simon Horman <horms@kernel.org>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> ---
>   net/can/raw.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/can/raw.c b/net/can/raw.c
> index cb8e6f788af8..897ffc17d850 100644
> --- a/net/can/raw.c
> +++ b/net/can/raw.c
> @@ -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;
Marc Kleine-Budde Feb. 20, 2024, 7:26 a.m. UTC | #2
On 19.02.2024 21:00:21, Oliver Hartkopp wrote:
> 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")
> Reported-by: Simon Horman <horms@kernel.org>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>

Applied to linux-can-next

regards,
Marc
diff mbox series

Patch

diff --git a/net/can/raw.c b/net/can/raw.c
index cb8e6f788af8..897ffc17d850 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -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;