From patchwork Fri Jun 21 02:29:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706694 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82D46C2BD05 for ; Fri, 21 Jun 2024 02:31:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F41768D0120; Thu, 20 Jun 2024 22:31:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF1D98D0111; Thu, 20 Jun 2024 22:31:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D428F8D0120; Thu, 20 Jun 2024 22:31:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AD2108D0111 for ; Thu, 20 Jun 2024 22:31:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2F529407A3 for ; Fri, 21 Jun 2024 02:31:13 +0000 (UTC) X-FDA: 82253318826.21.ADCD407 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) by imf02.hostedemail.com (Postfix) with ESMTP id 593848000A for ; Fri, 21 Jun 2024 02:31:10 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AgwnvLU0; spf=pass (imf02.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.179 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718937060; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nQwUpm7TadSQyuNlGOfh8JWtJNghSVDBcHtu3NLgdvg=; b=0jBwL5yrlXr9fXVtTA5RuSP0t4vwxPLHpkO5BpKmZJXAQR3iy5wz6e3kiq/RJrU9vztqT1 /nLReGsQtxK8JZF4NEu5yBPtGQLI7VEq/Cz223ryesIm4gznh4yB1Kjm2WVv7snF6Cp59+ Fw1WRE7L24QYKEM/WARrgWOfwMb+iAA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718937060; a=rsa-sha256; cv=none; b=UcUS9JFTQ2GYFEoGmdyx4ubYUDHS9aTBe1dB+kiJ976sZY1CQGI6GC7ou+Dx4OpN9yKuYI GCyU4FD3d9D7jEGFEehB68KLkPsw6zumxg0rvz9SBremF4VeabgysJm7YXtlM8E8Qj9LTM NMSScP6IxeC3zzNPLmXhq7mFX/SnpoY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AgwnvLU0; spf=pass (imf02.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.179 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3d21f7cc6c0so868393b6e.0 for ; Thu, 20 Jun 2024 19:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937069; x=1719541869; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nQwUpm7TadSQyuNlGOfh8JWtJNghSVDBcHtu3NLgdvg=; b=AgwnvLU0KKc5eOe7HDyHltJscjGBoLk8eSl7qrw4eN3zncyspPJg8pcWBZZ+hiihRj pR8kOPPVy5t1pMV/lVJuG05iUktKeZ6rQGkcZAdLsG1WDJouyTpPih1s30tJToBKER5e MEVbyGNVkvQVQf5JFRPp7JVekDIgtdo0Uwr07IP6Sa8cykL3VAH/clw4QfD8sx2u+3cH 1V3C6SnElC1OuYrf7myUUk9dbZeEb93JyDL+LeCa3feNWpZOtf2+9MRz7jgPG6ndYYPY +fZLvRoqAdBCv8jPQy47263m/CPvbGFCcwlUdIbx7BS2hGKnXuCEBg+j0oXcUteFY9gd LXtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937069; x=1719541869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nQwUpm7TadSQyuNlGOfh8JWtJNghSVDBcHtu3NLgdvg=; b=uM2KfQa3dW7+yiwC/BpHoTE2T3vpjJ/tzHOhPQ8yHihS7NwAFKuF9KnTwrxK5TwuoB pJaJttdLcl4x9Rum8v/ot7mHvVJlgmahY+oyYAzkTlASHD5WXToQb+TUg2N5N8IselkO w+yj324O8Jga7K1+Sh3ec3Y0POfuHncTEnYmxpHogpMG+DYsmwOV0bFfkcXmk8fo9Rlv WYAeheSxJvafcOlmx8JEaxo5VGkSB1d7Bllc7k/MwYDB+i3yYHZe6gdvItnbiGxuUP7l m5g9dVy4L8WvE/6EX/ifaCiRBRws2WBmZ+WuqpDeb2lPKSvljontzxxghCbmTO2cISKZ cLRw== X-Forwarded-Encrypted: i=1; AJvYcCUEgfLdfGeRBzvKmUmqF2OZeCOE1za5XPTuIg1UMR7eUXNVhmV3G0SOhZmPQ9qITc1Ydxsu5WztXFzpDXcBfhjh2kE= X-Gm-Message-State: AOJu0Yz8voVkbCeV60McojuI5esg/ZSA6AFdUfD4xZ6Lc+XYGGNUcwFl pBnlzs7fJdMEqivT79ABV4OyUn03h9h04NV2tqVAsFLf1XDAbjGc X-Google-Smtp-Source: AGHT+IF9RQI6I8fwWnu/VEcjE+HIUegV9PWFNk6TPRJqj9VSP13v0pKuFsE10NjsKk43i459GXxRWg== X-Received: by 2002:a05:6870:b52c:b0:254:7a82:cb3f with SMTP id 586e51a60fabf-25c94a2368bmr7837289fac.25.1718937069341; Thu, 20 Jun 2024 19:31:09 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.30.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:31:08 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, penguin-kernel@i-love.sakura.ne.jp, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, audit@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, Yafang Shao , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Ondrej Mosnacek Subject: [PATCH v3 03/11] security: Replace memcpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:51 +0800 Message-Id: <20240621022959.9124-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: ofzm35a6w8ofg3kbkyys9jke7b4jud1u X-Rspamd-Queue-Id: 593848000A X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718937070-641272 X-HE-Meta: U2FsdGVkX18OoTdBBi7XL7GAiUpN7QgPkU5B+Y3vDCT+ixYHZpy/qzFzOAm54+41fphwB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WyPWoXa4oFj634jJIE5JUdn7vsMbNy7s9Py96aWHPNBwoE0ePTqcXISy9y5F5J5fWJDDAiPyQn9MLF85vr3oUXzpluGowPGVn3wrXZDSUAfEUIXIH/ujX1gEU/WaHA74txrb0kPfWz1hQGdlfPqJDTiJEYdWSB6NI5E5934wQsNsPHMf5ohweUH+8qz1jTFJtoVCawJYA2KfDzFdxD+ObfNwr2gz8AvDHyfJbMiycTJ9CUeCy8YZ8QgODxdh/Up6kvYEb/ABnjqjH0dMJKXWQ0W0aTi9fm4nAAF/N3U2Ns8v5KhKCre+TDmKxf1pKydz2qaC1lcLbjEp4QVUREmyM4ELdzmmBPoaX/2zAP/tMkaieDUjEGDafzsd0MDs7UZfhaO7o9Y20uyvhLVV2iMnQ+tu6ZoBIg1RCXqugOWsV9iIWagDXFIGJ0PyzZ5feYUCM8sz+DVf4ezu+FSWdXIsvc098cQd7cnKPUdAw3DKY2553TF8DtySlz6tjNIQa4XosVf6tP/FaYgowiWUJNH1QKP8km2vt1PvZXdoBoF0YHESzUiRuj2abBEChQ4jmIGj755HdK6SXAXK0VqQ2x4Ze+lF3JSPzuxXpnKk2gbXL X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. 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 --- security/lsm_audit.c | 4 ++-- security/selinux/selinuxfs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/security/lsm_audit.c b/security/lsm_audit.c index 849e832719e2..a922e4339dd5 100644 --- a/security/lsm_audit.c +++ b/security/lsm_audit.c @@ -207,7 +207,7 @@ static void dump_common_audit_data(struct audit_buffer *ab, 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, sizeof(comm), current)); switch (a->type) { case LSM_AUDIT_DATA_NONE: @@ -302,7 +302,7 @@ static void dump_common_audit_data(struct audit_buffer *ab, 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, sizeof(comm), tsk)); } } break; diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index e172f182b65c..a8a2ec742576 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -708,7 +708,7 @@ static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf, if (new_value) { char comm[sizeof(current->comm)]; - memcpy(comm, current->comm, sizeof(comm)); + __get_task_comm(comm, sizeof(comm), current); pr_err("SELinux: %s (%d) set checkreqprot to 1. This is no longer supported.\n", comm, current->pid); }