From patchwork Mon Jul 29 02:37: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: 13744271 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 CC9CAC3DA49 for ; Mon, 29 Jul 2024 02:47:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 618806B00A5; Sun, 28 Jul 2024 22:47:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C8A66B00A6; Sun, 28 Jul 2024 22:47:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 468C66B00A7; Sun, 28 Jul 2024 22:47: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 27A8F6B00A5 for ; Sun, 28 Jul 2024 22:47:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E2EBC1602A8 for ; Mon, 29 Jul 2024 02:47:21 +0000 (UTC) X-FDA: 82391253882.10.4FD86E9 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf13.hostedemail.com (Postfix) with ESMTP id 1340220005 for ; Mon, 29 Jul 2024 02:47:19 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WsBTTedI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722221236; a=rsa-sha256; cv=none; b=7Dhk9yXUmvuO7AGvLs5w4vB9iyG+MWNcTQY7warYWOXnUbuZG8O1vIkqJTeeX2FecU6lJf 1e1KhrJtKv8gIY521EbTrj9S+jbR9UBJgo/EOMyYy33dwogJy/swZAuvl8wPhcAzmFZmcd 3pLNfQhycxnEzN/O3XRulypP4JbjzRE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WsBTTedI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.47 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=1722221236; 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=/Cv3tjdGG97YCwgOlXgEBsrvlHrrgiTFYRDjMKYVYxc=; b=7WBJYix9HUsif6rDAz2BIMf4Xp2CGbZxNL/xp8GJ25bnXxfIVAx38jN+EG+GaVvjqpdliH d6iVPCCyRQ6IkgD0LlWKRdkDgO9I+OURXLGpuGmfOaT6FTQyxscjggWztcffFrMdPWUDk3 MN9l5UV9smde640x1mUcYbPZ/KNrrUI= Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2cb5243766dso2083991a91.0 for ; Sun, 28 Jul 2024 19:47:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722221239; x=1722826039; 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=/Cv3tjdGG97YCwgOlXgEBsrvlHrrgiTFYRDjMKYVYxc=; b=WsBTTedIjVI4oZQDTKLmn3khL9viE8a+g/r6JAj7k3rXICk8YIi/I0rLATaMEpshaE vuv1MANK0r8vqxpvZQAnBS80j7Nk/0qU27i/MikvOiOAfKa9cVI1JbAd1JAn/teIcvkg VhyLda+IpHqzrF4oaSRbyhRD4EYSv1ex+zK2AtwJynTUCSu9L+VXiuFkdL0z/tC36sYy Yh8IMW8fxmdvr8ngkUr/LS1dD9+gMK6NupwdO/1kMgTtH5c/VrzeVuvrRLMqARtS4Uht cCJOd6M0R6rySy7aVveZlZ0RoZTce4ZEyttxbLh2i63pxQiITR3WtwW8IpIT0bg6JVjx CLxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722221239; x=1722826039; 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=/Cv3tjdGG97YCwgOlXgEBsrvlHrrgiTFYRDjMKYVYxc=; b=Yxbcnad34e1tjfH99R1wcsLicFvTBR484otGn/DmTTWYnjFrRhAdZ4nQcMRcIgSJ/p d07H3fuRJtIyN874qGf0WVsFVlChq/2vwafreSyl/TZ43yhdAHif+y6ShlJayRIc5GNR 2cBIXn7T/NVFArX0jEFvXZNqTR+igGb5puXpyVlqJXF/MWjH1Cbcrd+QX/ONCBwR5Fst c53dytcr8xmvaoLiRgWrVpMtmag4rp9o/pGE4Lo4ZPdc4aqL5RAddsWBmH4ZXe0WRfe/ tiADrlMjtWbfgcN7A0hnmLRL/by+U+4R5HAieQVonENa6/apP498WmObtaPAw3H+JPcB 6Oqw== X-Forwarded-Encrypted: i=1; AJvYcCUQkuxwAWLJPGV1xiya14yMI+ywXJ1n+wGe1gXTYXOEK9k1twPLL1fXZAlXo5o0Hf8vNKxgbnXwGUtdiYRbvp7UrWQ= X-Gm-Message-State: AOJu0YxXNJ1RM6H0n+PJKMoH5biC3akWY4GOYVcqXu+8ld799Y8z4qHQ PL+RTy90e9b2tWN2xAR35EEdHhuflbfDoNvq9nfg7/w3oY0uivkF X-Google-Smtp-Source: AGHT+IFj28K/vh2Wo2JpPTzYf/GZmJskWb9fJ0b0sRrDd73+gDsWQ9AUVDG1zRV3AS7zIGO4lNszYQ== X-Received: by 2002:a17:90b:4ecc:b0:2c9:6d07:18f4 with SMTP id 98e67ed59e1d1-2cf7e71b7b6mr7068182a91.35.1722221238743; Sun, 28 Jul 2024 19:47:18 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.46.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:47:18 -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 v4 09/11] tracing: Replace strncpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:17 +0800 Message-Id: <20240729023719.1933-10-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 1340220005 X-Rspamd-Server: rspam01 X-Stat-Signature: tzaa6zqxnurasrhhd9ytucy8kzpd8by3 X-HE-Tag: 1722221239-733104 X-HE-Meta: U2FsdGVkX18V48RTzE4KnG3JKgmQ3osZCZp29tqjkKfSZhfHjpDKtWLa4r9D9/leR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+4YtHZ992PJf27L4kC+3iTOSVjnLrtaikf0I+b42Dmd8taTWyI0mlWH9xXPKRUtyDhT/55roLMNKbSQhHMsDVH0N5/iBs+s0AKw2vDjbfsByYoe5drozm56UmgqrSfVw3yCI6Y5povF/7IalH+08tSvOtH87Ic9PqXlqDPAEoIsZCbNBUzFh4yPHpVFHeOwU33pgVNBjI/rERAfvspxCuU77J1VrvJUXh9bCM9Ss44D5pHswPHjVHyIJ5kRMSUTuoNeC1lSR4BJ62JxrOpOkX1m95snyD2zhJY1LOMgS1dAoqNlgFoCKD6cXF/wxyyiN2R4vDxlinUL52cuIjmnJg53BjFByIMnhsbmHjS0Gnfmb2b0CbGMv6Nsq7ifdiYMYGTlWaZoX1zOJ1dhGnEpeikKIbg3jLWSUJNScFfefChhovL0Rttz8qsaHBP9hcycH6B5ETPouTV71y4doMWlSDKrz/MP9XaUol8ydWmmCcw6Tv96R7pjgS7wd7bDPUYSsGZSPotSO9AoJ6UGAyN6ZTErU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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 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)