From patchwork Mon Jul 29 02:37:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744222 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 550CDC3DA49 for ; Mon, 29 Jul 2024 02:39:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E01A06B009F; Sun, 28 Jul 2024 22:39:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB1626B00A0; Sun, 28 Jul 2024 22:39:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7A006B00A1; Sun, 28 Jul 2024 22:39:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A8AD26B009F for ; Sun, 28 Jul 2024 22:39:31 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 614F6C0190 for ; Mon, 29 Jul 2024 02:39:31 +0000 (UTC) X-FDA: 82391234142.28.E93EED5 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf05.hostedemail.com (Postfix) with ESMTP id 8E596100002 for ; Mon, 29 Jul 2024 02:39:29 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZlL64ZNS; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 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=1722220699; 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=J+uQG4RKAtUTljj+c6PuEzvl8DtV0722F0vMFtL07WU=; b=PtjrkFnlN5XqjoUcPn8SQ/y782yz1BCn2PqOm7TrGCvGZOoRTNob08NvYOmMgVSVlD9Ya3 93fNEox1BhXJocJEgZTjdGTTfYATMhJfRtBi3Ub9MjJ0EGN6g7X9PqQ9cJZ9mXgP9Ta8LO X2eq7AYDAYDmr7xS/1ZqQrAt+E5BnVg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZlL64ZNS; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722220699; a=rsa-sha256; cv=none; b=wZ6/SLEQNtRA2QwsaAgefEE1Bu8LxySZu0AneVqM9NRzMRvmuA9QTNXWAGT5NyV9Ft+Ued pz9fNyOFvDrZoqPG5+UUu6VHPQfB5XTp8EO/FQh1VZ1Nwk3naRb1FyLoaUj9IhBddGEcNT 1xl7QsNHCsFXP82obqlwPFY/kyRu7cQ= Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7aa7703cf08so2045616a12.2 for ; Sun, 28 Jul 2024 19:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722220768; x=1722825568; 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=J+uQG4RKAtUTljj+c6PuEzvl8DtV0722F0vMFtL07WU=; b=ZlL64ZNS8UDqKxFuq26z7VoN3njNKdST0WbpaGqaXXdCoNdJEUNLD5VohTPdATRLn4 /1o5eDu/LeaGe70FQ5cC2iygT+NeP2MmZjDbykBuRezIVOtumruZUnHF3sFtAn0POEcb uvfDgiXVYau1J0fQVJGtWtThKfSQsNFqUTrzVYfQgIctnRI3vxOo4bSWOewlewbG0Tkj 1+3Pr7Yu3p9PfFDd2JjxaXpooEkA+qsepwgU5SqCop6gDyPh2H6Mrjkrb86fAq0j0Zm/ ZhNHf0iKuvbmNcPnZBW2EqOBZCLC1igTMMUAi2bsEQcJz6yPrRnI1AlnBjYwdJH+n7mW itlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722220768; x=1722825568; 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=J+uQG4RKAtUTljj+c6PuEzvl8DtV0722F0vMFtL07WU=; b=h5dmlyjmHcq6MZGfCZWVDkw72+Y7nVB4nAkbVS9ZHLZ9rSXxNXs0yRrOjKsQGQ7tji +Z5onRPSzl9v0622cPFjLk66ZdDfm2nDTwFUwAQ+rn6T+neCG4kjZZk/Hom7Q5u2gbLd PHkWOzItVsBQTDTt/CJz/O4wjWMi75AlCUjhxgfsaFcBz/rG0BcvxwXsPKoK4aRh2LTR VN0Oo7cN0lG50A44sUIfbtKxiRTktCGhN03vZ/3xE0kxf87ReRjPfhX3SQfTEw9OcObn s5T9KBOWeBxrNM2N0oXoua0gWiKkIxEotAkI1wMAlNboRp6FLFu3pPq3bWI2mC3SqqAb jEJg== X-Forwarded-Encrypted: i=1; AJvYcCVJMkquiPghguXqicM5/ZM/voznWH67Cptd8RKjl7DSM8Vvnuvs5j3RUcwvedypO4nNGzJflitCqzIHrrb8jLwzN3I= X-Gm-Message-State: AOJu0YzBTZafdvcBaftpaE7H7EIHiTSJu1VHNMvuHYAKuJy8LfW/MmS/ JxGTWCItnYJXKJ4bh4sMgYyPy2YlKo3FcvHG67ar63Yn/fQv4pEe X-Google-Smtp-Source: AGHT+IGDDVacAHzuqJf1zY2UQsKDkDe/fVaez1tdPtuFhqBPLEHRkdQpCzionBNRtCrdgKFvX6YkKg== X-Received: by 2002:a05:6a20:d50a:b0:1c4:8bba:76e9 with SMTP id adf61e73a8af0-1c4a153afecmr8452767637.53.1722220768309; Sun, 28 Jul 2024 19:39:28 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.39.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:39:27 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, 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 v4 03/11] security: Replace memcpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:11 +0800 Message-Id: <20240729023719.1933-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8E596100002 X-Stat-Signature: dqb8p1fbhmgepewpih8xg7fkes19ay7c X-Rspam-User: X-HE-Tag: 1722220769-850977 X-HE-Meta: U2FsdGVkX19aDmrXX8XPn12cFBW4GvQQN6691LmiO2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mKqJax5h/5NjK/A/FWUSgLs8tepL66cSBG0uKnkJ1TVk0YdFkydWisz06nAkE176e6eRs6FBvK6gMKj6gRxfiEEZFR7lEk1/imF8lc327BZDpvwJwZU0L95jV//i09Tx4p+kCmGaGfS4d+eMwUUm1jiy5Nt3ae75BBn8uVGHMCYTsGHc9or1xyXXMPjMSt2e+o+LKckNCpcJGbvV3G4teIIb/g22Rs55Sy083dgs82T8fEsketlS41jfjxo43RJ31QiJryb1Je8WiIsQkhvtiix32b8d1o7vT1ZSucJmrQkc5I05Xhs+4Cc8W0REBLVHgMKXdP5AFTKnpmCDrzsFVewWQV/CW9h5lq7GHhthYRS+BhHN36j/IGxAZg7ziBRq4KE1ChqV9Yt8WmSFj3P53zEtrojB8vUu0WxOYcrPYdw3lYq2M6Ae/AmliQFwWYIHRrcudEVoPBUPw7e7PWCwovmvdLwpdeSx5kTLDZUUakku8DO4PyOtQ1ZjEb4S/LdYof9ZkWnHrjTSgBfB3628DwZ7ccF4E3XMND4dbubn41PE2M5s6ph8bAcyWAOsZ4ENKzybpk6cIIfNs5YO+C8QzLIthOZwtEokj+TzUTZ5XlYNOV+qL/G0ppmfibr5eqGhacJ 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); }