Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net/atm: fix slab-out-of-bounds read in vcc_setsockopt()
@ 2026-08-04 14:58 Eric Dumazet
  2026-08-05  6:44 ` Eric Dumazet
  2026-08-19 18:53 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2026-08-04 14:58 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet,
	syzbot+6c98d6eb7aabb6b1ad39

vcc_setsockopt() never checked optlen for ATM-specific options (SO_ATMQOS
and SO_SETCLP) and called copy_from_sockptr() assuming optval contained
sufficient space for struct atm_qos or unsigned long.

While copy_from_user() previously copied from a user buffer without checking
optlen, the introduction of sockptr_t and cgroup BPF setsockopt filters allows
optval to point to a kernel memory buffer allocated with a reduced optlen.
Because copy_from_sockptr() on kernel pointers uses memcpy(), this leads to a
KASAN slab-out-of-bounds read when optlen is smaller than the expected structure
size.

Fix this by using copy_safe_from_sockptr(), which validates that optlen is at
least the expected size before copying.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: syzbot+6c98d6eb7aabb6b1ad39@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/6a71fd31.9511d2ce.1fc5b9.033c.GAE@google.com/T/#u
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/atm/common.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/atm/common.c b/net/atm/common.c
index c7f92405daf050ecd2a507e41efdd622ab8dc6a8..6a0c5184c0d6380deaa95f68cb97c7745b4f7b56 100644
--- a/net/atm/common.c
+++ b/net/atm/common.c
@@ -722,8 +722,9 @@ int vcc_setsockopt(struct socket *sock, int level, int optname,
 	{
 		struct atm_qos qos;
 
-		if (copy_from_sockptr(&qos, optval, sizeof(qos)))
-			return -EFAULT;
+		error = copy_safe_from_sockptr(&qos, sizeof(qos), optval, optlen);
+		if (error)
+			return error;
 		error = check_qos(&qos);
 		if (error)
 			return error;
@@ -737,8 +738,9 @@ int vcc_setsockopt(struct socket *sock, int level, int optname,
 		return 0;
 	}
 	case SO_SETCLP:
-		if (copy_from_sockptr(&value, optval, sizeof(value)))
-			return -EFAULT;
+		error = copy_safe_from_sockptr(&value, sizeof(value), optval, optlen);
+		if (error)
+			return error;
 		if (value)
 			vcc->atm_options |= ATM_ATMOPT_CLP;
 		else
-- 
2.55.0.571.g244d577d93-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/atm: fix slab-out-of-bounds read in vcc_setsockopt()
  2026-08-04 14:58 [PATCH net] net/atm: fix slab-out-of-bounds read in vcc_setsockopt() Eric Dumazet
@ 2026-08-05  6:44 ` Eric Dumazet
  2026-08-19 18:53 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2026-08-05  6:44 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, syzbot+6c98d6eb7aabb6b1ad39

