Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp493055pxb; Sun, 10 Oct 2021 03:42:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdznk33bP11Z2J/5wJsJ7NemR1QttS3suluD5MFBdnmN8w8o3kazV8K/25xb5V/YpKPW2H X-Received: by 2002:a05:6402:274b:: with SMTP id z11mr32018852edd.151.1633862542615; Sun, 10 Oct 2021 03:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633862542; cv=none; d=google.com; s=arc-20160816; b=E/SoKsi1Jgw8LwarHYeE36iIC7bMDvDtHIX6BUWyzV6zeo/8YJhftFy60Ab8xWrBaO OtKiDVyfKIJOIpeDOH30Tf09gojXXnWo0dOt84J6aCE/Mn0R0r02cx4AdPzuYGa6DXat HQ9jxNvTajfx+XL56u2w9ksVxDeQE8QMyCt5raILqiL/0u0b3EzMOLuXFZ/ND6kHvssu hoAtKwViyXtc9dzePFVgeuJ/ZR4P5/9c8bqNUwn+MtWaAHwEaD7gBoevQ2VL1L1pwkX2 QCdzlkE3D79Wj4/rkJst6oALWi9uAqt6kfNdCOjUa7xpBEnp2it6YKrm+gMmoVrq43Op SXWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lHX3T1QaGRW7QLyVlwJ/mNN/4KcRZcqxwEcbPgjUcaI=; b=vqriSxDZ4cFFOElW28jfXSAfqh8gTQK6U51xfY/rlTUlQNL5UB/IksyizntRFj/rRS ApaUyy1Enq5FHoyEpIB/NZFpV6y/Z/+k81n1/MCelXNeeXmr1hPxTz70QIHhGx6WKpji cdRSScVBIWPjbXQRAnq++vmHcjuA12taMCoLed0QtjSkL40JWkFWwWqEyoWqydwOaWeB NXC2A+x20mAOM9kVoXDXVWPFFQlSg7iL11NiUrvbOy3COEX7crCutE77ohiDXqH2o0pA GhYl+ECiSQguYJKYWs1c0bYYX9XXlY0bnuM0dNIsRgkavcPTcdtK+qAG0jawsT2SsGZe nj/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ky2XqBId; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i3si6611775ejy.715.2021.10.10.03.41.58; Sun, 10 Oct 2021 03:42:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ky2XqBId; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231727AbhJJK1Y (ORCPT + 99 others); Sun, 10 Oct 2021 06:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231580AbhJJK1P (ORCPT ); Sun, 10 Oct 2021 06:27:15 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB130C061762 for ; Sun, 10 Oct 2021 03:25:16 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id 187so12194396pfc.10 for ; Sun, 10 Oct 2021 03:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lHX3T1QaGRW7QLyVlwJ/mNN/4KcRZcqxwEcbPgjUcaI=; b=Ky2XqBIdiz4urS2uso29THdRJHXLDNpCj53Bc4AsnF0vA8YmsFy8f5sGr5ZwQ+/KAR c3SlFZ+b4/Ibgq5GsTABwP6az0a27Naebvb3vhzvcuQqhT7LJnDLjkhAMzys7qJeI2Me lMg/ewQNjqL6R1e9Rw4Kk/AxlqU5hcXVlNBmxtqv8sQxOW5lIk9DpA//o7LRppPdehUv mYD2IgdZrEYyhjzZrPWweN/OlfBaEvfkYmccqAHPVVjVTN7EbzAg3HBqJcdshR+FwEVt 2wt/M0XG7jVJoDlIYf9zpkfjPTAhAel1WUZekF1W0fuRBsBvTJuDaD51HKVoKRrwQfIp U+Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lHX3T1QaGRW7QLyVlwJ/mNN/4KcRZcqxwEcbPgjUcaI=; b=vnNpjzeynh51LQMI2BmnZWLta0p6d7FRruKyfiRdXDhpuNf7OmZRsqLWO0PdNQ2iN3 dChFCUbfV1sUfHnp2vN9ehczOgg65PWZYyUMF6i0VQIlEhSaTL/auBSIGMuG6sJkoLG+ IqvP/JJzR4ywvfvv/lTC61rer12h7HOG0AEpvr8Xp1UnrMWrS0gcS2NxpFbhevNghTiD 8AA3oETRunCZx/fm4UbwlgBcRoNZnaaadWK0C8xuhMy0clw5t6ojp3W3NZMDgqAJS6T2 LARgJJ4wAJsPh17aFeikgQDQeil6g6dn6C/oqTiAXtd6+QbjKFWfSHn7BHFPro0oqJET NR5w== X-Gm-Message-State: AOAM531GiwI+DkmLeKuKF18PP+zTtgPv4zWzBefeXSE/T3wPJK2l+0ZB /Ty5CFbVdNz/tvGuM3zhbGQ= X-Received: by 2002:a05:6a00:1147:b029:3e0:8c37:938e with SMTP id b7-20020a056a001147b02903e08c37938emr19805158pfm.65.1633861516515; Sun, 10 Oct 2021 03:25:16 -0700 (PDT) Received: from vultr.guest ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id w4sm4347494pfb.3.2021.10.10.03.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Oct 2021 03:25:16 -0700 (PDT) From: Yafang Shao To: keescook@chromium.org, rostedt@goodmis.org, peterz@infradead.org, pmladek@suse.com, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, valentin.schneider@arm.com, mathieu.desnoyers@efficios.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com Cc: linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH v3 4/4] kernel/kthread: show a warning if kthread's comm is truncated Date: Sun, 10 Oct 2021 10:24:29 +0000 Message-Id: <20211010102429.99577-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211010102429.99577-1-laoar.shao@gmail.com> References: <20211010102429.99577-1-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Show a warning if task comm is truncated. Below is the result of my test case: truncated kthread comm:I-am-a-kthread-with-lon, pid:14 by 6 characters Suggested-by: Petr Mladek Signed-off-by: Yafang Shao Reviewed-by: Kees Cook Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Petr Mladek --- kernel/kthread.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index 5b37a8567168..46b924c92078 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -399,12 +399,17 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data), if (!IS_ERR(task)) { static const struct sched_param param = { .sched_priority = 0 }; char name[TASK_COMM_LEN]; + int len; /* * task is already visible to other tasks, so updating * COMM must be protected. */ - vsnprintf(name, sizeof(name), namefmt, args); + len = vsnprintf(name, sizeof(name), namefmt, args); + if (len >= TASK_COMM_LEN) { + pr_warn("truncated kthread comm:%s, pid:%d by %d characters\n", + name, task->pid, len - TASK_COMM_LEN + 1); + } set_task_comm(task, name); /* * root may have changed our (kthreadd's) priority or CPU mask. -- 2.18.2