All of lore.kernel.org
 help / color / mirror / Atom feed
* [syzbot] [bpf?] [net?] WARNING in __sk_msg_free
@ 2024-01-05 17:32 syzbot
  2024-01-09  5:34 ` Edward Adam Davis
  2024-01-09  9:32 ` [PATCH] tls: fix " Edward Adam Davis
  0 siblings, 2 replies; 6+ messages in thread
From: syzbot @ 2024-01-05 17:32 UTC (permalink / raw)
  To: andrii, ast, borisp, bpf, daniel, davem, dhowells, edumazet,
	jakub, john.fastabend, kuba, linux-kernel, netdev, pabeni,
	syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    2ab1efad60ad net/sched: cls_api: complement tcf_tfilter_du..
git tree:       net-next
console+strace: https://syzkaller.appspot.com/x/log.txt?x=162a3829e80000
kernel config:  https://syzkaller.appspot.com/x/.config?x=a4e9ca8e3c104d2a
dashboard link: https://syzkaller.appspot.com/bug?extid=f2977222e0e95cec15c8
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=153f4f29e80000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=14acd65ee80000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/bc9bebeba249/disk-2ab1efad.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/1b355f4afef6/vmlinux-2ab1efad.xz
kernel image: https://storage.googleapis.com/syzbot-assets/0c561e15b929/bzImage-2ab1efad.xz

The issue was bisected to:

commit fe1e81d4f73b6cbaed4fcc476960d26770642842
Author: David Howells <dhowells@redhat.com>
Date:   Wed Jun 7 18:19:17 2023 +0000

    tls/sw: Support MSG_SPLICE_PAGES

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=13e87d81e80000
final oops:     https://syzkaller.appspot.com/x/report.txt?x=10187d81e80000
console output: https://syzkaller.appspot.com/x/log.txt?x=17e87d81e80000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+f2977222e0e95cec15c8@syzkaller.appspotmail.com
Fixes: fe1e81d4f73b ("tls/sw: Support MSG_SPLICE_PAGES")

