From patchwork Thu Jun 13 02:30:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13695899 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 790FDC27C53 for ; Thu, 13 Jun 2024 02:31:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BB1B6B00A0; Wed, 12 Jun 2024 22:31:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 16B946B00A1; Wed, 12 Jun 2024 22:31:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00BD06B00A2; Wed, 12 Jun 2024 22:31:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D65C36B00A0 for ; Wed, 12 Jun 2024 22:31:29 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 979A0120437 for ; Thu, 13 Jun 2024 02:31:29 +0000 (UTC) X-FDA: 82224289098.11.34918B0 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf16.hostedemail.com (Postfix) with ESMTP id C1B26180004 for ; Thu, 13 Jun 2024 02:31:26 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TLfMV+4c; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.173 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=1718245886; 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=ge2Zl6HCu7b033/pICuy9Z/JzsEkNbaeLhgeDOgBPvBFNWEopVZYAKn/IqCEB+GE5wlZ42 b5c9GGmlurRSk4/d2qgqPqk/uoqDNZgx8sjIKTrGGfWpur1wInls9XDKM/4RPDVxwe8Ns8 xHNeRMoZWP8W68sXuSjG8FpTtJ6VWOE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718245886; a=rsa-sha256; cv=none; b=uwHjG2Jo+aqMTH6Vhyyx5E8IPAdgMkqehexp4qFqbEhTg7DPdIhqoFx+nW7yEjYOgKkpsT ro3Z66foIJRF49XCcMMv2PG1shWwkwdYTeQbbl8l1ijPxhGqI6WZTVOQiM3m640d49snJa 26yqleUR4JMq90AdZCFIE9b6k6HLSa4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TLfMV+4c; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f6f1677b26so3884605ad.0 for ; Wed, 12 Jun 2024 19:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718245886; x=1718850686; 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=TLfMV+4cT+VICBk87YLXBnXENPVUQlnetEOwS2vXdMsOz9wVsB4YWOZcjClu56Ynzd VmJIrfpNH+p8AHSHI1UjU2b9bq1XsryECCLIMZloOBCpTyPzmsxaCt8Pyw0jd100lCyK GlrCTAJr65BCXH47YT1eOgIGfErLN4cEzkl7CcTcMmObDFHAJVJtDLyJjnz6QJpoGx3d 210ds4NvI1tB5oEKp07/TDJQGD2fmAdJYdPp6PK+f1EmNYe2vEXjT77BbPK5iyNUtx8z N3ys1E6MyglR5AusXNPd5SEuqGJJTBeBA/2RazpB3crV0kNhrzm8CKooN6HTxhCJ6aj2 G1jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718245886; x=1718850686; 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=SbuQdKJHpC55wFFaI7OFiaPmPXXo+vb4sdBM9yAU3JgvAtNoQ4H9iu06Rgwb1+CzL2 F1tA+RaJfsE54BzBBg2vgMhFzEBP4lC5d+mML1ioOy6rvUEeDgZUKHg4lkYHWHvcjQd4 NnTncBxRMgXRZz4qawbzQGh6WUI1fQKBMrUCOf9fUysPZlFjtHhHrxPtjlM0Vpi47eDh Ej4bcAg8r5aCnIP0UDDesE/IXC3Phjqgdu3nux513iPU6+1sZRzRGURM3FmH3NOmhSKH EHvA0jDhtuCqTSlh+bi4o1QkIkssYVSjX8K0psTpHqSHUnXRJk7dagmcy1dKQEs7KPYN gRuw== X-Forwarded-Encrypted: i=1; AJvYcCXFDaxsJreqod3NbKJ0ihcTUbYRiNjXwtRT6+bOrayXRZaS1lQsf0NqVMnXFUSwIYp4ShLZWMwQkE7fVVHdWhixzBM= X-Gm-Message-State: AOJu0Yzprx9qM6NaHHw6KgzetQzcCilsWbxuhgn7RBs9h4QfvwiWCfiK hZkLo2STU4CktMtjSl0Txmi8o4+tC1aIXOAj27Yje0hI+ExQSSHh X-Google-Smtp-Source: AGHT+IGMO7B1LQEga8czanZyIFvbKD26XnoiSA9hTxuO951zhYSmXnFwAhLQKN8VIXez5ya7Dmvfhw== X-Received: by 2002:a17:903:40d2:b0:1f6:ed6d:7890 with SMTP id d9443c01a7336-1f84e2cc0b3mr21158875ad.16.1718245885659; Wed, 12 Jun 2024 19:31:25 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.92]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855f4d159sm1755695ad.289.2024.06.12.19.31.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2024 19:31:25 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, 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 v2 03/10] security: Replace memcpy() with __get_task_comm() Date: Thu, 13 Jun 2024 10:30:37 +0800 Message-Id: <20240613023044.45873-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240613023044.45873-1-laoar.shao@gmail.com> References: <20240613023044.45873-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: C1B26180004 X-Stat-Signature: w11p1scgshz77o1cia3d7m9jm7jufjsr X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718245886-57829 X-HE-Meta: U2FsdGVkX1+wPHTCVRrmmSV19AZP59603HE4e0HnBXrXiCcn+dxqiPjvmLf5qONn62MT4sYm3clde0ZPOeHBtgHdQf7pt+2rrO9tNhXz0pNbAjTv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WyFJNAEkA/BgCsm/DOpXOyHVrd37mF4i6yFJO/k6NVtMIm+dBkHl0ZnC6tR6EopGCBPxlSB24OrGAgAEHt3lHaEHlFbFT8VWi3jPCzkAIF9cknAZtol2SfYOsZt9dWAsuNnWRLRWuskrWtG/wgJlN3mPzZrjffMX4PbuvFSXxL9wZ4gTjS1UsqXDMfT+i7ln+eR2SDmCs4dYo/Y1kYSPVDj2aUi2XgN+YwHa3HH6Selc/jrqEI1WdmPDkt9MABpl8xMA49aHQh1nHRu0OOHzVb0X/bmO3UPi+PeGBQY1Zif8UhqeNl/YFK4kbxyYpLlnrK2yDtD4ldWCc2pqep5v4XomaP/r3I5tqkwdD1D6JTBGt0bqNDJCwU+jYNAiP0l2fcFw9CadKPOSngNmSyx9zuMnrvSLmESg9TFlv2o2GzH7iHkFwBEKlxuPG4EALoj7DORnwVkjwG1/5rhq72B0tNQvtlpnUnpVrrcc3GCWbGRjlxsn/qY2cdTj31siSfeY7fVDEALymuK7sJJJlUXay7g4VS73xkViqzVGqD9vwD8jNpxjD8 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); }