From patchwork Sun Aug 4 07:56:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13752526 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 A9F50C3DA7F for ; Sun, 4 Aug 2024 07:57:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09A946B008C; Sun, 4 Aug 2024 03:57:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 023746B0092; Sun, 4 Aug 2024 03:57:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE0316B0093; Sun, 4 Aug 2024 03:57:38 -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 C0A186B008C for ; Sun, 4 Aug 2024 03:57:38 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 42896A0D1D for ; Sun, 4 Aug 2024 07:57:38 +0000 (UTC) X-FDA: 82413808596.12.728DBCB Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf18.hostedemail.com (Postfix) with ESMTP id 644A91C0003 for ; Sun, 4 Aug 2024 07:57:36 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ty+gIr8c; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.179 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=1722758226; a=rsa-sha256; cv=none; b=pF+bFnd7Ht4ZjAP1/TvmSkFbuwIBkiXx93hjcjMtCmSIXDyzb4hpZRjuWF8IEmwSGrgNMu xvAI4BdlqtByDw2a7pByZvSPoHS+Us4IADp1stxKbYubrzZs6VesKNDu/ts7/HUyOFrGcW OyVH2qLBJidNLp/su5HSW0z3AHuTmDw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ty+gIr8c; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.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=1722758226; 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=B0KTkwxi3yTBFtdP01Ghiv9wnj3oEVaVdo6Xnw/VoxQ=; b=4G18E1lyXRaqNgN+6Ep6Xwl/0xmC3r0ZDOa9uZnrQp/jETKzQLtwfNJ2Xhk6lOFFtBwgjM wFEtamAmpp7qMSIbH4gM2KAZo7zevEH7idlRdPyjBMaDQBEao6A624TOUOMbuvHNL2Pbps Vkd31R5myTHFPKeKSjNzX8xX8OSjgjg= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1ff4568676eso39992765ad.0 for ; Sun, 04 Aug 2024 00:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722758255; x=1723363055; 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=B0KTkwxi3yTBFtdP01Ghiv9wnj3oEVaVdo6Xnw/VoxQ=; b=Ty+gIr8cBeVYiQMepJ8Z7nC0NA5l5AzR6jSkWc1w1buk83pTJ32IZj7WmMU82RWZYF 910qjrf0+rBwFCbh1ZsOxY28v/UC5gkcABb5iL91TQxfgyRtP7B2QKoEhfLzjaqlrHwD W8Lhii1CZklbgJSc0iOp/r4+apDpSA8v8ZfXJeOwxdvQROghvwp5fmhhJWk24e5xi9rj 9LdRXE0buQxdAykKj78Y9m0x8HXkfM0lv69MYRm8pZmOBitLPGEf77YsQmSuvteB8uGT 6xKqndjhJTXC/QB6qbrk5VhcKYAgMaJJkH5vBy0ZxKBlkeaWM/h9xuF4wagF7cLMMomm cr4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722758255; x=1723363055; 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=B0KTkwxi3yTBFtdP01Ghiv9wnj3oEVaVdo6Xnw/VoxQ=; b=pYC80lDUxkC+pi4zzNg62nnhlQDW05SNLeGlQZv1Zdd+xIxS67i2nT1c5D8tVMBF3B i6PG0BiJeOGlQStS0PUlQL8qTBmJ8nlviO+HrOZRhAwUbpHH3tO95NPsT5Y+LvMId0d/ AGoQGuLYyCwsPtyl0MzJ+uLgg6uGBy5BJLwGk5t6xg2S8gi2x0W5CXv3YQ7+SpaHtSS0 QUEh4DuGuISCrUNx9zPGleLAVhNHWwjYPFvj6DbOaMer59JcHxfB34RD3VB9QDjfEfYI PO5jVtUkho5KcPFPyEK6Uy6h+CDN0VHB3vOr3IWLxdFY5/RDYgsVUnJO7+9wBf7+vyXn j3UQ== X-Forwarded-Encrypted: i=1; AJvYcCXs6z43YQMVcKG//8HIGXyZBo2IRdgYRio2HNsCF9JiAHq3+ZRC+zCix7sny4iWe+KZXywcandP+v+jSeV23ZlO6oQ= X-Gm-Message-State: AOJu0YxcYz4UCmo429Azqvygzx6UHsPiDthSZmK6tYrdn+rYbywCEOTV QfyqLu9Qa8VU19CBYJLTIa3sg/JWO+CavviD94cWAX5bFHaUFMPE X-Google-Smtp-Source: AGHT+IH6wosRQHFK1XrZrMQ/1/OazY5atARBRVgGVQBt8cXkjOG1KelkDNxLA3xQ6gKV/rMpiZ54sg== X-Received: by 2002:a17:902:aa42:b0:1fd:96e1:7ffe with SMTP id d9443c01a7336-1ff57456f1cmr80659485ad.55.1722758254963; Sun, 04 Aug 2024 00:57:34 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.172]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59178248sm46387605ad.202.2024.08.04.00.57.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Aug 2024 00:57:34 -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 v5 3/9] security: Replace memcpy() with __get_task_comm() Date: Sun, 4 Aug 2024 15:56:13 +0800 Message-Id: <20240804075619.20804-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240804075619.20804-1-laoar.shao@gmail.com> References: <20240804075619.20804-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: knz1fsywnt8b1oqmcqu11srnnopa7w83 X-Rspamd-Queue-Id: 644A91C0003 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722758256-706878 X-HE-Meta: U2FsdGVkX1/Is/910/k0xPj+OJeVaTb3Ur5a0W58s9EVnT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m6HUw5vpIng+e5TJTUqvCdDB4xMWR3yuurB/5lVdfUC2fl5eJ6uemCcG1xiI+T7fN39Npsg+TUGYEPWg0YBpTmDO4/Yk7aUeXcIB8u/9mlNzpedsBoDcMC4PmZr9k/OaE+3fEyZO7F6FyPatjBT1jaESfwwJeoAWHB/tp47FMHEsMHOud3DFze/a5pfihnx6Un4tXiGR1sQkBclCj11X2JJP2dyrwe64mEH8Q18ZcI9DzjmD2PiUj9gKBMsF6AFL8B7JDj1dnhqi2639U+Yo/NToh0bHxLHY5pjcM+/lQISfxHQCYk4jwwvkwH4Glk5XF3WqdFuPJ5ZmvcPBAOgILDdeBkfSh3KvrCaxQQPMe7PR/XLV6ydk6Vqp/lSpfu3cQ96D9IreCJS27MfhQWpMBFgr0rEX85rb8wQJr6dsE9agL7Hse2FAmDwUMTJNc+a+a6tsT5yWXSfGzOShkKE9kHPY6wiBLDl/qRy3Cc3HpK+Ut0MvyF9jsYqk6/Z2y/hvEgA6X/pBulug0ENlsXMYlt2caAXoINx22IQtybbcBLOhpQ6NScvMx4/i+epiGeKcrw7VNTsj+xzKjFRQzNSBjaXSewy1js0LKdY6HDdxIxH1AzAg+jO2m1BMy0g 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); }