On Tue, Aug 4, 2026 at 4:58 PM Eric Dumazet <edumazet@google.com> wrote:
>
> vcc_setsockopt() never checked optlen for ATM-specific options (SO_ATMQOS
> and SO_SETCLP) and called copy_from_sockptr() assuming optval contained
> sufficient space for struct atm_qos or unsigned long.
>
> While copy_from_user() previously copied from a user buffer without checking
> optlen, the introduction of sockptr_t and cgroup BPF setsockopt filters allows
> optval to point to a kernel memory buffer allocated with a reduced optlen.
> Because copy_from_sockptr() on kernel pointers uses memcpy(), this leads to a
> KASAN slab-out-of-bounds read when optlen is smaller than the expected structure
> size.
>
> Fix this by using copy_safe_from_sockptr(), which validates that optlen is at
> least the expected size before copying.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Reported-by: syzbot+6c98d6eb7aabb6b1ad39@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/netdev/6a71fd31.9511d2ce.1fc5b9.033c.GAE@google.com/T/#u
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>  net/atm/common.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/net/atm/common.c b/net/atm/common.c
> index c7f92405daf050ecd2a507e41efdd622ab8dc6a8..6a0c5184c0d6380deaa95f68cb97c7745b4f7b56 100644
> --- a/net/atm/common.c
> +++ b/net/atm/common.c
> @@ -722,8 +722,9 @@ int vcc_setsockopt(struct socket *sock, int level, int optname,
>         {
>                 struct atm_qos qos;
>
> -               if (copy_from_sockptr(&qos, optval, sizeof(qos)))
> -                       return -EFAULT;
> +               error = copy_safe_from_sockptr(&qos, sizeof(qos), optval, optlen);
> +               if (error)
> +                       return error;
>                 error = check_qos(&qos);
>                 if (error)
>                         return error;
> @@ -737,8 +738,9 @@ int vcc_setsockopt(struct socket *sock, int level, int optname,
>                 return 0;
>         }
>         case SO_SETCLP:
> -               if (copy_from_sockptr(&value, optval, sizeof(value)))
> -                       return -EFAULT;
> +               error = copy_safe_from_sockptr(&value, sizeof(value), optval, optlen);

I will send a V2, because @value is an "unsigned long", while a prior
check uses an "int"

#define SO_SETCLP   __SO_ENCODE(SOL_ATM,0,int)

I will change @value to an "int" in V2.

pw-bot: cr

> +               if (error)
> +                       return error;
>                 if (value)
>                         vcc->atm_options |= ATM_ATMOPT_CLP;
>                 else
> --
> 2.55.0.571.g244d577d93-goog
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/atm: fix slab-out-of-bounds read in vcc_setsockopt()
  2026-08-04 14:58 [PATCH net] net/atm: fix slab-out-of-bounds read in vcc_setsockopt() Eric Dumazet
  2026-08-05  6:44 ` Eric Dumazet
@ 2026-08-19 18:53 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-08-19 18:53 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: oe-kbuild-all, Simon Horman, netdev, eric.dumazet, Eric Dumazet,
	syzbot+6c98d6eb7aabb6b1ad39

Hi Eric,

kernel test robot noticed the following build errors:

[auto build test ERROR on horms-ipvs/master]
[cannot apply to net/main net-next/main linus/master v7.2 next-20260818]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Eric-Dumazet/net-atm-fix-slab-out-of-bounds-read-in-vcc_setsockopt/20260804-145806
base:   https://git.kernel.org/pub/scm/linux/kernel/git/horms/ipvs.git master
patch link:    https://lore.kernel.org/r/20260804145806.2112004-1-edumazet%40google.com
patch subject: [PATCH net] net/atm: fix slab-out-of-bounds read in vcc_setsockopt()
config: alpha-allmodconfig (https://download.01.org/0day-ci/archive/20260820/202608200206.vI8yz6EN-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260820/202608200206.vI8yz6EN-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202608200206.vI8yz6EN-lkp@intel.com/

All errors (new ones prefixed by >>):

   net/atm/common.c: In function 'vcc_setsockopt':
>> net/atm/common.c:763:25: error: implicit declaration of function 'copy_safe_from_sockptr'; did you mean 'copy_from_sockptr'? [-Wimplicit-function-declaration]
     763 |                 error = copy_safe_from_sockptr(&qos, sizeof(qos), optval, optlen);
         |                         ^~~~~~~~~~~~~~~~~~~~~~
         |                         copy_from_sockptr


vim +763 net/atm/common.c

   746	
   747	int vcc_setsockopt(struct socket *sock, int level, int optname,
   748			   sockptr_t optval, unsigned int optlen)
   749	{
   750		struct atm_vcc *vcc;
   751		unsigned long value;
   752		int error;
   753	
   754		if (__SO_LEVEL_MATCH(optname, level) && optlen != __SO_SIZE(optname))
   755			return -EINVAL;
   756	
   757		vcc = ATM_SD(sock);
   758		switch (optname) {
   759		case SO_ATMQOS:
   760		{
   761			struct atm_qos qos;
   762	
 > 763			error = copy_safe_from_sockptr(&qos, sizeof(qos), optval, optlen);
   764			if (error)
   765				return error;
   766			error = check_qos(&qos);
   767			if (error)
   768				return error;
   769			if (sock->state == SS_CONNECTED)
   770				return atm_change_qos(vcc, &qos);
   771			if (sock->state != SS_UNCONNECTED)
   772				return -EBADFD;
   773			vcc->qos = qos;
   774			set_bit(ATM_VF_HASQOS, &vcc->flags);
   775			return 0;
   776		}
   777		case SO_SETCLP:
   778			error = copy_safe_from_sockptr(&value, sizeof(value), optval, optlen);
   779			if (error)
   780				return error;
   781			if (value)
   782				vcc->atm_options |= ATM_ATMOPT_CLP;
   783			else
   784				vcc->atm_options &= ~ATM_ATMOPT_CLP;
   785			return 0;
   786		default:
   787			return -EINVAL;
   788		}
   789	}
   790	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-19 18:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-04 14:58 [PATCH net] net/atm: fix slab-out-of-bounds read in vcc_setsockopt() Eric Dumazet
2026-08-05  6:44 ` Eric Dumazet
2026-08-19 18:53 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox