From patchwork Wed Aug 28 03:03:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13780363 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 2EEA7C54749 for ; Wed, 28 Aug 2024 03:04:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3F4D6B008C; Tue, 27 Aug 2024 23:04:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEF446B0092; Tue, 27 Aug 2024 23:04:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96AF26B0093; Tue, 27 Aug 2024 23:04:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 770296B008C for ; Tue, 27 Aug 2024 23:04:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 223BEA1C6A for ; Wed, 28 Aug 2024 03:04:04 +0000 (UTC) X-FDA: 82500160008.22.EA549E1 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf13.hostedemail.com (Postfix) with ESMTP id 48CEB20008 for ; Wed, 28 Aug 2024 03:04:01 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KxmUC5Dn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724814221; a=rsa-sha256; cv=none; b=ba75/U7XUGqhKQkArjqsXauka7mjDh9E+rbCjT8l2nYcw22TkWhzVjV89c8VfbNTAV39cr i9ldFUKKEIpzyO1Hgz0F2YH1CG67zUqvC4xMD5TjPYq9gmucgW5UVxX3XJGLgc3OxL3uvI OtDY7XGD+u3/JJ8z475i905ePjOkoOM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KxmUC5Dn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724814221; 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=mIIMsSPqVp5AusgTbRbdrgF3qEr8ccJBENe3BbQ0UBw=; b=eqVZbm0xWLEe3RDkJSmdHA8I3WIsCx2GF8exyOjBWDHCIrzggS/YTYXu568piqk7vo4y+8 lQwxs4aWKWsjVcXPMpH0CwroEWPDNl90nzyD3f4jwzWILC2cJ+xNo+sabjtWE0Z0Y2XA9a 9i6x4GuSsSr2pdpLEIxrpU188GeSEQs= Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7c6b4222fe3so3832188a12.3 for ; Tue, 27 Aug 2024 20:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724814240; x=1725419040; 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=mIIMsSPqVp5AusgTbRbdrgF3qEr8ccJBENe3BbQ0UBw=; b=KxmUC5Dn4MqF8EYaOUfL/dnJfsUlz8bphkdGBmsguUKfbowe0R1992gy/kxBEFAXwk CzA5fsRhrKuDWqumdnh2U3bL3X56cmHaZLqntVijaacRWG4cYgWdqLj76lRDdd518Dh7 P7BSfQBDYKOK/re1qJkkjeAlffiWbqiVmDIKDXlC8B5BPtLBRe2AcpxS15fpYqTveExu 4W2Z2Lm+qilwJ55CNJVHzkpd3gAOsIVSiIwBLg3C3cHf03Hu4WL794HmYpu4nBkKYVwv EvHU29BZZe/rNTOEoIQop4SFJTuEDisXRBowViqgGKTJ97v14VfQKVeD3+E/dmy+Luc2 IAkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724814240; x=1725419040; 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=mIIMsSPqVp5AusgTbRbdrgF3qEr8ccJBENe3BbQ0UBw=; b=M/rGSA89ZVydBs13r5j/lCyD2LY2GUfPh2dH9kbK5Dk6oDV44+xUZWJ74VHFQByJPO F+V0hXUaWwO2S26NQKqdkXBigovWHxkSs7NQfAyOLqEOtmuAMujzFhMixJuCLJ9soNcy zRQ9tOzQBwBZdiLH6ObqNG/SECmC4WZU1SDAziBGg8+bKvWOOFnfvlzgnC486xrOSFyP Dwr7q8u++EGwyyyh0XqFHjJKH4JdHKnmhaDNfxbY0hU52AEvkZ6oy9CF6stw/9XB4I6E hFhTfQDrbnKejMCDjhZlVwOlIkLdgUmjSm/mSI2B7UIZdz0zVP0h7K5T/XI4hrLVB729 bYjQ== X-Forwarded-Encrypted: i=1; AJvYcCWvf9VKKjm7yB6mZG7C3ORM01zWTkO+fPG/0tHClZ6Uu3ouE6sd8QXv61P0sbmaivG7ncqASx345w==@kvack.org X-Gm-Message-State: AOJu0YymVaF6EeozuclhPZljk9xbXUF1Z7bEdnPAmfCdrgsA3qFUx7KZ xChu0GU77qFCbsiYDQOK1rVOdDB1ra97CxpLYcyLqvzJ2/75P2wt X-Google-Smtp-Source: AGHT+IFERm607QheW54BofDpcXniBv+8JM5KHrTSMUx7woXR1463qkdvSKbT6nvldL/lDZfqmA0dvg== X-Received: by 2002:a05:6a20:43a5:b0:1c4:c7ae:ecea with SMTP id adf61e73a8af0-1ccd286f499mr543329637.11.1724814239886; Tue, 27 Aug 2024 20:03:59 -0700 (PDT) Received: from localhost.localdomain ([39.144.104.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d8445db8f6sm317977a91.1.2024.08.27.20.03.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Aug 2024 20:03:59 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, alx@kernel.org, justinstitt@google.com, 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 v8 3/8] security: Replace memcpy() with get_task_comm() Date: Wed, 28 Aug 2024 11:03:16 +0800 Message-Id: <20240828030321.20688-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240828030321.20688-1-laoar.shao@gmail.com> References: <20240828030321.20688-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 48CEB20008 X-Rspamd-Server: rspam01 X-Stat-Signature: tmm7pejs51jt119r7wqy89anfogkn7ne X-HE-Tag: 1724814241-31900 X-HE-Meta: U2FsdGVkX1+vaEGdMP4v11ESr2gsBNWu3e/cVDRvq8K/P4An9X11tQwgoSM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qyFQCvZgMIrjnnkGIE4l/X0/+FYw4+2xRxfWoRpCLS+2qkS8gZQpBUIvN3ZjPIwgDubcpbrRf7C329P5dRM7fngQmVX23OIk3y7ISvKfaDyS83Vp4H8KMdE/NvR2qRI/o0eU6WlnKmvK+XFbwmOxvVk/mvXRLgxYaGgwynclpDKnyblT9DlHVFPoBS6P/deOX0NSs5xTBWolMMjfOKArNVAA0IqqmwHki/cG7u6Txy7CbM4VoQ2WEuDpcqPfi7ltZaYRj/YZuRJVVsAdEZJMCnxkhky883bFrfsVudaLM5Z5oYI8+VZZxWwkOpQyxcMffTh2M4DVu7LhU5rSD+QzDVsFpDWU8Wwr4Tk1UEU3PI8B4M6LfWZINel2/TAvJe0A47JmTAlIDD57TrXLll63IWvV+6GZzrEoLru16jIZtGnALbDgVdDMGhoAn8HiphQ9f6yhGOmXgTZmGmrjaEcWEEUxF3IT6P27QWsfB+rhovbS8Hx2z9qQHG+vn/snclDHAorQwyGJrFiBhWCi5BVUd4tvhQEAOGQGqNUYMjRlXZJWDlN6qGvNRvgMbFCqrgqnSSZsnabdj0lteQVz74dg8fl5+le1BDtosO7NaMoo2KbmLwPAwtjG4FUfr7E6VvcPsgYx/1aWWWSaCPhccFmSpYTBeKmem8E6QuwGoG5P1Dv7Q77yWMyVJgYbdHT6hqr/htjGVwsmcZMNDytxbNjOyXpBK1B4Mc/RpmY= 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..9a8352972086 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, 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, tsk)); } } break; diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index e172f182b65c..c9b05be27ddb 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)); + strscpy(comm, current->comm); pr_err("SELinux: %s (%d) set checkreqprot to 1. This is no longer supported.\n", comm, current->pid); }