From patchwork Fri Jun 28 09:05:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13715784 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 A7C70C2BBCA for ; Fri, 28 Jun 2024 09:06:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B23B6B00AB; Fri, 28 Jun 2024 05:06:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1627F6B00AC; Fri, 28 Jun 2024 05:06:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 003C46B00AD; Fri, 28 Jun 2024 05:06:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CE6A96B00AB for ; Fri, 28 Jun 2024 05:06:23 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 858D8120A02 for ; Fri, 28 Jun 2024 09:06:23 +0000 (UTC) X-FDA: 82279716246.08.E23BDAD Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf06.hostedemail.com (Postfix) with ESMTP id AF521180006 for ; Fri, 28 Jun 2024 09:06:21 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eXZFNb01; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.173 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=1719565561; 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=c4JKYwN0qh6pTTQkl09ZZEWjQojE49Qnlzn+SAtMpE5KzY5gPiMzSwJU5bLaeinefaOIII MBPfsLnucwpbgHfv/AoeuSfsIIEMhhAtxAYGy+ALXMRiehC+FOw+umOO0Z5ZyTR4Q21z1C iPygKKQQn/3rjaNFOjxlk/7cHBO+lgg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719565561; a=rsa-sha256; cv=none; b=E0NIBE1GwIJXcSY5hzzSBi0C8V9pznJ/SqgO/844Ds1tF8oJqzUBXu7Ao9z+jwZxlTm7E+ 41rtf73nFe3S3VCJ7Aa1MWxFkjJ/L9Ff1pnzgY5Q8vrFqKRaH9N6y5zgzZpT+PhLOqCOgP GaBn2JWlH5n93Az1/K0czLkUlu8ySi4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eXZFNb01; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f480624d10so2276955ad.1 for ; Fri, 28 Jun 2024 02:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719565580; x=1720170380; 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=eXZFNb01aQRyAOq7ObimDtGBqXYJvLCcpMuEafGMJXld0G44eV3ovKG+450HWub2Bb 6e3S4uEq3D6bcxNbphR4mmzor8IvSZMZZ8CwnhkQEaOI1frGjJXyBbhGL8EqFEQVxyrc IK/cS9bwe4cbA0tuXR8djfOg0Ktr/LSeOTkpRjYQ6Z4y6sxTCYpdUspUflacvEShRjaI D1F6H8gFUFTK+WQwIoB6KceeNAN2iAApZHsj7wiDVv0jdqNBHti56BI3V5M98fDwBYVV avzUFmnyRV54+micvAigLzW0VyN/4Comtgp0Ke+PFIeRNJHKoQJU6GvXcVijHGI7rHsQ bWcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719565580; x=1720170380; 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=O3ZI36pNVXAxtA5Mz49HCMhTTgjY9zo63P+/EfS1JoCLbCMSubhNNPutlcTNhW789Y 8zY2e+pU1faH0cnE9Z7eIOTbqPtiYrmkhD8LiBXTuApVP0YU/n7MoIJeBqH1IrkqG5Uj 5BZbEpM+CBkdtkAl42I4hh/F5/PaaaFQa4b80DBRdf+ATPkDzJDdXJa90k2Av4jECTTH gny6wGLPypsM8CTQcwHiuPAnIFuZb1Enkc7KiwtsnQEbw1yyfUR3K+5vtyUDMr+fPj4x tdbhE0jzBdDvG3IlgfObnnBZK8Fh9U9fNd1bXNyPSE1HBALdTmeg/Wc26rjR4v+N6K/3 NCnA== X-Forwarded-Encrypted: i=1; AJvYcCVGhUELPcpZQwYE+eq509SnZxts/N6v/XGmDdOEEflzE/GybKRPP/fPDTtlDhY3Z/0mlmzjiGL1dUcBKO4hhKk4wXY= X-Gm-Message-State: AOJu0YxyHy+P+08kolX6SsYKEMWAN1rFZ0mPRh76DymjZ8gB4MLeKX0b VRb8iG4Jo3yPMRXsFRL+P7wJyXAlus2HkwaFajHuIBQxUuz1m73C X-Google-Smtp-Source: AGHT+IHxho2IY/KPtiPSOQ+4V3CqX1HJNyhpaejcbnnpb1PpTk/59mlf95gQnvz1ll6XSDBM+JJ4SA== X-Received: by 2002:a17:903:1c3:b0:1f9:9cdd:dc76 with SMTP id d9443c01a7336-1fa1d667d19mr200814765ad.47.1719565580537; Fri, 28 Jun 2024 02:06:20 -0700 (PDT) Received: from localhost.localdomain ([39.144.106.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac10e3a1dsm10473085ad.68.2024.06.28.02.06.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jun 2024 02:06:19 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org, laoar.shao@gmail.com Cc: akpm@linux-foundation.org, alexei.starovoitov@gmail.com, audit@vger.kernel.org, bpf@vger.kernel.org, catalin.marinas@arm.com, dri-devel@lists.freedesktop.org, ebiederm@xmission.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, penguin-kernel@i-love.sakura.ne.jp, rostedt@goodmis.org, selinux@vger.kernel.org, Masami Hiramatsu , Mathieu Desnoyers Subject: [PATCH v4 09/11] tracing: Replace strncpy() with __get_task_comm() Date: Fri, 28 Jun 2024 17:05:15 +0800 Message-Id: <20240628090517.17994-9-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240628090517.17994-1-laoar.shao@gmail.com> References: <20240628085750.17367-1-laoar.shao@gmail.com> <20240628090517.17994-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: AF521180006 X-Stat-Signature: 4wmjdqahi87qmxag7pe5ri1k8p5uh1y9 X-Rspam-User: X-HE-Tag: 1719565581-64370 X-HE-Meta: U2FsdGVkX1/G01Eae4lsxRZZtGbZ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dZLV2h4IHLS9Nirv1oKliT13OqbwW0ludgTwqHcxFnF46tsTFnQowdjEjUvuSfwVjEttPvyX1oJcmIu3CHB/cm4Y2Tf4BALu8wlTI6s8SMzNkwsx9HLNcU2FYVwvRp/aC8760oqeHV7eif8gE08A0lp4KcdMzlYRZrVVdHoOe5JUOSEh51tdAKEAqcUdI51C9fatGWitkcu7CKFWZ0WWZOU4/d5/JdJv4TXycjWtXNBeKf6F/Qc9DCwPqH2ip+2tnbMMSGXq4jceqaciieDREv0mvf/CC4uOqcI/92k9RGEcKRP3yBT54HIESTduk9I37yl03FkT77PZ33ze8ujbN9qic0WDzYajqOeJW55+xchGNbY4M1fHaGlRPl1cpxRsKSVB4kyElwrNq6MhxUXfTQ0XEPJ4jx3HoLqnh5jknzahv3O9HXWgbRKrNBMoraqbLqVjW1XExFZb8YBMAgYIYc3zOft8CDxUyLJpjaoEDPFmg88R5stlwsZC7qXs77JuATKqkz3XFLXCD1/iTbMpZSR9F4sUscUd9MM7zy7pv8I7elQRE8nc4r2ksZq7OHK81e171wUDRhu1pLlwYCGn/aVckJFcFx8739HkT09bvMAELxcsQ0GlVjn5w3TIB57O3kuTXoWDvB3F46sTwnPeuiTTvht7 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)