KASAN: global-out-of-bounds Read in bus_uevent_store
Subsystems (2)
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: 50d05c7c76c9 Merge tag 'landlock-7.3-rc3' of git://git.ker.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15489c8e580000 kernel config: https://syzkaller.appspot.com/x/.config?x=85bc5cc2fc7394d9 dashboard link: https://syzkaller.appspot.com/bug?extid=9a321aea9d851b299486 compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 userspace arch: i386 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=17de9905580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11f042d1580000
Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/d900f083ada3/non_bootable_disk-50d05c7c.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/303a0ade8f9e/vmlinux-50d05c7c.xz
kernel image: https://storage.googleapis.com/syzbot-assets/70b8ca71442b/bzImage-50d05c7c.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
==================================================================
BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 CPU: 2 UID: 0 PID: 5917 Comm: syz.0.17 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 Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0x13d/0x4b0 mm/kasan/report.c:482 kasan_report+0xdf/0x1c0 mm/kasan/report.c:595 kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687 ksys_write+0x12a/0x250 fs/read_write.c:739 do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:79 [inline] __do_fast_syscall_32+0x13a/0x8b0 arch/x86/entry/syscall_32.c:291 do_fast_syscall_32+0x32/0x70 arch/x86/entry/syscall_32.c:316 entry_SYSENTER_compat_after_hwframe+0x84/0x8e RIP: 0023:0xf702efec Code: Unable to access opcode bytes at 0xf702efc2. RSP: 002b:00000000ffa3eb5c EFLAGS: 00000296 ORIG_RAX: 0000000000000004 RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000080000280 RDX: 000000000000ff0a RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 </TASK> The buggy address belongs to the variable: kobject_actions+0xdff/0x4e80 The buggy address belongs to the physical page: page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0xd725 flags: 0xfff00000002000(reserved|node=0|zone=1|lastcpupid=0x7ff) raw: 00fff00000002000 ffffea000035c948 ffffea000035c948 0000000000000000 raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected
page_owner info is not present (never set?)
Memory state around the buggy address:
ffffffff8d725480: f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9 00 06 f9 f9
ffffffff8d725500: f9 f9 f9 f9 00 00 01 f9 f9 f9 f9 f9 00 00 02 f9
>ffffffff8d725580: f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9 00 07 f9 f9
^
ffffffff8d725600: f9 f9 f9 f9 00 00 06 f9 f9 f9 f9 f9 00 04 f9 f9
ffffffff8d725680: f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9 00 05 f9 f9
==================================================================---
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 [email protected].
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
From: Edward Aadm Davis <[email protected]>
#syz test: upstream 50d05c7c76c9
lib/kobject_uevent.c +2 -1
@@ -83,7 +83,8 @@ static int kobject_action_type(const char *buf, size_t count,for (action =0 ; action <ARRAY_SIZE (kobject_actions); action++) {if (strncmp (kobject_actions[action], buf, count_first) !=0 )continue ; -if (kobject_actions[action][count_first] !='\0' ) +if (count_first <=strlen (kobject_actions[action]) && + kobject_actions[action][count_first] !='\0' )continue ;if (args) *args = args_start;
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 50d05c7c Merge tag 'landlock-7.3-rc3' of git://git.ker.. git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git console output: https://syzkaller.appspot.com/x/log.txt?x=1030fdf9580000 kernel config: https://syzkaller.appspot.com/x/.config?x=85bc5cc2fc7394d9 dashboard link: https://syzkaller.appspot.com/bug?extid=9a321aea9d851b299486 compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 userspace arch: i386 patch: https://syzkaller.appspot.com/x/patch.diff?x=13c07905580000
Note: testing is done by a robot and is best-effort only.
From: Edward Aadm Davis <[email protected]>
#syz test: upstream 50d05c7c76c9
fs/sysfs/file.c +2 -0
@@ -228,10 +228,12 @@ static const struct kernfs_ops sysfs_file_kfops_ro = { };static const struct kernfs_ops sysfs_file_kfops_wo = { + .atomic_write_len =PAGE_SIZE , .write = sysfs_kf_write, };static const struct kernfs_ops sysfs_file_kfops_rw = { + .atomic_write_len =PAGE_SIZE , .seq_show = sysfs_kf_seq_show, .write = sysfs_kf_write, };
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 50d05c7c Merge tag 'landlock-7.3-rc3' of git://git.ker.. git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git console output: https://syzkaller.appspot.com/x/log.txt?x=14307905580000 kernel config: https://syzkaller.appspot.com/x/.config?x=85bc5cc2fc7394d9 dashboard link: https://syzkaller.appspot.com/bug?extid=9a321aea9d851b299486 compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44 userspace arch: i386 patch: https://syzkaller.appspot.com/x/patch.diff?x=147348c9580000
Note: testing is done by a robot and is best-effort only.
PATCH 1/1 sysfs: prevent writing excessively large files
In reply to syzbotSince atomic_write_len is not configured for sysfs_file_kfops_rw, a large file write via sysfs_kf_write() may result in an out-of-bounds read when checking for the null terminator of a string element in the kobject_actions array within kobject_action_type(), potentially hitting:
BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687
Add atomic_write_len for sysfs_file_kfops_rw and sysfs_file_kfops_wo properly.
--- fs/sysfs/file.c | 2 ++ 1 file changed, 2 insertions(+)
fs/sysfs/file.c +2 -0
@@ -228,10 +228,12 @@ static const struct kernfs_ops sysfs_file_kfops_ro = { };static const struct kernfs_ops sysfs_file_kfops_wo = { + .atomic_write_len =PAGE_SIZE , .write = sysfs_kf_write, };static const struct kernfs_ops sysfs_file_kfops_rw = { + .atomic_write_len =PAGE_SIZE , .seq_show = sysfs_kf_seq_show, .write = sysfs_kf_write, };
Signature · 1 line
2.43.0
Greg KH
maintainerRe: [PATCH] sysfs: prevent writing excessively large files
Quoted 4 lines · Edward Adam Davis
Since
atomic_write_lenis not configured forsysfs_file_kfops_rw, a large file write viasysfs_kf_write()may result in an out-of-bounds read when checking for the null terminator of a string element in thekobject_actionsarray withinkobject_action_type(), potentially hitting:
What sysfs file are you hitting this on?
Quoted 14 lines
BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687
Quoted 4 lines
Add
atomic_write_lenforsysfs_file_kfops_rwandsysfs_file_kfops_woproperly.Fixes f6acf8bb6a40 ("sysfs, kernfs: introduce kernfs_ops")
What changed to suddenly cause this to show up now if this has been present for decades?
thanks,
greg k-h
Re: [PATCH] sysfs: prevent writing excessively large files
From: Edward Aadm Davis <[email protected]>
Quoted 6 lines · Greg KH
Quoted 4 lines
Since
atomic_write_lenis not configured forsysfs_file_kfops_rw, a large file write viasysfs_kf_write()may result in an out-of-bounds read when checking for the null terminator of a string element in thekobject_actionsarray withinkobject_action_type(), potentially hitting:What sysfs file are you hitting this on?
Regular sysfs files.
Quoted 15 lines
Quoted 15 lines
BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687
Quoted 7 lines
Quoted 4 lines
Add
atomic_write_lenforsysfs_file_kfops_rwandsysfs_file_kfops_woproperly.Fixes f6acf8bb6a40 ("sysfs, kernfs: introduce kernfs_ops")What changed to suddenly cause this to show up now if this has been present for decades?
This issue has always existed. It remained undetected simply because the buffer lengths typically passed when writing to /sys/bus/acpi/uevent happened to be reasonably appropriate.
cheers,
Edward
Greg KH
maintainerRe: [PATCH] sysfs: prevent writing excessively large files
Quoted 10 lines · Edward Adam Davis
From: Edward Aadm Davis <[email protected]>
Quoted 6 lines · Greg KH
Quoted 4 lines
Since
atomic_write_lenis not configured forsysfs_file_kfops_rw, a large file write viasysfs_kf_write()may result in an out-of-bounds read when checking for the null terminator of a string element in thekobject_actionsarray withinkobject_action_type(), potentially hitting:What sysfs file are you hitting this on?
Regular sysfs files.
Which one, all?
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687Add
atomic_write_lenforsysfs_file_kfops_rwandsysfs_file_kfops_woproperly.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Fixes f6acf8bb6a40 ("sysfs, kernfs: introduce kernfs_ops")What changed to suddenly cause this to show up now if this has been present for decades?
This issue has always existed. It remained undetected simply because the buffer lengths typically passed when writing to
/sys/bus/acpi/ueventhappened to be reasonably appropriate.
So what changed to cause this to show up now?
thanks,
greg k-h
Re: [PATCH] sysfs: prevent writing excessively large files
From: Edward Aadm Davis <[email protected]>
Quoted 9 lines · Greg KH
Quoted 8 lines · Edward Adam Davis
From: Edward Aadm Davis <[email protected]>
Quoted 5 lines · Greg KH
Quoted 4 lines
Since
atomic_write_lenis not configured forsysfs_file_kfops_rw, a large file write viasysfs_kf_write()may result in an out-of-bounds read when checking for the null terminator of a string element in thekobject_actionsarray withinkobject_action_type(), potentially hitting:
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
What sysfs file are you hitting this on?
Regular sysfs files.
Which one, all?
/sys/bus/acpi/uevent
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687Add
atomic_write_lenforsysfs_file_kfops_rwandsysfs_file_kfops_woproperly.Fixes f6acf8bb6a40 ("sysfs, kernfs: introduce kernfs_ops")
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
What changed to suddenly cause this to show up now if this has been present for decades?
This issue has always existed. It remained undetected simply because the buffer lengths typically passed when writing to
/sys/bus/acpi/ueventhappened to be reasonably appropriate.So what changed to cause this to show up now?
Starting from f6acf8bb6a40.
cheers,
Edward
Greg KH
maintainerRe: [PATCH] sysfs: prevent writing excessively large files
In reply to Edward Adam DavisQuoted 50 lines · Edward Adam Davis
Since
atomic_write_lenis not configured forsysfs_file_kfops_rw, a large file write viasysfs_kf_write()may result in an out-of-bounds read when checking for the null terminator of a string element in thekobject_actionsarray withinkobject_action_type(), potentially hitting:BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687Add
atomic_write_lenforsysfs_file_kfops_rwandsysfs_file_kfops_woproperly.Fixes f6acf8bb6a40 ("sysfs, kernfs: introduce kernfs_ops")Reported-by [email protected]Tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- fs/sysfs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/sysfs/file.c +2
-0@@ -228,10 +228,12 @@ static const struct kernfs_ops sysfs_file_kfops_ro = { };static const struct kernfs_ops sysfs_file_kfops_wo = { + .atomic_write_len =PAGE_SIZE , .write = sysfs_kf_write, };static const struct kernfs_ops sysfs_file_kfops_rw = { + .atomic_write_len =PAGE_SIZE , .seq_show = sysfs_kf_seq_show, .write = sysfs_kf_write, };Signature · 1 line
2.43.0
Are you sure this will not break those sysfs files that want larger page sizes? Given the age of this "issue" it's really worrying to me to change it now...
thanks,
greg k-h
Re: [PATCH] sysfs: prevent writing excessively large files
From: Edward Aadm Davis <[email protected]>
Quoted 42 lines · Greg KH
Quoted 42 lines
Since
atomic_write_lenis not configured forsysfs_file_kfops_rw, a large file write viasysfs_kf_write()may result in an out-of-bounds read when checking for the null terminator of a string element in thekobject_actionsarray withinkobject_action_type(), potentially hitting:BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687Add
atomic_write_lenforsysfs_file_kfops_rwandsysfs_file_kfops_woproperly.Fixes f6acf8bb6a40 ("sysfs, kernfs: introduce kernfs_ops")Reported-by [email protected]Tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- fs/sysfs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/sysfs/file.c +1
-0@@ -228,10 +228,12 @@ static const struct kernfs_ops sysfs_file_kfops_ro = { };static const struct kernfs_ops sysfs_file_kfops_wo = { + .atomic_write_len =PAGE_SIZE , .write = sysfs_kf_write, };
Quoted 12 lines
Quoted 8 lines
fs/sysfs/file.c +1
-1static const struct kernfs_ops sysfs_file_kfops_rw = { + .atomic_write_len =PAGE_SIZE , .seq_show = sysfs_kf_seq_show, .write = sysfs_kf_write, }; --2.43.0
Are you sure this will not break those sysfs files that want larger page sizes? Given the age of this "issue" it's really worrying to me to change it now...
Perhaps it would be better to make a decision after delving deeper into the details.
cheers,
Edward
Re: [PATCH] sysfs: prevent writing excessively large files
In reply to Greg KHQuoted 43 lines · On Thu, 17 Sep 2026 08:34:46 +0100 Greg KH <[email protected]> wrote:
Quoted 42 lines · Edward Adam Davis
Since
atomic_write_lenis not configured forsysfs_file_kfops_rw, a large file write viasysfs_kf_write()may result in an out-of-bounds read when checking for the null terminator of a string element in thekobject_actionsarray withinkobject_action_type(), potentially hitting:BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687Add
atomic_write_lenforsysfs_file_kfops_rwandsysfs_file_kfops_woproperly.Fixes f6acf8bb6a40 ("sysfs, kernfs: introduce kernfs_ops")Reported-by [email protected]Tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- fs/sysfs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/sysfs/file.c +1
-0@@ -228,10 +228,12 @@ static const struct kernfs_ops sysfs_file_kfops_ro = { };static const struct kernfs_ops sysfs_file_kfops_wo = { + .atomic_write_len =PAGE_SIZE , .write = sysfs_kf_write, };
Quoted 12 lines
Quoted 8 lines
fs/sysfs/file.c +1
-0static const struct kernfs_ops sysfs_file_kfops_rw = { + .atomic_write_len =PAGE_SIZE , .seq_show = sysfs_kf_seq_show, .write = sysfs_kf_write, };Signature · 1 line
2.43.0Are you sure this will not break those sysfs files that want larger page sizes? Given the age of this "issue" it's really worrying to me to change it now...
If you allowed to leave atomic_write_len as zero then the code shouldn't let an overlong write through (or should truncate it).
So there must be a bug somewhere else.
Do we know the length for the test that failed?
'atomic_write_len' is also badly named - probably historical. There is no code to loop over the fragments of a long write and (IIRC) the write offset is always zero.
There is also some (horrid) related code that can reserve a page buffer (per node) just in case an access is made when kernel memory isn't available.
(a flag and a single global page would suffice...)
David
Quoted 5 lines
thanks,
greg k-h
From: Edward Aadm Davis <[email protected]>
#syz test: upstream 50d05c7c76c9
lib/kobject_uevent.c +1 -1
@@ -78,7 +78,7 @@ static int kobject_action_type(const char *buf, size_t count, count_first = args_start - buf; args_start = args_start +1 ; }else - count_first = count; + count_first =min_t (size_t,strnlen (buf, count), count);for (action =0 ; action <ARRAY_SIZE (kobject_actions); action++) {if (strncmp (kobject_actions[action], buf, count_first) !=0 )
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 50d05c7c Merge tag 'landlock-7.3-rc3' of git://git.ker.. git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git console output: https://syzkaller.appspot.com/x/log.txt?x=13695405580000 kernel config: https://syzkaller.appspot.com/x/.config?x=8c5c3949d762a91f dashboard link: https://syzkaller.appspot.com/bug?extid=9a321aea9d851b299486 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=11ab8d25580000
Note: testing is done by a robot and is best-effort only.
PATCH v2 1/1 kobject: optimize count first value
In reply to Edward Adam DavisThe user writes to the regular sysfs file "/sys/bus/acpi/uevent\000" is as follows:
write(r0, &(0x7f0000000280)='add\x00', 0xff0a);
From the parameters of write, we can know that: buffer is 'add\x00', and buffer count is 0xff0a.
Since atomic_write_len was 0, kernfs_fop_write_iter() would silently truncate the buffer count 0xff0a to PAGE_SIZE.
In kobject_action_type(), the strncmp() successfully stops at the null terminator for "add". Then the code directly attempts to access index 4095 of the 4-byte string literal "add" via kobject_actions[action][count_first], potentially hitting:
BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687
When the buffer does not contain parameters, we take the smaller of the buffer string's actual length and the buffer count provided by the user as count_first.
---
v1 -> v2: change to optimize kobject
lib/kobject_uevent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject_uevent.c +1 -1
@@ -78,7 +78,7 @@ static int kobject_action_type(const char *buf, size_t count, count_first = args_start - buf; args_start = args_start +1 ; }else - count_first = count; + count_first =min_t (size_t,strnlen (buf, count), count);for (action =0 ; action <ARRAY_SIZE (kobject_actions); action++) {if (strncmp (kobject_actions[action], buf, count_first) !=0 )
Signature · 1 line
2.43.0
Greg KH
maintainerRe: [PATCH v2] kobject: optimize count first value
Quoted 4 lines · Edward Adam Davis
The user writes to the regular sysfs file "/sys/bus/acpi/uevent\000" is as follows:
write(r0, &(0x7f0000000280)='add\x00', 0xff0a);
You mean a "root user", right? So don't do that :)
Quoted 28 lines
Quoted 1 line
From the parameters of write, we can know that: buffer is 'add\x00', and
buffer count is
0xff0a.Since
atomic_write_lenwas 0,kernfs_fop_write_iter()would silently truncate the buffer count0xff0atoPAGE_SIZE.In
kobject_action_type(), thestrncmp()successfully stops at the null terminator for "add". Then the code directly attempts to access index 4095 of the 4-byte string literal "add" via kobject_actions[action][count_first], potentially hitting:BUG: KASAN: global-out-of-bounds in kobject_action_type lib/kobject_uevent.c:86 [inline] BUG: KASAN: global-out-of-bounds in kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 Read of size 1 at addr ffffffff8d72559f by task syz.0.17/5917 Call Trace: kobject_action_type lib/kobject_uevent.c:86 [inline] kobject_synth_uevent+0x79d/0x7d0 lib/kobject_uevent.c:200 bus_uevent_store+0x3d/0x90 drivers/base/bus.c:917 bus_attr_store+0x74/0xb0 drivers/base/bus.c:172 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345 new_sync_write fs/read_write.c:595 [inline] vfs_write+0x6af/0x1050 fs/read_write.c:687When the buffer does not contain parameters, we take the smaller of the buffer string's actual length and the buffer count provided by the user as
count_first.
Quoted 7 lines
Fixes 5c5daf657cb5 ("Driver core: exclude kobject_uevent.c for !CONFIG_HOTPLUG")Reported-by [email protected]Tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>---
v1 -> v2: change to optimize kobject
Hasn't this been submitted before from others? Have you seen this thread:
https://lore.kernel.org/r/[email protected]
?
Your "fix" is different from the above, which is correct?
thanks,
greg k-h