From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E31C1DE4D3 for ; Mon, 7 Oct 2024 18:51:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728327072; cv=none; b=Uy0T3FyTIhrAa3y/GSZ+d0JB5F3lULmXED8yheqGar4VCmo8xTB2MqaTylZBG1nN05mvAqa8SSdh8YxDIvFoUbrgL9qA39K92HMbqLeqC4xyuY8nikd9PMkSlnlbHF/tbdIMCg81HGDiD89A5QJGUaknwIsFn6a3t/tgpoxy61Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728327072; c=relaxed/simple; bh=WJ+nkqLMq+mK7j+QwJHq4O2fDpKY7oM+fG1E1UnVNOw=; h=Date:To:From:Subject:Message-Id; b=cY+f0Jc9hLal2pnzyiN8MS45WupLRHB1eCZ0Pauze1WK+OL0S6xegRNlEfz1/V8xiWQv9m43QKyQnObewWNRkyHmjSG3emWJhlt+/tvfisZj6IIiauORpDgpAbyZzTdKYi3P3LJSM7sygbzbxP6lsSB330trYnUY5SdxzhS1M6g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=z/sCIBvY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="z/sCIBvY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3BAEC4CEC7; Mon, 7 Oct 2024 18:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1728327072; bh=WJ+nkqLMq+mK7j+QwJHq4O2fDpKY7oM+fG1E1UnVNOw=; h=Date:To:From:Subject:From; b=z/sCIBvYeuCnjBcaS9s5LaVP0Ya3vTTxoT1JJR+wZCZlT0nFw8v9o0yAyxxkA16YX h+tVq9RflKjh+9eUZHyHZPAPrz+slSJXVgdKsjT7f+y7VX/uViSTtTF0Vd4FghKwhI /q9P85Svp4kXRF4AiRhCxfjxwcZIsjmuw8n7YS1E= Date: Mon, 07 Oct 2024 11:51:11 -0700 To: mm-commits@vger.kernel.org,willy@infradead.org,viro@zeniv.linux.org.uk,tzimmermann@suse.de,torvalds@linux-foundation.org,stephen.smalley.work@gmail.com,serge@hallyn.com,rostedt@goodmis.org,qmo@kernel.org,penguin-kernel@I-love.SAKURA.ne.jp,paul@paul-moore.com,omosnace@redhat.com,mripard@kernel.org,matus.jokay@stuba.sk,maarten.lankhorst@linux.intel.com,keescook@chromium.org,justinstitt@google.com,jmorris@namei.org,jack@suse.cz,horms@kernel.org,eparis@redhat.com,ebiederm@xmission.com,daniel.vetter@ffwll.ch,catalin.marinas@arm.com,brauner@kernel.org,andy.shevchenko@gmail.com,alx@kernel.org,alexei.starovoitov@gmail.com,airlied@gmail.com,laoar.shao@gmail.com,akpm@linux-foundation.org From: Andrew Morton Subject: + security-replace-memcpy-with-get_task_comm.patch added to mm-nonmm-unstable branch Message-Id: <20241007185111.E3BAEC4CEC7@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: security: replace memcpy() with get_task_comm() has been added to the -mm mm-nonmm-unstable branch. Its filename is security-replace-memcpy-with-get_task_comm.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/security-replace-memcpy-with-get_task_comm.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Yafang Shao Subject: security: replace memcpy() with get_task_comm() Date: Mon, 7 Oct 2024 22:49:07 +0800 Quoted from Linus [0]: selinux never wanted a lock, and never wanted any kind of *consistent* result, it just wanted a *stable* result. Using get_task_comm() 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-4-laoar.shao@gmail.com Signed-off-by: Yafang Shao Link: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npJooP8chLPEfaFV0oNYTTBA@mail.gmail.com/ [0] Acked-by: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek Cc: Alejandro Colomar Cc: Alexander Viro Cc: Alexei Starovoitov Cc: Andy Shevchenko Cc: Catalin Marinas Cc: Christian Brauner Cc: Daniel Vetter Cc: David Airlie Cc: Eric Biederman Cc: Eric Paris Cc: Jan Kara Cc: Justin Stitt Cc: Kees Cook Cc: Linus Torvalds Cc: Maarten Lankhorst Cc: Matthew Wilcox Cc: Matus Jokay Cc: Maxime Ripard Cc: Quentin Monnet Cc: Simon Horman Cc: Steven Rostedt (Google) Cc: Tetsuo Handa Cc: Thomas Zimmermann Signed-off-by: Andrew Morton --- security/lsm_audit.c | 4 ++-- security/selinux/selinuxfs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) --- a/security/lsm_audit.c~security-replace-memcpy-with-get_task_comm +++ a/security/lsm_audit.c @@ -207,7 +207,7 @@ static void dump_common_audit_data(struc BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2); audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current)); - audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm))); + audit_log_untrustedstring(ab, get_task_comm(comm, current)); switch (a->type) { case LSM_AUDIT_DATA_NONE: @@ -302,7 +302,7 @@ static void dump_common_audit_data(struc char comm[sizeof(tsk->comm)]; audit_log_format(ab, " opid=%d ocomm=", pid); audit_log_untrustedstring(ab, - memcpy(comm, tsk->comm, sizeof(comm))); + get_task_comm(comm, tsk)); } } break; --- a/security/selinux/selinuxfs.c~security-replace-memcpy-with-get_task_comm +++ a/security/selinux/selinuxfs.c @@ -708,7 +708,7 @@ static ssize_t sel_write_checkreqprot(st if (new_value) { char comm[sizeof(current->comm)]; - memcpy(comm, current->comm, sizeof(comm)); + strscpy(comm, current->comm); pr_err("SELinux: %s (%d) set checkreqprot to 1. This is no longer supported.\n", comm, current->pid); } _ Patches currently in -mm which might be from laoar.shao@gmail.com are get-rid-of-__get_task_comm.patch auditsc-replace-memcpy-with-strscpy.patch security-replace-memcpy-with-get_task_comm.patch bpftool-ensure-task-comm-is-always-nul-terminated.patch mm-util-fix-possible-race-condition-in-kstrdup.patch mm-util-deduplicate-code-in-kstrdupkstrndupkmemdup_nul.patch drm-replace-strcpy-with-strscpy.patch