From patchwork Fri Jun 21 02:29:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706756 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 C71B2C2BBCA for ; Fri, 21 Jun 2024 02:32:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BA026B019A; Thu, 20 Jun 2024 22:32:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 331556B0446; Thu, 20 Jun 2024 22:32:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 135FC6B0448; Thu, 20 Jun 2024 22:32:29 -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 E30356B0446 for ; Thu, 20 Jun 2024 22:32:28 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8AD33A076C for ; Fri, 21 Jun 2024 02:32:28 +0000 (UTC) X-FDA: 82253321976.19.4641D75 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf09.hostedemail.com (Postfix) with ESMTP id B849014000D for ; Fri, 21 Jun 2024 02:32:26 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GiUuIhQ9; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.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=1718937141; a=rsa-sha256; cv=none; b=8o/jDlZOUg1aY0ogMRHKZYJfQdtyoB3Xm3fUboQHooCx1kgfhBcXibsfPCqSxiJ8XNYagT ZohmeFMfFkrREieyMgrioo4bT2Z+A3e6lpKAAims6OVIlb9MfA4qgndwpRFkFpXAnoJH3Z 0Db3GyLctji6aaKGbldx9cgv11tKLiA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GiUuIhQ9; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.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=1718937141; 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=HQT31JSkonb7Xmqn+k1uqrjgngeoHr6IFKrX/+KN6Ok=; b=pPogLx2keZj1I2Cj1ySvQz1bLDwzkk6X4fKMw8q5/dAXCnjvG7F5BlOi55gXAnuqhjbgiT Wk6zkxADzKXaJsGEv8s29HiDNhldqxd1VYji443O7ymYLGdBxKRpIV6b4WvI0lyeH0ZxvI 4E65Iu2JYXlkhQF0fESvMTJUykHU0ok= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7062c0ee254so1351113b3a.0 for ; Thu, 20 Jun 2024 19:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937145; x=1719541945; 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=HQT31JSkonb7Xmqn+k1uqrjgngeoHr6IFKrX/+KN6Ok=; b=GiUuIhQ9d2Nv840iJwHBkyL81yDITagKBrh6n362NEO5vbizTgSxrFWs0+XPUBV+VD 3PsjWCqF03ru4aaSCAYOAupEa+172nsKZqsuQHhmKDAa37g77b0XAXxCFLiDNwgUsBlH 1nHnMpFgmRy6V5TuKDcSSFZOHzojsFl7PluQcWHnMLhRB6wG7Zkc+1wrcBiK7yzz326K 9qQD5ao/2z3zvOQqitCh3EJIAcxZ302JfYRsN+qnWsli+YP0pdwUC0WUJh3UL9ife7Be SWN3EVSQLCBxA7WtUFHRHpbpNf3KzGcmYwJREtMirJtRztp6IyoNExZbOvvdm1+eOmQo MD5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937145; x=1719541945; 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=HQT31JSkonb7Xmqn+k1uqrjgngeoHr6IFKrX/+KN6Ok=; b=Z2OAzJWn24w50+RiaRih45ZI8FygAxED2rS3f8R3YkeFSUx3M0YS2IjO3CtgzWcLDf I5+pOIWvCnKZoT9rGIvbGeMdYSS7FGPnl/mjlzf8C/TX0IHoiS1vTN1/T9m0P0n4eEVy DguZ4bd+mrpd2cpy1dP5vRe+y9Xw5tnyMJzBZ8euiybeoHS0yZIvF4Qw/EkbM2UE/vLT BFmWElah6UyMDoxKz+KpfbUpt6ElX+dnAoPt+bBkiYrK1zufGEZP/gZKxR4ZPSvVEGub 2kkJQxv/PRxI2x/ZtpEAQxGXBireGW+LMe0fnjblylWhL3a6pTbXcudcRFxbgMScq5kW scvg== X-Forwarded-Encrypted: i=1; AJvYcCVQxvHW5y6x+CXeB3GJoSMMpg9D7o+vHEgfiV4dJrsk3LdoGhs1iZEmwnrcE649R/jMiBAw4IZI75V6wL6LTG1hAWs= X-Gm-Message-State: AOJu0Yywx2oIDZCwlPOP+G1WL2zx1HNpvnvWcaR+Q0YUlWvlsUfvK4CN eXLtp/Y/Mmx09OIykU7ZJpDIHnmcPK461zIc/rPDBcw8hzwCossV X-Google-Smtp-Source: AGHT+IGhhQvd2U/sH2KdV0ZtBjJthL8CznXxKI/3OBzCZg9mpyXqgc1aLbbwbnNImYe317PDiBUknw== X-Received: by 2002:aa7:8b0f:0:b0:705:d9e3:6179 with SMTP id d2e1a72fcca58-7062bf98e16mr5991736b3a.26.1718937132481; Thu, 20 Jun 2024 19:32:12 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.32.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:32:11 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 09/11] tracing: Replace strncpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:57 +0800 Message-Id: <20240621022959.9124-10-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: f16ky7c8xgmahxfapyicen791gjir5o7 X-Rspamd-Queue-Id: B849014000D X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718937146-803795 X-HE-Meta: U2FsdGVkX19+sRR9A9jlmnXWTvQ4PZstRSdWlX34xmIKWalOEAXu8mWThKdJpBYvxCPY23UKr0d58eNfswVRySazvFBL5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qEhOQt/CwzhfpdUZ97jU2BrZRojMd/zajoAC8d0a5HB/r8aXF8AFpswzi/gubEuCFSCX5z8tS4ByTsiTlNuDR+Oz8N6vro+BfGm7NxWAIVzeuE8DUrX153CVw3TEh98SZ6RgA2yJrjMMqz6iArj0jFEVLnpvr/y+b9uf4MJuQpcVtWlYPxFHuz+cMBOVhFXTE0UEbF8uwDuJjC16nnnR4fbEE3uTEb1OmngCLt4cH+hTRoGQFxcIL3yllIjI0qR7HofGIKybiH0YEO81jZb55xminlFhIVDXQsVeni0DBoHyp7ELgVzUgRcdT0fNum3oR9w5Z0M/dJy32cZmie2/DR6hZd3wAKdUf65p+QLC3EIKQb4YsRUYkGRqETLUTW7cQJtIPYewQiK9Z9DbLqZ1e2hTi6fX5/zml8OFL4KRGkemrOOlGfyBfNpAtmnzyCQUL6iD+lb+++RVZVI9Tv0aY+tqezd0uf4tBeZO+SbFByWT9o+56AGUlCxblc= 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 Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Acked-by: Masami Hiramatsu (Google) --- 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 578a49ff5c32..ce94a86154a2 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)