netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int)
       [not found] <234da60a-709f-4430-b594-386b7c2b65f5@molgen.mpg.de>
@ 2024-04-09 12:15 ` Edward Adam Davis
  2024-04-09 13:07   ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Edward Adam Davis @ 2024-04-09 12:15 UTC (permalink / raw)
  To: pmenzel
  Cc: netdev, eadavis, johan.hedberg, linux-bluetooth, linux-kernel,
	luiz.dentz, marcel, syzbot+d4ecae01a53fd9b42e7d, syzkaller-bugs

The optlen value passed by syzbot to _sys_setsockopt() is 2, which results in
only 2 bytes being allocated when allocating memory to kernel_optval, and the
optval size passed when calling the function copy_from_sockptr() is 4 bytes.
Here, optlen is determined uniformly in the entry function __sys_setsockopt(). 
If its value is less than 4, the parameter is considered invalid.

Reported-by: syzbot+837ba09d9db969068367@syzkaller.appspotmail.com
Reported-by: syzbot+b71011ec0a23f4d15625@syzkaller.appspotmail.com
Reported-by: syzbot+d4ecae01a53fd9b42e7d@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 net/socket.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/socket.c b/net/socket.c
index e5f3af49a8b6..ac8fd4f6ebfe 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2327,6 +2327,9 @@ int __sys_setsockopt(int fd, int level, int optname, char __user *user_optval,
 	int err, fput_needed;
 	struct socket *sock;
 
+	if (optlen < sizeof(int))
+		return -EINVAL;
+
 	sock = sockfd_lookup_light(fd, &err, &fput_needed);
 	if (!sock)
 		return err;
-- 
2.43.0


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

* Re: [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int)
  2024-04-09 12:15 ` [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int) Edward Adam Davis
@ 2024-04-09 13:07   ` Eric Dumazet
  2024-04-09 13:25     ` Luiz Augusto von Dentz
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Eric Dumazet @ 2024-04-09 13:07 UTC (permalink / raw)
  To: Edward Adam Davis, pmenzel, edumazet
  Cc: netdev, johan.hedberg, linux-bluetooth, linux-kernel, luiz.dentz,
	marcel, syzbot+d4ecae01a53fd9b42e7d, syzkaller-bugs


On 4/9/24 14:15, Edward Adam Davis wrote:
> The optlen value passed by syzbot to _sys_setsockopt() is 2, which results in
> only 2 bytes being allocated when allocating memory to kernel_optval, and the
> optval size passed when calling the function copy_from_sockptr() is 4 bytes.
> Here, optlen is determined uniformly in the entry function __sys_setsockopt().
> If its value is less than 4, the parameter is considered invalid.
>
> Reported-by: syzbot+837ba09d9db969068367@syzkaller.appspotmail.com
> Reported-by: syzbot+b71011ec0a23f4d15625@syzkaller.appspotmail.com
> Reported-by: syzbot+d4ecae01a53fd9b42e7d@syzkaller.appspotmail.com
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>


I think I gave my feedback already.

Please do not ignore maintainers feedback.

This patch is absolutely wrong.

Some setsockopt() deal with optlen == 1 just fine, thank you very much.



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

* Re: [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int)
  2024-04-09 13:07   ` Eric Dumazet
@ 2024-04-09 13:25     ` Luiz Augusto von Dentz
  2024-04-09 13:36     ` [PATCH] Bluetooth: fix oob in rfcomm_sock_setsockopt Edward Adam Davis
  2024-04-09 14:01     ` [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int) Edward Adam Davis
  2 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2024-04-09 13:25 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Edward Adam Davis, pmenzel, edumazet, netdev, johan.hedberg,
	linux-bluetooth, linux-kernel, marcel,
	syzbot+d4ecae01a53fd9b42e7d, syzkaller-bugs

Hi,

On Tue, Apr 9, 2024 at 9:07 AM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
>
> On 4/9/24 14:15, Edward Adam Davis wrote:
> > The optlen value passed by syzbot to _sys_setsockopt() is 2, which results in
> > only 2 bytes being allocated when allocating memory to kernel_optval, and the
> > optval size passed when calling the function copy_from_sockptr() is 4 bytes.
> > Here, optlen is determined uniformly in the entry function __sys_setsockopt().
> > If its value is less than 4, the parameter is considered invalid.
> >
> > Reported-by: syzbot+837ba09d9db969068367@syzkaller.appspotmail.com
> > Reported-by: syzbot+b71011ec0a23f4d15625@syzkaller.appspotmail.com
> > Reported-by: syzbot+d4ecae01a53fd9b42e7d@syzkaller.appspotmail.com
> > Signed-off-by: Edward Adam Davis <eadavis@qq.com>
>
>
> I think I gave my feedback already.
>
> Please do not ignore maintainers feedback.
>
> This patch is absolutely wrong.
>
> Some setsockopt() deal with optlen == 1 just fine, thank you very much.

