Per Documentation/filesystems/sysfs.rst, new implementations of
show() methods should only use sysfs_emit() or sysfs_emit_at()
when formatting the value to be returned to user space, since it
is aware of the sysfs PAGE_SIZE buffer and includes sanity checks
that sprintf() lacks.
This fixes fade_in_show() and fade_out_show() (both generated by
the gb_lights_fade_attr() macro) and color_show().
Signed-off-by: Tomasz Unger <tomasz.unger(a)yahoo.pl>
---
Verified with checkpatch.pl - no errors or warnings.
Compiled the gb-light module successfully with CONFIG_GREYBUS_LIGHT=m
and CONFIG_LEDS_CLASS_FLASH=m (both previously disabled).
greybus.ko, led-class-flash.ko and gb-light.ko all load without
errors in a QEMU environment (verified via insmod and lsmod, dmesg
shows no errors). This confirms the modules load cleanly but does
not exercise the changed sysfs show() code paths, which would
require an actual Greybus light device bound to the driver.
---
drivers/staging/greybus/light.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index cab02b5da867..2689f9a7524a 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -173,7 +173,7 @@ static ssize_t fade_##__dir##_show(struct device *dev, \
struct led_classdev *cdev = dev_get_drvdata(dev); \
struct gb_channel *channel = get_channel_from_cdev(cdev); \
\
- return sprintf(buf, "%u\n", channel->fade_##__dir); \
+ return sysfs_emit(buf, "%u\n", channel->fade_##__dir); \
} \
\
static ssize_t fade_##__dir##_store(struct device *dev, \
@@ -220,7 +220,7 @@ static ssize_t color_show(struct device *dev, struct device_attribute *attr,
struct led_classdev *cdev = dev_get_drvdata(dev);
struct gb_channel *channel = get_channel_from_cdev(cdev);
- return sprintf(buf, "0x%08x\n", channel->color);
+ return sysfs_emit(buf, "0x%08x\n", channel->color);
}
static ssize_t color_store(struct device *dev, struct device_attribute *attr,
---
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
change-id: 20260819-greybus-light-sysfs-emit-4b8beab74fcc
Best regards,
--
Tomasz Unger <tomasz.unger(a)yahoo.pl>
Per Documentation/filesystems/sysfs.rst, new implementations of
show() methods should only use sysfs_emit() or sysfs_emit_at()
when formatting the value to be returned to user space, since it
is aware of the sysfs PAGE_SIZE buffer and includes sanity checks
that sprintf() lacks.
Signed-off-by: Tomasz Unger <tomasz.unger(a)yahoo.pl>
---
Verified with checkpatch.pl - no errors or warnings.
Compiled the gb-gbphy module successfully with CONFIG_GREYBUS=m
and CONFIG_GREYBUS_BRIDGED_PHY=m (both previously disabled).
Both greybus.ko and gb-gbphy.ko load without errors in a QEMU
environment (verified via insmod and lsmod). This confirms the
modules load cleanly but does not exercise the changed sysfs
show() code path, which would require an actual Greybus device
(or a userspace simulator such as gbsim) bound to the driver.
---
drivers/staging/greybus/gbphy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/greybus/gbphy.c b/drivers/staging/greybus/gbphy.c
index bdb0f5164a6f..bb9a5b538e6e 100644
--- a/drivers/staging/greybus/gbphy.c
+++ b/drivers/staging/greybus/gbphy.c
@@ -31,7 +31,7 @@ static ssize_t protocol_id_show(struct device *dev,
{
struct gbphy_device *gbphy_dev = to_gbphy_dev(dev);
- return sprintf(buf, "0x%02x\n", gbphy_dev->cport_desc->protocol_id);
+ return sysfs_emit(buf, "0x%02x\n", gbphy_dev->cport_desc->protocol_id);
}
static DEVICE_ATTR_RO(protocol_id);
---
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
change-id: 20260818-greybus-gbphy-sysfs-emit-69739912458e
Best regards,
--
Tomasz Unger <tomasz.unger(a)yahoo.pl>
gb_lights_channel_config() builds the LED classdev name with kasprintf()
and stores it in cdev->name for every channel during the configuration
phase, which runs before the channel is registered.
That name was only released by __gb_lights_led_unregister(), i.e. only for
a normal LED channel that was actually registered. It was therefore leaked
in two cases:
- a channel that is configured but never registered, e.g.
channel_attr_groups_set() fails, the flash configuration fails, or a
later channel in the same light fails to configure and the whole light
is torn down; the release path calls gb_lights_channel_unregister()
(which returns early because the channel is not registered) and then
gb_lights_channel_free();
- a flash, torch or indicator channel, whose unregister path
(__gb_lights_flash_led_unregister()) never releases cdev->name at all,
so the name leaks even on a successful teardown.
cdev->name is a configuration-phase allocation, like channel->color_name
and channel->mode_name. Free it in gb_lights_channel_free() next to
those, since that runs unconditionally on every teardown path, and drop
the special case free from __gb_lights_led_unregister().
gb_lights_channel_unregister() is only ever called from
gb_lights_channel_release(), immediately followed by
gb_lights_channel_free(), so the name is still released on the registered
path and is freed exactly once.
Commit 04820da21050 ("staging: greybus: light: Release memory obtained by
kasprintf") fixed the leak for the registered normal-LED path only; this
covers the remaining cases.
Fixes: 2870b52bae4c ("greybus: lights: add lights implementation")
Assisted-by: Claude:claude-opus-4
Signed-off-by: Cong Nguyen <congnt264(a)gmail.com>
---
Changes in v2:
- Add Assisted-by: tag to document AI assistance, per
Documentation/process/coding-assistants.rst (Greg KH).
- No functional change.
drivers/staging/greybus/light.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index cab02b5da867..1ecca479b5f4 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -905,8 +905,6 @@ static void __gb_lights_led_unregister(struct gb_channel *channel)
return;
led_classdev_unregister(cdev);
- kfree(cdev->name);
- cdev->name = NULL;
channel->led = NULL;
}
@@ -1063,6 +1061,9 @@ static int gb_lights_light_register(struct gb_light *light)
static void gb_lights_channel_free(struct gb_channel *channel)
{
+ struct led_classdev *cdev = get_channel_cdev(channel);
+
+ kfree(cdev->name);
kfree(channel->attrs);
kfree(channel->attr_group);
kfree(channel->attr_groups);
--
2.25.1
On Fri, Aug 28, 2026 at 06:00:04PM +0800, Yang Zi wrote:
> gb_connection_recv() accepts a received message whose advertised size is
> smaller than struct gb_operation_msg_hdr. In particular, a header with a
> size of zero passes the incomplete-message check and reaches
> gb_operation_create_incoming().
Thanks for the fix.
Please shorten the commit summary (Subject) to something less verbose,
like:
greybus: operation: fix NULL-deref on short request
> This issue was found using a locally modified syzkaller. The
> analysis and fix were assisted by GPT-5.6.
This can go at the end of the commit message.
> The subtraction used to derive the request payload size then underflows.
> When gb_operation_message_alloc() adds the header size, the result wraps
> to zero, bypassing the maximum-buffer-size check. kzalloc(0) returns
> ZERO_SIZE_PTR and gb_operation_message_init() subsequently dereferences
> it.
>
> Reject advertised sizes smaller than the message header. Also check the
> payload size before adding the header size, so that the size calculation
> cannot wrap and bypass the buffer-size limit.
This is arguably two changes; a fix for the NULL-deref due to the
missing header sanity check and a hardening against any further bugs
like it.
But I guess they can go in together in one patch like you do here.
> Fixes: 87d208feb74f ("greybus: embed message buffer into message structure")
This is not the commit that introduced the issue. This should be:
Fixes: d90c25b0a279 ("greybus: let operation layer examine incoming data")
as that's the commit that started acting on the header size field
without first rejecting invalid headers (even if there was a WARN_ON()
at that time).
> Assisted-by: Codex:gpt-5.6
> Signed-off-by: Yang Zi <2959243019(a)qq.com>
> ---
> v2:
> - Add the syzkaller provenance and Assisted-by trailer.
> - Regenerate the patch for git-send-email.
> - Verify the received patch with git am and checkpatch.
>
> drivers/greybus/operation.c | 18 +++++++++++++++---
> 1 file changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c
> index 7e12ffb2dd60..c3d51176c373 100644
> --- a/drivers/greybus/operation.c
> +++ b/drivers/greybus/operation.c
> @@ -364,14 +364,21 @@ gb_operation_message_alloc(struct gb_host_device *hd, u8 type,
> {
> struct gb_message *message;
> struct gb_operation_msg_hdr *header;
> - size_t message_size = payload_size + sizeof(*header);
> + size_t message_size;
>
> - if (message_size > hd->buffer_size_max) {
> + /*
> + * Reject a payload size that would make the total message size
> + * overflow, before it wraps around and bypasses the maximum
> + * buffer size check.
> + */
I think you can drop the comment.
> + if (payload_size > hd->buffer_size_max - sizeof(*header)) {
> dev_warn(&hd->dev, "requested message size too big (%zu > %zu)\n",
And this should now say "payload size".
> - message_size, hd->buffer_size_max);
> + payload_size, hd->buffer_size_max - sizeof(*header));
> return NULL;
> }
>
> + message_size = payload_size + sizeof(*header);
> +
> /* Allocate the message structure and buffer. */
> message = kmem_cache_zalloc(gb_message_cache, gfp_flags);
> if (!message)
> @@ -1047,6 +1054,11 @@ void gb_connection_recv(struct gb_connection *connection,
> /* Use memcpy as data may be unaligned */
> memcpy(&header, data, sizeof(header));
> msg_size = le16_to_cpu(header.size);
> + if (msg_size < sizeof(header)) {
> + dev_err_ratelimited(dev, "%s: short message received (%zu < %zu)\n",
> + connection->name, msg_size, sizeof(header));
> + return;
> + }
> if (size < msg_size) {
> dev_err_ratelimited(dev,
> "%s: incomplete message 0x%04x of type 0x%02x received (%zu < %zu)\n",
Johan
Hello,
As part of the kernel research at ASU's SEFCOM
lab, we hit the crash below. Crash reports can be found here:
https://github.com/farhad-alemi/public_bug_reports/tree/main/165-warning-od…
ODEBUG: free active (active state 0) object: ffff888014747a70 object
type: timer_list hint: gb_operation_timeout+0x0/0x100
drivers/greybus/operation.c:1265
WARNING: lib/debugobjects.c:632 at
debug_check_no_obj_freed+0x3fd/0x540 lib/debugobjects.c:1156, CPU#1:
kworker/u8:3/10201
Call Trace:
kmem_cache_free+0xcb/0x4d0 mm/slub.c:6378
gb_operation_sync_timeout+0x1c7/0x270 drivers/greybus/operation.c:1172
gb_operation_sync include/linux/greybus/operation.h:203 [inline]
gb_svc_dme_peer_get+0x10a/0x250 drivers/greybus/svc.c:428
gb_interface_read_and_clear_init_status
drivers/greybus/interface.c:380 [inline]
gb_interface_enable+0x146/0x900 drivers/greybus/interface.c:1075
gb_module_register_interface drivers/greybus/module.c:162 [inline]
gb_module_add+0x1b3/0x3d0 drivers/greybus/module.c:209
Our reproducer.c is available upon request.
Happy to test a patch if that would help.
Regards,
Hello,
As part of the kernel research at ASU's SEFCOM
lab, we hit the crash below. Crash reports can be found here:
https://github.com/farhad-alemi/public_bug_reports/tree/main/167-warning-od…
greybus 3-svc: Resetting the greybus network, watch out!!!
ODEBUG: init active (active state 0) object: ffffffff92bbc2a0 object
type: timer_list hint: greybus_reset+0x0/0x50
WARNING: lib/debugobjects.c:632 at __debug_object_init+0x2a8/0x4a0
lib/debugobjects.c:790, CPU#0: kworker/0:4/11040
Call Trace:
debug_timer_init kernel/time/timer.c:788 [inline]
debug_init kernel/time/timer.c:836 [inline]
timer_init_key+0x34/0x1e0 kernel/time/timer.c:880
list_splice_tail_init include/linux/list.h:620 [inline]
do_work+0x19e/0x2b0 drivers/md/dm-kcopyd.c:664
process_one_work kernel/workqueue.c:3314 [inline]
process_scheduled_works+0x881/0x1170 kernel/workqueue.c:3397
worker_thread+0x988/0xde0 kernel/workqueue.c:3478
WARNING: kernel/workqueue.c:806 at insert_work+0x1f3/0x240
BUG: KASAN: slab-use-after-free in do_work+0x257/0x2b0
Our reproducer.c is available upon request.
Happy to test a patch if that would help.
Regards,