Re: [PATCH net-next v3 4/5] net: af_unix: replace copy_from_sockptr() with copy_safe_from_sockptr()
From: Kuniyuki Iwashima <kuniyu@google.com>
Date: 2026-06-30 16:19:07
Also in:
linux-fsdevel, lkml
From: Kuniyuki Iwashima <kuniyu@google.com>
Date: 2026-06-30 16:19:07
Also in:
linux-fsdevel, lkml
On Mon, Jun 29, 2026 at 12:42 PM Jori Koolstra [off-list ref] wrote:
Replace deprecated call to copy_from_sockptr() with copy_safe_from_sockptr(). Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl> --- net/unix/af_unix.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 83274ce18e06..07a0b07cd65f 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c@@ -933,6 +933,7 @@ static int unix_setsockopt(struct socket *sock, int level, int optname, { struct unix_sock *u = unix_sk(sock->sk); struct sock *sk = sock->sk; + int error; int val; if (level != SOL_SOCKET)@@ -941,11 +942,9 @@ static int unix_setsockopt(struct socket *sock, int level, int optname, if (!unix_custom_sockopt(optname)) return sock_setsockopt(sock, level, optname, optval, optlen); - if (optlen != sizeof(int)) - return -EINVAL; - - if (copy_from_sockptr(&val, optval, sizeof(val))) - return -EFAULT; + error = copy_safe_from_sockptr(&val, sizeof(val), optval, optlen);
Currently, only int is allowed, but this change unnecessarily loosens the validation. Please keep copy_from_sockptr() as is.
+ if (error)
+ return error;
switch (optname) {
case SO_INQ:
--
2.54.0