+1, I don't think the setsockopt interface has a fixed minimum of
sizeof(int), so this is a nak from me as well.

-- 
Luiz Augusto von Dentz

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

* [PATCH] Bluetooth: fix oob in rfcomm_sock_setsockopt
  2024-04-09 13:07   ` Eric Dumazet
  2024-04-09 13:25     ` Luiz Augusto von Dentz
@ 2024-04-09 13:36     ` Edward Adam Davis
  2024-04-09 14:11       ` Luiz Augusto von Dentz
  2024-04-09 14:01     ` [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int) Edward Adam Davis
  2 siblings, 1 reply; 8+ messages in thread
From: Edward Adam Davis @ 2024-04-09 13:36 UTC (permalink / raw)
  To: eric.dumazet
  Cc: eadavis, edumazet, johan.hedberg, linux-bluetooth, linux-kernel,
	luiz.dentz, marcel, netdev, pmenzel, syzbot+d4ecae01a53fd9b42e7d,
	syzkaller-bugs

If optlen < sizeof(u32) it will trigger oob, so take the min of them.

Reported-by: syzbot+d4ecae01a53fd9b42e7d@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 net/bluetooth/rfcomm/sock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index b54e8a530f55..42c55c756b51 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -629,7 +629,7 @@ static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname,
 
 	switch (optname) {
 	case RFCOMM_LM:
-		if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
+		if (copy_from_sockptr(&opt, optval, min_t(int, sizeof(u32), optlen))) {
 			err = -EFAULT;
 			break;
 		}
-- 
2.43.0


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

* Re: [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int)
  2024-04-09 13:07   ` Eric Dumazet
  2024-04-09 13:25     ` Luiz Augusto von Dentz
  2024-04-09 13:36     ` [PATCH] Bluetooth: fix oob in rfcomm_sock_setsockopt Edward Adam Davis
@ 2024-04-09 14:01     ` Edward Adam Davis
  2024-04-09 14:17       ` Eric Dumazet
  2024-04-09 18:27       ` Jakub Kicinski
  2 siblings, 2 replies; 8+ messages in thread
From: Edward Adam Davis @ 2024-04-09 14:01 UTC (permalink / raw)
  To: eric.dumazet
  Cc: eadavis, edumazet, johan.hedberg, linux-bluetooth, linux-kernel,
	luiz.dentz, marcel, netdev, pmenzel, syzbot+d4ecae01a53fd9b42e7d,
	syzkaller-bugs

On Tue, 9 Apr 2024 15:07:41 +0200, Eric Dumazet wrote:
> > The optlen value passed by syzbot to _sys_setsockopt() is 2, which results in
> > only 2 bytes being allocated when allocating memory to kernel_optval, and the
> > optval size passed when calling the function copy_from_sockptr() is 4 bytes.
> > Here, optlen is determined uniformly in the entry function __sys_setsockopt().
> > If its value is less than 4, the parameter is considered invalid.
> >
> > Reported-by: syzbot+837ba09d9db969068367@syzkaller.appspotmail.com
> > Reported-by: syzbot+b71011ec0a23f4d15625@syzkaller.appspotmail.com
> > Reported-by: syzbot+d4ecae01a53fd9b42e7d@syzkaller.appspotmail.com
> > Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> 
> 
> I think I gave my feedback already.
> 
> Please do not ignore maintainers feedback.
> 
> This patch is absolutely wrong.
> 
> Some setsockopt() deal with optlen == 1 just fine, thank you very much.
It's better to use evidence to support your claim, rather than your "maintainer" title.


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

* Re: [PATCH] Bluetooth: fix oob in rfcomm_sock_setsockopt
  2024-04-09 13:36     ` [PATCH] Bluetooth: fix oob in rfcomm_sock_setsockopt Edward Adam Davis
@ 2024-04-09 14:11       ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2024-04-09 14:11 UTC (permalink / raw)
  To: Edward Adam Davis
  Cc: eric.dumazet, edumazet, johan.hedberg, linux-bluetooth,
	linux-kernel, marcel, netdev, pmenzel,
	syzbot+d4ecae01a53fd9b42e7d, syzkaller-bugs

Hi Edward,

