Skip to content

Commit

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

copy_from_sockptr() is used incorrectly: return value is the number of
bytes that could not be copied. Since it's deprecated, switch to
copy_safe_from_sockptr().

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

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Suggested-by: David Wei <[email protected]>
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 f688979 commit 981d647
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/llc/af_llc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
lock_sock(sk);
if (unlikely(level != SOL_LLC || optlen != sizeof(int)))
goto out;
rc = copy_from_sockptr(&opt, optval, sizeof(opt));
rc = copy_safe_from_sockptr(&opt, sizeof(opt), optval, optlen);
if (rc)
goto out;
rc = -EINVAL;
Expand Down

0 comments on commit 981d647

Please sign in to comment.