| From: Arnd Bergmann <arnd@arndb.de> |
| Subject: blktrace: convert strncpy() to strscpy_pad() |
| Date: Tue, 9 Apr 2024 16:00:57 +0200 |
| |
| gcc-9 warns about a possibly non-terminated string copy: |
| |
| kernel/trace/blktrace.c: In function 'do_blk_trace_setup': |
| kernel/trace/blktrace.c:527:2: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] |
| |
| Newer versions are fine here because they see the following explicit |
| nul-termination. Using strscpy_pad() avoids the warning and |
| simplifies the code a little. The padding helps give a clean |
| buffer to userspace. |
| |
| Link: https://lkml.kernel.org/r/20240409140059.3806717-5-arnd@kernel.org |
| Signed-off-by: Arnd Bergmann <arnd@arndb.de> |
| Acked-by: Justin Stitt <justinstitt@google.com> |
| Cc: Alexey Starikovskiy <astarikovskiy@suse.de> |
| Cc: Bob Moore <robert.moore@intel.com> |
| Cc: Jens Axboe <axboe@kernel.dk> |
| Cc: Len Brown <lenb@kernel.org> |
| Cc: Lin Ming <ming.m.lin@intel.com> |
| Cc: Masahiro Yamada <masahiroy@kernel.org> |
| Cc: Masami Hiramatsu <mhiramat@kernel.org> |
| Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| Cc: Nathan Chancellor <nathan@kernel.org> |
| Cc: Nicolas Schier <nicolas@fjasle.eu> |
| Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com> |
| Cc: "Richard Russon (FlatCap)" <ldm@flatcap.org> |
| Cc: Steven Rostedt <rostedt@goodmis.org> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| kernel/trace/blktrace.c | 3 +-- |
| 1 file changed, 1 insertion(+), 2 deletions(-) |
| |
| --- a/kernel/trace/blktrace.c~blktrace-convert-strncpy-to-strscpy_pad |
| +++ a/kernel/trace/blktrace.c |
| @@ -524,8 +524,7 @@ static int do_blk_trace_setup(struct req |
| if (!buts->buf_size || !buts->buf_nr) |
| return -EINVAL; |
| |
| - strncpy(buts->name, name, BLKTRACE_BDEV_SIZE); |
| - buts->name[BLKTRACE_BDEV_SIZE - 1] = '\0'; |
| + strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE); |
| |
| /* |
| * some device names have larger paths - convert the slashes |
| _ |