On Tue, Apr 9, 2024 at 9:36 AM Edward Adam Davis <eadavis@qq.com> wrote:
>
> If optlen < sizeof(u32) it will trigger oob, so take the min of them.
>
> Reported-by: syzbot+d4ecae01a53fd9b42e7d@syzkaller.appspotmail.com
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
>  net/bluetooth/rfcomm/sock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
> index b54e8a530f55..42c55c756b51 100644
> --- a/net/bluetooth/rfcomm/sock.c
> +++ b/net/bluetooth/rfcomm/sock.c
> @@ -629,7 +629,7 @@ static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname,
>
>         switch (optname) {
>         case RFCOMM_LM:
> -               if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
> +               if (copy_from_sockptr(&opt, optval, min_t(int, sizeof(u32), optlen))) {
>                         err = -EFAULT;
>                         break;
>                 }
> --
> 2.43.0

This has been dealt with already:

https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/commit/?id=ee77912bc0bbd78fceb785a81cc9108fa954982f


-- 
Luiz Augusto von Dentz

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

* Re: [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int)
  2024-04-09 14:01     ` [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int) Edward Adam Davis
@ 2024-04-09 14:17       ` Eric Dumazet
  2024-04-09 18:27       ` Jakub Kicinski
  1 sibling, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2024-04-09 14:17 UTC (permalink / raw)
  To: Edward Adam Davis
  Cc: eric.dumazet, johan.hedberg, linux-bluetooth, linux-kernel,
	luiz.dentz, marcel, netdev, pmenzel, syzbot+d4ecae01a53fd9b42e7d,
	syzkaller-bugs

On Tue, Apr 9, 2024 at 4:02 PM Edward Adam Davis <eadavis@qq.com> wrote:
>
> On Tue, 9 Apr 2024 15:07:41 +0200, Eric Dumazet wrote:
> > > The optlen value passed by syzbot to _sys_setsockopt() is 2, which results in
> > > only 2 bytes being allocated when allocating memory to kernel_optval, and the
> > > optval size passed when calling the function copy_from_sockptr() is 4 bytes.
> > > Here, optlen is determined uniformly in the entry function __sys_setsockopt().
> > > If its value is less than 4, the parameter is considered invalid.
> > >
> > > Reported-by: syzbot+837ba09d9db969068367@syzkaller.appspotmail.com
> > > Reported-by: syzbot+b71011ec0a23f4d15625@syzkaller.appspotmail.com
> > > Reported-by: syzbot+d4ecae01a53fd9b42e7d@syzkaller.appspotmail.com
> > > Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> >
> >
> > I think I gave my feedback already.
> >
> > Please do not ignore maintainers feedback.
> >
> > This patch is absolutely wrong.
> >
> > Some setsockopt() deal with optlen == 1 just fine, thank you very much.
> It's better to use evidence to support your claim, rather than your "maintainer" title.

I will answer since you ask so nicely,
but if you plan sending linux kernel patches, I suggest you look in
the source code.

Look at do_ip_setsockopt(), which is one of the most used setsockopt()
in the world.

The code is at least 20 years old.

It even supports optlen == 0

               if (optlen >= sizeof(int)) {
                       if (copy_from_sockptr(&val, optval, sizeof(val)))
                               return -EFAULT;
               } else if (optlen >= sizeof(char)) {
                       unsigned char ucval;

                       if (copy_from_sockptr(&ucval, optval, sizeof(ucval)))
                               return -EFAULT;
                       val = (int) ucval;
               }
       }

       /* If optlen==0, it is equivalent to val == 0 */

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

* Re: [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int)
  2024-04-09 14:01     ` [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int) Edward Adam Davis
  2024-04-09 14:17       ` Eric Dumazet
@ 2024-04-09 18:27       ` Jakub Kicinski
  1 sibling, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2024-04-09 18:27 UTC (permalink / raw)
  To: Edward Adam Davis
  Cc: eric.dumazet, edumazet, johan.hedberg, linux-bluetooth,
	linux-kernel, luiz.dentz, marcel, netdev, pmenzel,
	syzbot+d4ecae01a53fd9b42e7d, syzkaller-bugs

On Tue,  9 Apr 2024 22:01:45 +0800 Edward Adam Davis wrote:
> > I think I gave my feedback already.
> > 
> > Please do not ignore maintainers feedback.
> > 
> > This patch is absolutely wrong.
> > 
> > Some setsockopt() deal with optlen == 1 just fine, thank you very much.  
>
> It's better to use evidence to support your claim, rather than your "maintainer" title.

Run selftests.

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

end of thread, other threads:[~2024-04-09 18:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <234da60a-709f-4430-b594-386b7c2b65f5@molgen.mpg.de>
2024-04-09 12:15 ` [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int) Edward Adam Davis
2024-04-09 13:07   ` Eric Dumazet
2024-04-09 13:25     ` Luiz Augusto von Dentz
2024-04-09 13:36     ` [PATCH] Bluetooth: fix oob in rfcomm_sock_setsockopt Edward Adam Davis
2024-04-09 14:11       ` Luiz Augusto von Dentz
2024-04-09 14:01     ` [PATCH] net/socket: Ensure length of input socket option param >= sizeof(int) Edward Adam Davis
2024-04-09 14:17       ` Eric Dumazet
2024-04-09 18:27       ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).