From patchwork Fri Jun 28 09:05:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13715778 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 1C6E4C30659 for ; Fri, 28 Jun 2024 09:05:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3E0A6B009C; Fri, 28 Jun 2024 05:05:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ED276B009E; Fri, 28 Jun 2024 05:05:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 866276B009F; Fri, 28 Jun 2024 05:05:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 654866B009C for ; Fri, 28 Jun 2024 05:05:46 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E9C21818A7 for ; Fri, 28 Jun 2024 09:05:45 +0000 (UTC) X-FDA: 82279714650.13.5244D5D Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf18.hostedemail.com (Postfix) with ESMTP id 1E35F1C0006 for ; Fri, 28 Jun 2024 09:05:42 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=X6f9GSKl; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.172 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=1719565519; 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=hKHUYTJ6piWqvwE9eLct8z5nJKSMkThG8RmMW+OHxwGFDAERLRcebbhLsraRKq25rL/Ych HY3qgAWKSiEL6nmUcUsf+qQd5asqXKKkAppEEwdwUca5V1W7K5kjSoXOYWPPd/pvJv/6ZV YPCdZb5w17PPpwvqKqFJ+SnmAEg2r3Q= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=X6f9GSKl; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.172 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=1719565519; a=rsa-sha256; cv=none; b=S8/rpFH4xrNbdwvkvlek813jt2Ml9QV9xMojB4e+6lfGYdoBAGhIJepc3su2cP0xIQwAmd d+XnEKhQ6yY6JF7+tjACXY9rnI16yAj8NlqNDFU6hGdv871+QBkt+AN/L3iptOCWrfT2Hp 2FNw2zRYD7mchrrT+LzgrTtbOFbu9Pk= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1f9a78c6c5dso2160305ad.1 for ; Fri, 28 Jun 2024 02:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719565542; x=1720170342; 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=X6f9GSKl2u6fZ8R0VIiXynI1nFuP11aULr91XmRktJBzObePMQenQw4PfKZgoBDzM1 TGfV8Uf16XvJlEXhCdEHxoRpo4ResbP9E8Bs3XeMKLnTjGWJ9vPl20YcclSwKufkJt9f vr663fsWFuW7uMp54bDgpnDUTmqOXHzJA03Lb2wokV8RLa2iFdFAVNZIKtCuJrarXVep EZqM2vHd0e9x+Hs0wNA0V+R7pwwc2T2r7uWePNtPv7RUJvSfcZqZtQwtSj61zSr7L45L sWnSCX35AC2HnSQW/bte+B00RPGTVR8Oky4te0OwiBJr7yozruRv8NBN7B01E9BJPmEh e6ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719565542; x=1720170342; 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=QF4VfBPuiBzrw+fblFDyJnkU3rKM9KWk5kTcozM590VavGFlMCZA361FrzHSQVjJw+ gFD8Bsup5R1oa4shR/vh2xvjqz1Ds9zUb+PPHurbQWw9Rw0xv5uYh0DQHCe/5SzVijo7 jH8SjsaS5vx3n6OXGv1lBDMwnIrpdDjEBUQg5xtUhb3sBgdOpFtvLssOYMdka1tejOfR Xbd2u/B+zNtoDJUwB+TUbjS2dgw4Zy7YmVmwdthwTSuCGU11uGgb4lJ1+ggqm1NKoZNZ edGPHuLpWlN7gq0Ktw0TQqp2YlCk+akPqE1HHUXq8XJ5HSEZhgkx3mwUmHWPPCCfGmq8 pxxA== X-Forwarded-Encrypted: i=1; AJvYcCWB+QvxbfdrxXhOJ2umHgHYb4wtQSmROA6Pqw2NdcAkofbiNLHdQTGpgk6W3DbFzp85nlBwqtc3YAIvKPRXfBFU/4M= X-Gm-Message-State: AOJu0Yw3rGw37ATDzfz0TkV1p/rYJtEXJ52wfVN9AxbqSI4fTNjkaThQ b9O7Sz0VPMBb5QhUrbJG9mJRIQLfvWnY3JdU2I6R1XdoNpNG1FAv X-Google-Smtp-Source: AGHT+IEiCe46L4L+6u8pFkskIn0tSNW3yZf9XlVCW3W2rC8VIHwBiWsCsriXmS70kmQMnPpYjn9ORg== X-Received: by 2002:a17:902:a3cd:b0:1fa:a34e:8819 with SMTP id d9443c01a7336-1faa34e8cb9mr39730485ad.60.1719565541990; Fri, 28 Jun 2024 02:05:41 -0700 (PDT) Received: from localhost.localdomain ([39.144.106.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac10e3a1dsm10473085ad.68.2024.06.28.02.05.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jun 2024 02:05:41 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org, laoar.shao@gmail.com Cc: akpm@linux-foundation.org, alexei.starovoitov@gmail.com, audit@vger.kernel.org, bpf@vger.kernel.org, catalin.marinas@arm.com, dri-devel@lists.freedesktop.org, ebiederm@xmission.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, penguin-kernel@i-love.sakura.ne.jp, rostedt@goodmis.org, selinux@vger.kernel.org, Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Ondrej Mosnacek Subject: [PATCH v4 03/11] security: Replace memcpy() with __get_task_comm() Date: Fri, 28 Jun 2024 17:05:09 +0800 Message-Id: <20240628090517.17994-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240628090517.17994-1-laoar.shao@gmail.com> References: <20240628085750.17367-1-laoar.shao@gmail.com> <20240628090517.17994-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1E35F1C0006 X-Stat-Signature: fm88jexns9u4unezr9yqhzrdsfpdnce6 X-Rspam-User: X-HE-Tag: 1719565542-296551 X-HE-Meta: U2FsdGVkX1/mZcxfrZdPhM6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eilEPPq1exd9VL1bFPkwF6A+CdqFDuKFcES6x5hchb33hLyco9Gmcc3CmFIh2X9fS+ILsJO2W2RsFIpRR6fa5tCsO3adQpfEu1fGysq+3mCBHZV087Z6JzXgFij2AXmwGNRKYv0k8BRhpuTb19lV6YAi4kS5YQ1zrULotoC0jIbo8N+++wa7Uk/o6MVqb581Eufdf07i8dg8hq6J7G8kIVqpBLDh5d68/7YYW+x4fP2cJIfgMYSc84nbd7XcSVPxbtVrJX3SE9b4M/jhlk5wXxSno+16MVWVzrcIBAJQl9CPPp9MfFiyhIezeiacVClccphTn0C1aPAFP0gCDaxFJawHbKuxU02feNNmP0zb8ffawiJ383ySYjkLujguhxxdBr/PaKuUgTt0lTjVzWjWPBrKka1kVQ3P6wTcjX1qEo1MosFjlDabpC71xiGCPIHGU5m9vF0Y0w/Nu5VRj5a7dnT/p81SM2jdskZ/oA8aougZtf9ZnjjsVPcm54VRUGSKE4hXs6inVzkMjn6m6jH/Mb2gtqCkKrTfcoBArA1Jippv613yXQyUvH9oQw8WWnimZx0JnzLBTbStUmUa13kVYkCGvjQlU1vN7E3eUIuDhV2vZIGccCwLT8Ng1Ze+lZrKABW9oofTiSjxp915vyMij6mnCaYqs/iQzwJ2sUX3yZVbxisbiA1MyxZyWm9LiEOVBhnm6A3rZ3f1imf1fRNeECxpMB+zmO/CIG++wUfY= 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); }