drm/amdkfd: use scnprintf/vscnprintf in kfd_smi_event_add
Subsystems (3)
PATCH 1/1 drm/amdkfd: use scnprintf/vscnprintf in kfd_smi_event_add
snprintf() and vsnprintf() return the number of bytes that would have been written if the buffer were large enough, not the actual bytes written. If truncation occurs, the accumulated length can exceed the buffer size, causing kfifo_in() to read past the fifo_in[] stack buffer.
Switch to scnprintf() and vscnprintf() which return the actual number of bytes written, excluding the null terminator. This prevents the potential buffer over-read when calculating the offset for subsequent writes.
--- drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +2 -2
@@ -206,10 +206,10 @@ static void kfd_smi_event_add(pid_t pid, struct kfd_node *dev,if (list_empty (&dev->smi_clients))return ; - len =snprintf (fifo_in,sizeof (fifo_in),"%x " , event); + len =scnprintf (fifo_in,sizeof (fifo_in),"%x " , event);va_start (args, fmt); - len +=vsnprintf (fifo_in + len,sizeof (fifo_in) - len, fmt, args); + len +=vscnprintf (fifo_in + len,sizeof (fifo_in) - len, fmt, args);va_end (args);add_event_to_kfifo (pid, dev, event, fifo_in, len);
Signature · 1 line
2.34.1
AMD General
-----Original Message-----
From: Palacek, William <[email protected]>
Sent: Thursday, May 28, 2026 10:05 AM
To: [email protected]
Cc: Liu, Alysa <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Palacek, William <[email protected]>
Subject: [PATCH] drm/amdkfd: use scnprintf/vscnprintf in kfd_smi_event_add
snprintf() and vsnprintf() return the number of bytes that would have been written if the buffer were large enough, not the actual bytes written. If truncation occurs, the accumulated length can exceed the buffer size, causing kfifo_in() to read past the fifo_in[] stack buffer.
Switch to scnprintf() and vscnprintf() which return the actual number of bytes written, excluding the null terminator. This prevents the potential buffer over-read when calculating the offset for subsequent writes.
--- drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +2 -2
@@ -206,10 +206,10 @@ static void kfd_smi_event_add(pid_t pid, struct kfd_node *dev,if (list_empty (&dev->smi_clients))return ; - len =snprintf (fifo_in,sizeof (fifo_in),"%x " , event); + len =scnprintf (fifo_in,sizeof (fifo_in),"%x " , event);va_start (args, fmt); - len +=vsnprintf (fifo_in + len,sizeof (fifo_in) - len, fmt, args); + len +=vscnprintf (fifo_in + len,sizeof (fifo_in) - len, fmt, args);va_end (args);add_event_to_kfifo (pid, dev, event, fifo_in, len);
--
2.34.1