From patchwork Mon Aug 12 02:29:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13760071 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 07586C52D7C for ; Mon, 12 Aug 2024 02:31:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 914776B00A7; Sun, 11 Aug 2024 22:31:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C4566B00A8; Sun, 11 Aug 2024 22:31:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 717E66B00A9; Sun, 11 Aug 2024 22:31:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4D6746B00A7 for ; Sun, 11 Aug 2024 22:31:22 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EFEC51A06FE for ; Mon, 12 Aug 2024 02:31:21 +0000 (UTC) X-FDA: 82442016762.05.183695A Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf18.hostedemail.com (Postfix) with ESMTP id 21C971C000B for ; Mon, 12 Aug 2024 02:31:18 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LeBGyDP8; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.178 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=1723429809; 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=qdEfItmwefU07w76SDkXtsO/LaxPCVZAR+StHmo8iTc=; b=0iKw23KWXPvjaYADxCQWjth1270DUWVf86QoURQARTH6RwfyAK+QWrSpP9U5VAmNEensHV UlStYvo8p6GxDv0BK47wzcJxU1uMcfCnJLHNCPf7V2bRfIISYycG6JBG10eqQeIIes3O9Q 6iBqUOYIVkanl5rifXZ5AaVp9B+D9+g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723429809; a=rsa-sha256; cv=none; b=VfRnhblCA//jMvwcNUHE1vcA39SDYyu3MK0qWlBHBbPCniHdf9kPnrmzKnEUi/wR8VjbPG IiTBfgctCxpYhXw67aAKooeO2iTwpKWQS63lnQrAVa7CxWASz30zG5CB4qKSMGqJA9lyXK 9IMx6r+ZSCVooYhTpOK+frkBR/2YurE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LeBGyDP8; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1ff67158052so23753615ad.0 for ; Sun, 11 Aug 2024 19:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723429878; x=1724034678; 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=qdEfItmwefU07w76SDkXtsO/LaxPCVZAR+StHmo8iTc=; b=LeBGyDP8wnyxtC0RWqBmCDnhPd3f61hWoPX+sWFttXZ2QH4v/MvPBX8cN/zCrePlXt 3vm/It0kMd8zGXlhci238m3lncNnMxbCndvNM5FPLbk6BGnvyAXNrrJsipC8trpYG6n9 p3d3qB2fQWm0PE1WvArpxJlnjQJDbtN066n7+DRrD0Vmuq0G3BkJiOlHd01k8BkcpzQc Ee4D/dNNqnqGZM8Lqm2ujSL4wSeE/gdCgJ5wSV9rkkdzv+FoybApBFIkbdOTI0tE5oj5 9cajW7jj62moCWhZWTMPw0Li28wmI2zq+XXmsahVkA5jQQ/x9Pbb9WQIP8d/OVl7Twps jpFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723429878; x=1724034678; 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=qdEfItmwefU07w76SDkXtsO/LaxPCVZAR+StHmo8iTc=; b=DfqORa0l7BJChXtRuy1DMn3HmLYzeM09XJ9Wu/pC6mt6WQdU1+k6WV2IC+lSinFFHx luB372l3AMX+jH+uHVtqAtgkH6X6Yqh7gbFps1msFc9lkyGj7uliPGDBFCxHeKmk5SFC iwfKzINmDVL52MOd2JDxXZEgSseH+0ONqMQ/ETbOHAcm3B+nkkBoUHg7+UaoYczjyMVE AQYhR6k9qnuIV5NY4XmtweFKQs0oon1Js9LOg+tOm4UGgN/wi4UQswH5ThJR+XsVmMf5 nhrn758o6ws5Vk0/DsNYB+dML71Gzds5oSTFEg2R0cS/KvD4mM77liT/B8raX13M0VOx whSA== X-Forwarded-Encrypted: i=1; AJvYcCUPu+3uzzHy6ssPZAcG7uQO3LbA1GhI2JvgCR0SNJ1KyTYt1bpFV6/xiqQ35uzbEM14DZhg6U+a0S1aDa8BL3FHXCU= X-Gm-Message-State: AOJu0YypDyCixcv9UNMAf2Ycpv5uhVZCj2hfO/VgARvYjtLO4fcISl+o G3qAipBeJXxQjgyCBUWdZu7L0+UwslcAzjcBFiWseEAttmsCKDGE X-Google-Smtp-Source: AGHT+IGvMeJ1WDvZRyKICOlWBdf489ybDgp4ZGppLiFztYYS3nDRhT+W8sx80+j2UnrjElUuwI0I0g== X-Received: by 2002:a17:902:e804:b0:1fc:57b7:995c with SMTP id d9443c01a7336-200ae4dba44mr56315805ad.7.1723429877770; Sun, 11 Aug 2024 19:31:17 -0700 (PDT) Received: from localhost.localdomain ([39.144.39.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-200bb9fed69sm27884765ad.188.2024.08.11.19.31.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Aug 2024 19:31:17 -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 v6 7/9] tracing: Replace strncpy() with strscpy() Date: Mon, 12 Aug 2024 10:29:31 +0800 Message-Id: <20240812022933.69850-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240812022933.69850-1-laoar.shao@gmail.com> References: <20240812022933.69850-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: jw3uacf6xmbeh5oi9rxour9zstebnz9y X-Rspamd-Queue-Id: 21C971C000B X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723429878-931416 X-HE-Meta: U2FsdGVkX19UmIDN3i/yMmH9HAcNlA8ixP9BLL0z67RVKQVjjS07igXT+NYA0xCDBGhj+fd9yTxUBivoJLGStOHl+2qBOB1lWuatT0x6K59pwmxLuIhPsnfvz4OuBk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9y8BEKwU3VTZjOyTJji775nFgVxnUP7PhbQAxRY9Vuz0aSwtHth9SCy6Z9IPe3ehyLcXuqAz8/UL1xzgCynxkQGcphJqlMMbPhSvjUcWoqIm3X5Eekpm0CJeS0UVKRwEMBRWCa1nE0DMvsThPFtlCDfevG+7lAMyXto3vIGE1mK4oyUSSXWXgvwVlpN6/IWzQ0sE594vZi1q2CSHeUUX8ZjccQoU1lMdS7KEq94yPNYVnKaU/DgLhBRiPCiJBE3a/at6T+YCZrlM2bK8Dx210WAbC7Rwprz6yjjSDJQczI7wipz7wV6Cxc5ydO7s8bMoQ1oYFr9cIRn4Qb+2/xvpdbyKSKKibvwl5RcSBFJGLqkfkkSWVChYMziwHu7zYLfQJt/RBOVzv3ETDHrpJLCiLBnyclFiny3B6G3GqZr4deGfpn 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 strscpy() 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 578a49ff5c32..1b2577f9d734 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); + strscpy(max_data->comm, tsk->comm, TASK_COMM_LEN); 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..4cd24c25ce05 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); + strscpy(comm, task->comm, TASK_COMM_LEN); } static void hist_elt_data_free(struct hist_elt_data *elt_data)