rxrpc: Improve setsockopt() handling of malformed user input

copy_from_sockptr() does not return negative value on error; instead, it
reports the number of bytes that failed to copy. Since it's deprecated,
switch to copy_safe_from_sockptr().

Note: Keeping the `optlen != sizeof(unsigned int)` check as
copy_safe_from_sockptr() by itself would also accept
optlen > sizeof(unsigned int). Which would allow a more lenient handling
of inputs.

Fixes: 17926a7932 ("[AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both")
Signed-off-by: Michal Luczaj <mhal@rbox.co>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Michal Luczaj 2024-11-19 14:31:42 +01:00 committed by Paolo Abeni
parent 1465036b10
commit 0202005664

View File

@ -707,9 +707,10 @@ static int rxrpc_setsockopt(struct socket *sock, int level, int optname,
ret = -EISCONN; ret = -EISCONN;
if (rx->sk.sk_state != RXRPC_UNBOUND) if (rx->sk.sk_state != RXRPC_UNBOUND)
goto error; goto error;
ret = copy_from_sockptr(&min_sec_level, optval, ret = copy_safe_from_sockptr(&min_sec_level,
sizeof(unsigned int)); sizeof(min_sec_level),
if (ret < 0) optval, optlen);
if (ret)
goto error; goto error;
ret = -EINVAL; ret = -EINVAL;
if (min_sec_level > RXRPC_SECURITY_MAX) if (min_sec_level > RXRPC_SECURITY_MAX)