The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [syzbot] [kernel?] general protection fault in __device_attach (2)
@ 2026-08-14  8:51 syzbot
  2026-08-15  1:57 ` Edward Adam Davis
  2026-08-15  2:22 ` [PATCH] driver core: Cancel the attach if device addition fails Edward Adam Davis
  0 siblings, 2 replies; 4+ messages in thread
From: syzbot @ 2026-08-14  8:51 UTC (permalink / raw)
  To: linux-kernel, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    2f1baf1fc892 Merge tag 'trace-v7.2-rc7' of git://git.kerne..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=10f9f149580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=c44651ea7dd2f307
dashboard link: https://syzkaller.appspot.com/bug?extid=de42beb9ccc760a210ab
compiler:       gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17c9a279580000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+de42beb9ccc760a210ab@syzkaller.appspotmail.com

 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>
serio serio2: device_add() failed for  (), error: -12
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000021: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000108-0x000000000000010f]
CPU: 2 UID: 0 PID: 847 Comm: kworker/2:2 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: events_long serio_handle_event
RIP: 0010:__device_attach+0xb0/0x4d0 drivers/base/dd.c:1074
Code: c1 e8 03 42 80 3c 28 00 0f 85 d1 03 00 00 48 ba 00 00 00 00 00 fc ff df 4c 8b 7b 48 49 8d bf 08 01 00 00 48 89 f9 48 c1 e9 03 <0f> b6 14 11 84 d2 74 06 0f 8e 9d 03 00 00 45 0f b6 af 08 01 00 00
RSP: 0018:ffffc90004ee7b40 EFLAGS: 00010206
RAX: 1ffff110068d6a48 RBX: ffff8880346b51f8 RCX: 0000000000000021
RDX: dffffc0000000000 RSI: ffffffff8c400400 RDI: 0000000000000108
RBP: 1ffff920009dcf69 R08: 0000000000000000 R09: fffffbfff224331a
R10: ffffc90004ee7b40 R11: 0000000000000000 R12: 0000000000000000
R13: dffffc0000000000 R14: ffff8880346b52c0 R15: 0000000000000000
FS:  0000000000000000(0000) GS:ffff8880d5fe9000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fdf29b81d58 CR3: 000000000e994000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 serio_find_driver drivers/input/serio/serio.c:112 [inline]
 serio_handle_event+0x60a/0x990 drivers/input/serio/serio.c:206
 process_one_work+0xa23/0x1940 kernel/workqueue.c:3322
 process_scheduled_works kernel/workqueue.c:3405 [inline]
 worker_thread+0x5ef/0xe50 kernel/workqueue.c:3486
 kthread+0x370/0x450 kernel/kthread.c:436
 ret_from_fork+0x72b/0xd50 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:__device_attach+0xb0/0x4d0 drivers/base/dd.c:1074
Code: c1 e8 03 42 80 3c 28 00 0f 85 d1 03 00 00 48 ba 00 00 00 00 00 fc ff df 4c 8b 7b 48 49 8d bf 08 01 00 00 48 89 f9 48 c1 e9 03 <0f> b6 14 11 84 d2 74 06 0f 8e 9d 03 00 00 45 0f b6 af 08 01 00 00
RSP: 0018:ffffc90004ee7b40 EFLAGS: 00010206
RAX: 1ffff110068d6a48 RBX: ffff8880346b51f8 RCX: 0000000000000021
RDX: dffffc0000000000 RSI: ffffffff8c400400 RDI: 0000000000000108
RBP: 1ffff920009dcf69 R08: 0000000000000000 R09: fffffbfff224331a
R10: ffffc90004ee7b40 R11: 0000000000000000 R12: 0000000000000000
R13: dffffc0000000000 R14: ffff8880346b52c0 R15: 0000000000000000
FS:  0000000000000000(0000) GS:ffff8880d5fe9000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fdf29b81d58 CR3: 000000000e994000 CR4: 0000000000352ef0
----------------
Code disassembly (best guess):
   0:	c1 e8 03             	shr    $0x3,%eax
   3:	42 80 3c 28 00       	cmpb   $0x0,(%rax,%r13,1)
   8:	0f 85 d1 03 00 00    	jne    0x3df
   e:	48 ba 00 00 00 00 00 	movabs $0xdffffc0000000000,%rdx
  15:	fc ff df
  18:	4c 8b 7b 48          	mov    0x48(%rbx),%r15
  1c:	49 8d bf 08 01 00 00 	lea    0x108(%r15),%rdi
  23:	48 89 f9             	mov    %rdi,%rcx
  26:	48 c1 e9 03          	shr    $0x3,%rcx
* 2a:	0f b6 14 11          	movzbl (%rcx,%rdx,1),%edx <-- trapping instruction
  2e:	84 d2                	test   %dl,%dl
  30:	74 06                	je     0x38
  32:	0f 8e 9d 03 00 00    	jle    0x3d5
  38:	45 0f b6 af 08 01 00 	movzbl 0x108(%r15),%r13d
  3f:	00


