Skip to content

Commit c9732f1

Browse files
azeemshaikh38kees
authored andcommitted
perf: Replace strlcpy with strscpy
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). No return values were used, so direct replacement is safe. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] KSPP#89 Signed-off-by: Azeem Shaikh <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 61ce78f commit c9732f1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

kernel/events/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8249,7 +8249,7 @@ static void perf_event_comm_event(struct perf_comm_event *comm_event)
82498249
unsigned int size;
82508250

82518251
memset(comm, 0, sizeof(comm));
8252-
strlcpy(comm, comm_event->task->comm, sizeof(comm));
8252+
strscpy(comm, comm_event->task->comm, sizeof(comm));
82538253
size = ALIGN(strlen(comm)+1, sizeof(u64));
82548254

82558255
comm_event->comm = comm;
@@ -8704,7 +8704,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
87048704
}
87058705

87068706
cpy_name:
8707-
strlcpy(tmp, name, sizeof(tmp));
8707+
strscpy(tmp, name, sizeof(tmp));
87088708
name = tmp;
87098709
got_name:
87108710
/*
@@ -9128,7 +9128,7 @@ void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len, bool unregister,
91289128
ksym_type == PERF_RECORD_KSYMBOL_TYPE_UNKNOWN)
91299129
goto err;
91309130

9131-
strlcpy(name, sym, KSYM_NAME_LEN);
9131+
strscpy(name, sym, KSYM_NAME_LEN);
91329132
name_len = strlen(name) + 1;
91339133
while (!IS_ALIGNED(name_len, sizeof(u64)))
91349134
name[name_len++] = '\0';

0 commit comments

Comments
 (0)