------------[ cut here ]------------
WARNING: CPU: 0 PID: 5059 at include/linux/skmsg.h:137 sk_msg_check_to_free include/linux/skmsg.h:137 [inline]
WARNING: CPU: 0 PID: 5059 at include/linux/skmsg.h:137 sk_msg_check_to_free include/linux/skmsg.h:135 [inline]
WARNING: CPU: 0 PID: 5059 at include/linux/skmsg.h:137 __sk_msg_free+0x29f/0x390 net/core/skmsg.c:203
Modules linked in:
CPU: 0 PID: 5059 Comm: syz-executor395 Not tainted 6.7.0-rc6-syzkaller-01873-g2ab1efad60ad #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/17/2023
RIP: 0010:sk_msg_check_to_free include/linux/skmsg.h:137 [inline]
RIP: 0010:sk_msg_check_to_free include/linux/skmsg.h:135 [inline]
RIP: 0010:__sk_msg_free+0x29f/0x390 net/core/skmsg.c:203
Code: 00 00 48 83 e0 fe 48 83 c8 02 49 89 85 40 02 00 00 8b 44 24 0c 48 83 c4 30 5b 5d 41 5c 41 5d 41 5e 41 5f c3 e8 62 98 00 f9 90 <0f> 0b 90 e8 59 98 00 f9 48 63 5c 24 08 48 83 fb 13 0f 87 9d 00 00
RSP: 0018:ffffc90003bff8e8 EFLAGS: 00010293
RAX: 0000000000000000 RBX: 000000000000000e RCX: ffffffff8886e85f
RDX: ffff888022e88000 RSI: ffffffff8886e90e RDI: 0000000000000005
RBP: 000000000000000e R08: 0000000000000005 R09: 0000000000000000
R10: 0000000000000036 R11: 0000000000000002 R12: 0000000000000036
R13: ffff8880177f2018 R14: 0000000000000007 R15: dffffc0000000000
FS:  0000000000000000(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f0c1dd31a18 CR3: 000000000cd77000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 tls_free_rec net/tls/tls_sw.c:359 [inline]
 tls_free_open_rec net/tls/tls_sw.c:370 [inline]
 tls_sw_release_resources_tx+0x4e8/0x6f0 net/tls/tls_sw.c:2467
 tls_sk_proto_cleanup net/tls/tls_main.c:352 [inline]
 tls_sk_proto_close+0x678/0xac0 net/tls/tls_main.c:382
 inet_release+0x132/0x270 net/ipv4/af_inet.c:433
 inet6_release+0x4f/0x70 net/ipv6/af_inet6.c:485
 __sock_release+0xae/0x260 net/socket.c:659
 sock_close+0x1c/0x20 net/socket.c:1419
 __fput+0x270/0xb70 fs/file_table.c:394
 task_work_run+0x14d/0x240 kernel/task_work.c:180
 exit_task_work include/linux/task_work.h:38 [inline]
 do_exit+0xa8a/0x2ad0 kernel/exit.c:869
 do_group_exit+0xd4/0x2a0 kernel/exit.c:1018
 get_signal+0x23b5/0x2790 kernel/signal.c:2904
 arch_do_signal_or_restart+0x90/0x7f0 arch/x86/kernel/signal.c:309
 exit_to_user_mode_loop kernel/entry/common.c:168 [inline]
 exit_to_user_mode_prepare+0x121/0x240 kernel/entry/common.c:204
 __syscall_exit_to_user_mode_work kernel/entry/common.c:285 [inline]
 syscall_exit_to_user_mode+0x1e/0x60 kernel/entry/common.c:296
 do_syscall_64+0x4d/0x110 arch/x86/entry/common.c:89
 entry_SYSCALL_64_after_hwframe+0x63/0x6b
RIP: 0033:0x7f0c1dcdae39
Code: Unable to access opcode bytes at 0x7f0c1dcdae0f.
RSP: 002b:00007f0c1dc9d218 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: 0000000000010000 RBX: 00007f0c1dd64328 RCX: 00007f0c1dcdae39
RDX: 00000000fffffecc RSI: 0000000020000100 RDI: 0000000000000004
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f0c1dd64320
R13: 0000000000000000 R14: 00007f0c1dd32004 R15: 34ea337571a66fd8
 </TASK>


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

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

* Re: [syzbot] [bpf?] [net?] WARNING in __sk_msg_free
  2024-01-05 17:32 [syzbot] [bpf?] [net?] WARNING in __sk_msg_free syzbot
@ 2024-01-09  5:34 ` Edward Adam Davis
  2024-01-09 18:17   ` syzbot
  2024-01-09  9:32 ` [PATCH] tls: fix " Edward Adam Davis
  1 sibling, 1 reply; 6+ messages in thread
From: Edward Adam Davis @ 2024-01-09  5:34 UTC (permalink / raw)
  To: syzbot+f2977222e0e95cec15c8; +Cc: linux-kernel, syzkaller-bugs

please test WARNING in __sk_msg_free

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index e37b4d2e2acd..68dbe821f61d 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1016,6 +1016,8 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
 
 		msg_pl = &rec->msg_plaintext;
 		msg_en = &rec->msg_encrypted;
+		if (msg_pl->sg.end >= MAX_MSG_FRAGS)
+			return -EINVAL;
 
 		orig_size = msg_pl->sg.size;
 		full_record = false;


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

* [PATCH] tls: fix WARNING in __sk_msg_free
  2024-01-05 17:32 [syzbot] [bpf?] [net?] WARNING in __sk_msg_free syzbot
  2024-01-09  5:34 ` Edward Adam Davis
@ 2024-01-09  9:32 ` Edward Adam Davis
  2024-01-09 23:22   ` John Fastabend
  1 sibling, 1 reply; 6+ messages in thread
From: Edward Adam Davis @ 2024-01-09  9:32 UTC (permalink / raw)
  To: syzbot+f2977222e0e95cec15c8
  Cc: andrii, ast, borisp, bpf, daniel, davem, dhowells, edumazet,
	jakub, john.fastabend, kuba, linux-kernel, netdev, pabeni,
	syzkaller-bugs

Syzbot constructed 32 scatterlists, and the data members in struct sk_msg_sg 
can only store a maximum of MAX_MSG_FRAGS scatterlists.
However, the value of MAX_MSG_FRAGS=CONFIG_MAX_SKB_FRAG is less than 32, which
leads to the warning reported here.

Prevent similar issues from occurring by checking whether sg.end is greater 
than MAX_MSG_FRAGS.

Reported-and-tested-by: syzbot+f2977222e0e95cec15c8@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 net/tls/tls_sw.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index e37b4d2e2acd..68dbe821f61d 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1016,6 +1016,8 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
 
 		msg_pl = &rec->msg_plaintext;
 		msg_en = &rec->msg_encrypted;
+		if (msg_pl->sg.end >= MAX_MSG_FRAGS)
+			return -EINVAL;
 
 		orig_size = msg_pl->sg.size;
 		full_record = false;
-- 
2.43.0


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

* Re: [syzbot] [bpf?] [net?] WARNING in __sk_msg_free
  2024-01-09  5:34 ` Edward Adam Davis
@ 2024-01-09 18:17   ` syzbot
  0 siblings, 0 replies; 6+ messages in thread
From: syzbot @ 2024-01-09 18:17 UTC (permalink / raw)
  To: eadavis, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+f2977222e0e95cec15c8@syzkaller.appspotmail.com

Tested on:

commit:         9f8413c4 Merge tag 'cgroup-for-6.8' of git://git.kerne..
git tree:       https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=13e7b575e80000
kernel config:  https://syzkaller.appspot.com/x/.config?x=d908a1f683257685
dashboard link: https://syzkaller.appspot.com/bug?extid=f2977222e0e95cec15c8
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=1482db4de80000

Note: testing is done by a robot and is best-effort only.

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

* RE: [PATCH] tls: fix WARNING in __sk_msg_free
  2024-01-09  9:32 ` [PATCH] tls: fix " Edward Adam Davis
@ 2024-01-09 23:22   ` John Fastabend
  2024-01-10  7:53     ` John Fastabend
  0 siblings, 1 reply; 6+ messages in thread
From: John Fastabend @ 2024-01-09 23:22 UTC (permalink / raw)
  To: Edward Adam Davis, syzbot+f2977222e0e95cec15c8
  Cc: andrii, ast, borisp, bpf, daniel, davem, dhowells, edumazet,
	jakub, john.fastabend, kuba, linux-kernel, netdev, pabeni,
	syzkaller-bugs

Edward Adam Davis wrote:
> Syzbot constructed 32 scatterlists, and the data members in struct sk_msg_sg 
> can only store a maximum of MAX_MSG_FRAGS scatterlists.
> However, the value of MAX_MSG_FRAGS=CONFIG_MAX_SKB_FRAG is less than 32, which
> leads to the warning reported here.
> 
> Prevent similar issues from occurring by checking whether sg.end is greater 
> than MAX_MSG_FRAGS.
> 
> Reported-and-tested-by: syzbot+f2977222e0e95cec15c8@syzkaller.appspotmail.com
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
>  net/tls/tls_sw.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> index e37b4d2e2acd..68dbe821f61d 100644
> --- a/net/tls/tls_sw.c
> +++ b/net/tls/tls_sw.c
> @@ -1016,6 +1016,8 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
>  
>  		msg_pl = &rec->msg_plaintext;
>  		msg_en = &rec->msg_encrypted;
> +		if (msg_pl->sg.end >= MAX_MSG_FRAGS)
> +			return -EINVAL;
>  
>  		orig_size = msg_pl->sg.size;
>  		full_record = false;
> -- 
> 2.43.0
> 

I'll test this in a bit, but I suspect this error is because even
if the msg_pl is full (the sg.end == MAX_MSG_FRAGS) the code is
missing a full_record=true set to force the loop to do the send
and abort. My opinion is we should never iterated the loop if the
msg_pl was full.

I think something like this is actually needed.

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index e37b4d2e2acd..9cfa6f8d51e3 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1052,8 +1052,10 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
                        if (ret < 0)
                                goto send_end;
                        tls_ctx->pending_open_record_frags = true;
-                       if (full_record || eor || sk_msg_full(msg_pl))
+                       if (full_record || eor || sk_msg_full(msg_pl)) {
+                               full_record = true;
                                goto copied;
+                       }
                        continue;
                }

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

* RE: [PATCH] tls: fix WARNING in __sk_msg_free
  2024-01-09 23:22   ` John Fastabend
@ 2024-01-10  7:53     ` John Fastabend
  0 siblings, 0 replies; 6+ messages in thread
From: John Fastabend @ 2024-01-10  7:53 UTC (permalink / raw)
  To: John Fastabend, Edward Adam Davis, syzbot+f2977222e0e95cec15c8
  Cc: andrii, ast, borisp, bpf, daniel, davem, dhowells, edumazet,
	jakub, john.fastabend, kuba, linux-kernel, netdev, pabeni,
	syzkaller-bugs

John Fastabend wrote:
> Edward Adam Davis wrote:
> > Syzbot constructed 32 scatterlists, and the data members in struct sk_msg_sg 
> > can only store a maximum of MAX_MSG_FRAGS scatterlists.
> > However, the value of MAX_MSG_FRAGS=CONFIG_MAX_SKB_FRAG is less than 32, which
> > leads to the warning reported here.
> > 
> > Prevent similar issues from occurring by checking whether sg.end is greater 
> > than MAX_MSG_FRAGS.
> > 
> > Reported-and-tested-by: syzbot+f2977222e0e95cec15c8@syzkaller.appspotmail.com
> > Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> > ---
> >  net/tls/tls_sw.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> > index e37b4d2e2acd..68dbe821f61d 100644
> > --- a/net/tls/tls_sw.c
> > +++ b/net/tls/tls_sw.c
> > @@ -1016,6 +1016,8 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
> >  
> >  		msg_pl = &rec->msg_plaintext;
> >  		msg_en = &rec->msg_encrypted;
> > +		if (msg_pl->sg.end >= MAX_MSG_FRAGS)
> > +			return -EINVAL;
> >  
> >  		orig_size = msg_pl->sg.size;
> >  		full_record = false;
> > -- 
> > 2.43.0
> > 
> 
> I'll test this in a bit, but I suspect this error is because even
> if the msg_pl is full (the sg.end == MAX_MSG_FRAGS) the code is
> missing a full_record=true set to force the loop to do the send
> and abort. My opinion is we should never iterated the loop if the
> msg_pl was full.
> 
> I think something like this is actually needed.
> 
> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> index e37b4d2e2acd..9cfa6f8d51e3 100644
> --- a/net/tls/tls_sw.c
> +++ b/net/tls/tls_sw.c
> @@ -1052,8 +1052,10 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
>                         if (ret < 0)
>                                 goto send_end;
>                         tls_ctx->pending_open_record_frags = true;
> -                       if (full_record || eor || sk_msg_full(msg_pl))
> +                       if (full_record || eor || sk_msg_full(msg_pl)) {
> +                               full_record = true;
>                                 goto copied;
> +                       }
>                         continue;
>                 }

Actually, it needs a bit more than above. That will fix the warning,
but it returns an error on when it should flush the full_record in
some cases. I'll send a fix shortly.

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

end of thread, other threads:[~2024-01-10  7:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-05 17:32 [syzbot] [bpf?] [net?] WARNING in __sk_msg_free syzbot
2024-01-09  5:34 ` Edward Adam Davis
2024-01-09 18:17   ` syzbot
2024-01-09  9:32 ` [PATCH] tls: fix " Edward Adam Davis
2024-01-09 23:22   ` John Fastabend
2024-01-10  7:53     ` John Fastabend

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.