---
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.

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] 4+ messages in thread

* Re: [syzbot] [kernel?] general protection fault in __device_attach (2)
  2026-08-14  8:51 [syzbot] [kernel?] general protection fault in __device_attach (2) syzbot
@ 2026-08-15  1:57 ` Edward Adam Davis
  2026-08-15  2:13   ` syzbot
  2026-08-15  2:22 ` [PATCH] driver core: Cancel the attach if device addition fails Edward Adam Davis
  1 sibling, 1 reply; 4+ messages in thread
From: Edward Adam Davis @ 2026-08-15  1:57 UTC (permalink / raw)
  To: syzbot+de42beb9ccc760a210ab; +Cc: linux-kernel, syzkaller-bugs

#syz test

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 60c005223844..d345f6c175a6 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1071,7 +1071,7 @@ static int __device_attach(struct device *dev, bool allow_async)
 	bool async = false;
 
 	device_lock(dev);
-	if (dev->p->dead) {
+	if (!dev->p || dev->p->dead) {
 		goto out_unlock;
 	} else if (dev->driver) {
 		if (device_is_bound(dev)) {


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

* Re: [syzbot] [kernel?] general protection fault in __device_attach (2)
  2026-08-15  1:57 ` Edward Adam Davis
@ 2026-08-15  2:13   ` syzbot
  0 siblings, 0 replies; 4+ messages in thread
From: syzbot @ 2026-08-15  2:13 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-by: syzbot+de42beb9ccc760a210ab@syzkaller.appspotmail.com
Tested-by: syzbot+de42beb9ccc760a210ab@syzkaller.appspotmail.com

Tested on:

commit:         dac3e89a Merge tag 'drm-fixes-2026-08-15' of https://g..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1653d279580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=c44651ea7dd2f307
dashboard link: https://syzkaller.appspot.com/bug?extid=de42beb9ccc760a210ab
compiler:       gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
patch:          https://syzkaller.appspot.com/x/patch.diff?x=134f06c6580000

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

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

* [PATCH] driver core: Cancel the attach if device addition fails
  2026-08-14  8:51 [syzbot] [kernel?] general protection fault in __device_attach (2) syzbot
  2026-08-15  1:57 ` Edward Adam Davis
@ 2026-08-15  2:22 ` Edward Adam Davis
  1 sibling, 0 replies; 4+ messages in thread
From: Edward Adam Davis @ 2026-08-15  2:22 UTC (permalink / raw)
  To: syzbot+de42beb9ccc760a210ab
  Cc: gregkh, rafael, dakr, driver-core, linux-kernel, syzkaller-bugs

syzbot reported a null-ptr-deref below [1] following a fault injection in
device_add(). [0]

When device_add() fails, dev->p is NULL.
Later, __device_attach() tries to access members of
dev->p(e.g., dev->p->dead), the issue in [1] is triggered.

Let's handle the error of __device_attach() properly.

[0]
FAULT_INJECTION: forcing a failure.
name failslab, interval 1, probability 1, space 0, times 1000000
Workqueue: events_long serio_handle_event
Call Trace:
 kmem_cache_alloc_noprof+0x91/0x6a0
 kernfs_new_node+0x117/0x150
 __kernfs_create_file+0x53/0x350
 sysfs_add_file_mode_ns+0x207/0x3c0
 internal_create_group+0x593/0xfb0
 internal_create_groups+0x9d/0x150
 device_add+0xf60/0x1970
 serio_handle_event+0x59b/0x990

[1]
KASAN: null-ptr-deref in range [0x0000000000000108-0x000000000000010f]
RIP: 0010:__device_attach+0xb0/0x4d0 drivers/base/dd.c:1074
Call Trace:
 serio_find_driver drivers/input/serio/serio.c:112 [inline]
 serio_handle_event+0x60a/0x990 drivers/input/serio/serio.c:206

Fixes: 654888327e9f ("driver core: Avoid binding drivers to dead devices")
Reported-by: syzbot+de42beb9ccc760a210ab@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=de42beb9ccc760a210ab
Tested-by: syzbot+de42beb9ccc760a210ab@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 drivers/base/dd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 60c005223844..d345f6c175a6 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1071,7 +1071,7 @@ static int __device_attach(struct device *dev, bool allow_async)
 	bool async = false;
 
 	device_lock(dev);
-	if (dev->p->dead) {
+	if (!dev->p || dev->p->dead) {
 		goto out_unlock;
 	} else if (dev->driver) {
 		if (device_is_bound(dev)) {
-- 
2.43.0


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

end of thread, other threads:[~2026-08-15  2:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14  8:51 [syzbot] [kernel?] general protection fault in __device_attach (2) syzbot
2026-08-15  1:57 ` Edward Adam Davis
2026-08-15  2:13   ` syzbot
2026-08-15  2:22 ` [PATCH] driver core: Cancel the attach if device addition fails Edward Adam Davis

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