Skip to content

Commit

Permalink
rxrpc: Improve setsockopt() handling of malformed user input
Browse files Browse the repository at this point in the history
[ Upstream commit 0202005 ]

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: 17926a7 ("[AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both")
Signed-off-by: Michal Luczaj <[email protected]>
Signed-off-by: Paolo Abeni <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
mmhal authored and gregkh committed Dec 14, 2024
1 parent 981d647 commit a784536
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions net/rxrpc/af_rxrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,10 @@ static int rxrpc_setsockopt(struct socket *sock, int level, int optname,
ret = -EISCONN;
if (rx->sk.sk_state != RXRPC_UNBOUND)
goto error;
ret = copy_from_sockptr(&min_sec_level, optval,
sizeof(unsigned int));
if (ret < 0)
ret = copy_safe_from_sockptr(&min_sec_level,
sizeof(min_sec_level),
optval, optlen);
if (ret)
goto error;
ret = -EINVAL;
if (min_sec_level > RXRPC_SECURITY_MAX)
Expand Down

0 comments on commit a784536

Please sign in to comment.