Skip to content

Commit d1524d0

Browse files
author
Paolo Abeni
committed
Merge branch 'net-fix-some-callers-of-copy_from_sockptr'
Michal Luczaj says: ==================== net: Fix some callers of copy_from_sockptr() Some callers misinterpret copy_from_sockptr()'s return value. The function follows copy_from_user(), i.e. returns 0 for success, or the number of bytes not copied on error. Simply returning the result in a non-zero case isn't usually what was intended. Compile tested with CONFIG_LLC, CONFIG_AF_RXRPC, CONFIG_BT enabled. Last patch probably belongs more to net-next, if any. Here as an RFC. Suggested-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Michal Luczaj <mhal@rbox.co> ==================== Link: https://patch.msgid.link/20241119-sockptr-copy-fixes-v3-0-d752cac4be8e@rbox.co Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2 parents 5dfd7d9 + 49b2b97 commit d1524d0

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

include/linux/sockptr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static inline int copy_from_sockptr_offset(void *dst, sockptr_t src,
5353
/* Deprecated.
5454
* This is unsafe, unless caller checked user provided optlen.
5555
* Prefer copy_safe_from_sockptr() instead.
56+
*
57+
* Returns 0 for success, or number of bytes not copied on error.
5658
*/
5759
static inline int copy_from_sockptr(void *dst, sockptr_t src, size_t size)
5860
{

net/llc/af_llc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
10981098
lock_sock(sk);
10991099
if (unlikely(level != SOL_LLC || optlen != sizeof(int)))
11001100
goto out;
1101-
rc = copy_from_sockptr(&opt, optval, sizeof(opt));
1101+
rc = copy_safe_from_sockptr(&opt, sizeof(opt), optval, optlen);
11021102
if (rc)
11031103
goto out;
11041104
rc = -EINVAL;

net/rxrpc/af_rxrpc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,10 @@ static int rxrpc_setsockopt(struct socket *sock, int level, int optname,
707707
ret = -EISCONN;
708708
if (rx->sk.sk_state != RXRPC_UNBOUND)
709709
goto error;
710-
ret = copy_from_sockptr(&min_sec_level, optval,
711-
sizeof(unsigned int));
712-
if (ret < 0)
710+
ret = copy_safe_from_sockptr(&min_sec_level,
711+
sizeof(min_sec_level),
712+
optval, optlen);
713+
if (ret)
713714
goto error;
714715
ret = -EINVAL;
715716
if (min_sec_level > RXRPC_SECURITY_MAX)

0 commit comments

Comments
 (0)