Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

auditsc: replace memcpy() with strscpy()

Using strscpy() to read the task comm ensures that the name is always
NUL-terminated, regardless of the source string. This approach also
facilitates future extensions to the task comm.

Link: https://lkml.kernel.org/r/20241007144911.27693-3-laoar.shao@gmail.com
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Reviewed-by: Justin Stitt <justinstitt@google.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Alejandro Colomar <alx@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Airlie <airlied@gmail.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: James Morris <jmorris@namei.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Matus Jokay <matus.jokay@stuba.sk>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Ondrej Mosnacek <omosnace@redhat.com>
Cc: Quentin Monnet <qmo@kernel.org>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Simon Horman <horms@kernel.org>
Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Yafang Shao and committed by
Andrew Morton
286d7a54 4cc0473d

+3 -3
+3 -3
kernel/auditsc.c
··· 2730 2730 context->target_uid = task_uid(t); 2731 2731 context->target_sessionid = audit_get_sessionid(t); 2732 2732 security_task_getsecid_obj(t, &context->target_sid); 2733 - memcpy(context->target_comm, t->comm, TASK_COMM_LEN); 2733 + strscpy(context->target_comm, t->comm); 2734 2734 } 2735 2735 2736 2736 /** ··· 2757 2757 ctx->target_uid = t_uid; 2758 2758 ctx->target_sessionid = audit_get_sessionid(t); 2759 2759 security_task_getsecid_obj(t, &ctx->target_sid); 2760 - memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN); 2760 + strscpy(ctx->target_comm, t->comm); 2761 2761 return 0; 2762 2762 } 2763 2763 ··· 2778 2778 axp->target_uid[axp->pid_count] = t_uid; 2779 2779 axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t); 2780 2780 security_task_getsecid_obj(t, &axp->target_sid[axp->pid_count]); 2781 - memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN); 2781 + strscpy(axp->target_comm[axp->pid_count], t->comm); 2782 2782 axp->pid_count++; 2783 2783 2784 2784 return 0;