From patchwork Sun Aug 4 07:56:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13752530 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 45269C3DA7F for ; Sun, 4 Aug 2024 07:58:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6C2C6B007B; Sun, 4 Aug 2024 03:58:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1C6B6B0082; Sun, 4 Aug 2024 03:58:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE4E96B009B; Sun, 4 Aug 2024 03:58:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A13F36B007B for ; Sun, 4 Aug 2024 03:58:39 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 379BE417FD for ; Sun, 4 Aug 2024 07:58:39 +0000 (UTC) X-FDA: 82413811158.24.D8CB360 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) by imf20.hostedemail.com (Postfix) with ESMTP id 67D341C0006 for ; Sun, 4 Aug 2024 07:58:37 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="U6gL/zyq"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.171 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722758310; a=rsa-sha256; cv=none; b=AXaS1vu2OCnptGmBg0fi3nDkIHSsBMLvZbDd3bAZ3OwAUKCGMTrbcdYWG62Vn1KEW96F10 eVjCpC8UQFdrVKc57GiX4BaCORZbcHOsHWcInaB2w29t8zluJpZjfBJmRCt+UCRMR/o+p6 tt3YRpBuSMYrnbApazY5TDUVRYB8WuI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="U6gL/zyq"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.171 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=1722758310; 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=hHFsexRAvS3+Twdq3ZGpnUTD4jZRkYjFMffxIhD4B7E=; b=SbpFW50Gb1jZmGEilrvaB9lGVmgrAH+x4ArLyH+ZJJKkALJjGwBxHOS9r/MGnejSirZSy/ oOByRHKWGWlz+hrUU0wUHIj3GHCUE500071wlJNyEo609CP13gmfXWpV/1SSfl083y10Sg GFmKqK7LwV9zBVfkivOCrSt+ygDDSu8= Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3db2315d7ceso5601711b6e.1 for ; Sun, 04 Aug 2024 00:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722758316; x=1723363116; 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=hHFsexRAvS3+Twdq3ZGpnUTD4jZRkYjFMffxIhD4B7E=; b=U6gL/zyqChBa9+LUSmX+Kpjze3d4WCaT9MmnCgyMlJvebfqsPHFSuJGwRzrGKHHutf CYFD9uxbozHSjlxg8gQCc7zc5xGe8sqiNEEZTdSyel8NEErEugQYv+nUlNeULqtGMpLS +f5VGXtxx+ZaZHTPWDaXe1wGzJ9MGrMHrGXopsAlqUXsUwcFW83w+d0JUBPOjRC5A3Lb MYy6eUm1i0tBlHnyYPUmX7V23qWxlOsYe/HF/wwdQ0RLJLEzjh0uKZRHQIDOL07hkFKx PI2WO7cOVW1c+bGOJ4EeD/AEACAXnOhhQzOqURKWo7yhu7nVnrQnt3ZC/MNtOP3ZpMnm LC3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722758316; x=1723363116; 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=hHFsexRAvS3+Twdq3ZGpnUTD4jZRkYjFMffxIhD4B7E=; b=t+a70MahEzD3XWCs6DGrZDNQ6lQ1DAMtKe7qEvnB3c+JrnJ11vcinNuLOnmWebJozJ t5XNkqOvDRt+cOXmqAs4aXvtCxjwj1/f5VVvVeVd54BQmMFfkmggb3ATO6q+WqDEIOF1 MBTY9eR1dc97I5iHjWlgGZj5JqSb42aE2cBl7ObJG/akhqbTh34wyy+Y8yutZfAMxblw 8Us2Wi2MXgJMTaqP67aAwxL9x+h2bKvW3/TCsZeHTDgHjv+nRybGVq1aTQKcSmmVuVd1 zhhdfU33EzLkYrgpmqwfktGDpFEMQN6rsygLzd5gTO2BihHNu2SGCR1VnMOyU01WcBKd +new== X-Forwarded-Encrypted: i=1; AJvYcCWsDNGXXFfZhbQTIYYA7R58FRXiPvjpCF/o0+BQm3m6+i5a9RoIE9wUA5jKkiIHDXVNlMdvd4x4m8bCotvkr7kHCxs= X-Gm-Message-State: AOJu0YyNeNgz73elDLauWXHrna8Umd0ksAY8tBtfdiNKzi/cWNioTZ+p aoe4BttNXJMVvr/Aq7TYmJgp2jA1zR9JPeZcIwToJwJX2F8DevSG X-Google-Smtp-Source: AGHT+IEQdsxKAJTw4i+uNNPkbgE3NiIW5Ir2yWohAneqMp4vDkArZBqW84U9DpBffvNg6sRs26e7Fw== X-Received: by 2002:a05:6808:212a:b0:3d9:2562:7541 with SMTP id 5614622812f47-3db5580f273mr11989986b6e.24.1722758316365; Sun, 04 Aug 2024 00:58:36 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.172]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59178248sm46387605ad.202.2024.08.04.00.58.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Aug 2024 00:58:35 -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 , Masami Hiramatsu , Mathieu Desnoyers Subject: [PATCH v5 7/9] tracing: Replace strncpy() with __get_task_comm() Date: Sun, 4 Aug 2024 15:56:17 +0800 Message-Id: <20240804075619.20804-8-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-Rspam-User: X-Rspamd-Queue-Id: 67D341C0006 X-Rspamd-Server: rspam01 X-Stat-Signature: u7cpb9eqfzuq7sg7y7tq5ar3yhrku3w9 X-HE-Tag: 1722758317-522491 X-HE-Meta: U2FsdGVkX1/yvY4/ojeNBg/vmIId8Z0Oge+xleIdVNV/2hCx4xVX8yIwtYPZe224Y5G7PzxfLkRE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BFp8LIRM1Fgaor+vo0kjU32/lNkBHPOVvWET90tL2DjQuHP65YOgmHSJ739KcdFIzaUprnE4X/UVsyEYwwNUSjzoZZsum/q+u1gy1Ko0vaSqF6mIYHraNsuAcTM0+Q9dhfcr3r6ZShqApb0a7BHOMOThbBFPmWJ+BT26o5dakKLr0Em7uJiwnpPggso3bB06OM+ST5fDcoS6Is9iqEqa9Aq4ilD4hmg9B9FWsi5cpDG9LJ0dwA7YxJfypoIwmCP3hejQTjCbCR7+PfwoV4INk01Iig6T5TA0ugznd5wbEIjfguLxZ5ulgAM6ZTzhaMn2RgDmdxh4QIRW58WT3BN5a+6au9lEW1/5UmdI0kE8j2bvj85qtzOcq4O1FIEnOnUJ+jIj634Qm7k9pz1TEVED0r2HgLmhKcaMQtr6D+8lnH0Gj8ChUXJ+W+HDfaCNzds5JwaOyPLBhkWsL5t/SWTXaKEru9PfOl0FRMatDsYrFA0gfm8Ptj6MDF7AREl1dWzfkOAkhU= 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: 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 Acked-by: Masami Hiramatsu (Google) Cc: Steven Rostedt Cc: Mathieu Desnoyers --- kernel/trace/trace.c | 2 +- kernel/trace/trace_events_hist.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 10cd38bce2f1..985d2bf2bbc5 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1907,7 +1907,7 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) max_data->critical_start = data->critical_start; max_data->critical_end = data->critical_end; - strncpy(max_data->comm, tsk->comm, TASK_COMM_LEN); + __get_task_comm(max_data->comm, TASK_COMM_LEN, tsk); max_data->pid = tsk->pid; /* * If tsk == current, then use current_uid(), as that does not use diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 6ece1308d36a..721d4758a79f 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -1599,7 +1599,7 @@ static inline void save_comm(char *comm, struct task_struct *task) return; } - strncpy(comm, task->comm, TASK_COMM_LEN); + __get_task_comm(comm, TASK_COMM_LEN, task); } static void hist_elt_data_free(struct hist_elt_data *elt_data)