mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 20:54:03 +02:00
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. Signed-off-by: William Palacek <William.Palacek@amd.com> Reviewed-by: Alysa Liu <Alysa.Liu@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
parent
46fda8bda6
commit
9ba9a14863
|
|
@ -224,10 +224,10 @@ static void kfd_smi_event_add(struct task_struct *task, struct kfd_node *dev,
|
|||
|
||||
pid = kfd_smi_task_to_pid(task);
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user