Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4047817pxb; Wed, 13 Oct 2021 19:28:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweVlUfMbcxLrTyZhaqYhs4WuSea1a97Lj36ALhY1rlfYeTS7R1+T31EqtRdF14Mnkc9OKJ X-Received: by 2002:a05:6402:26cc:: with SMTP id x12mr4659839edd.127.1634178526565; Wed, 13 Oct 2021 19:28:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634178526; cv=none; d=google.com; s=arc-20160816; b=r7YC8j/5GsUTLC3oqOKOR3dtqBOEHsM6YWchzsgiiDMXchn/BDIJuMe0mVReWhQUiF 9pSv/2KXB9DVoyUjKXGJLG0gam63Yy4mSLgI0SpFfRYKZkg9dPFyMnWNV01HhonLMQFA 6WSfeFMM8xoTsgSm0pwpw+c8DBgnLIDZtwfRRjb7X0rsvosP8M1QS1QDzX0kEdaEwdro 5xV5DtDYqQeuH/5oLm8Be/cIhPBBQ+002BcsBuFIzn7CBzOrfKCEwyH1UQGN49WmTSXY pKoxijinml9vh5jv15txJsKIUVsFrFn6osmXuf7BAtyDU54JMVAJgo/gzfWa6jj5z4hj N24A== 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:subject:cc:to:from:date; bh=SDow6klOhhaLDz+CAWAfnqgQEuhSH9JBO6z8c3arN80=; b=kn2XApVTreqn5KBN0Gqac9Owp760M2tH1+DjMJEctGDoAXaGaWCQfTPorD109KXD3w 5fEnJvlqLugffqb3OrjmQadB4dbeJsbysShFGed8U0l0k3L6wDd0icM+74wmQ5EfKSON Nv2K/iocywYgG+xmvdLdQafXaLMoN52al6cfCLu8CYV8F2YpSdzQOVh6FsJyfn1yXsDS SiOJyZeafg9ktpYGHRhPuJF3Es434dv9ajoxWSBJf2iZRc0CR3d3wHqiHH2S6Q2vfEh4 TmyAvL3h604VRuHyfSs6VpftPomOq/TY9426FWl2BfESct0FG67a4VGvgcNYOAdCYrQO c1tg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y13si2589579edd.94.2021.10.13.19.28.22; Wed, 13 Oct 2021 19:28:46 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229838AbhJNC01 (ORCPT + 99 others); Wed, 13 Oct 2021 22:26:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:35346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbhJNC00 (ORCPT ); Wed, 13 Oct 2021 22:26:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 69E6A610E5; Thu, 14 Oct 2021 02:24:20 +0000 (UTC) Date: Wed, 13 Oct 2021 22:24:18 -0400 From: Steven Rostedt To: Yafang Shao Cc: Kees Cook , Peter Zijlstra , Petr Mladek , Al Viro , Andrew Morton , Valentin Schneider , Mathieu Desnoyers , qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, Dietmar Eggemann , Ingo Molnar , Juri Lelli , Vincent Guittot , Benjamin Segall , Mel Gorman , Daniel Bristot de Oliveira , David Miller , kuba@kernel.org, LKML , Vladimir Zapolskiy , David Howells Subject: Re: [PATCH v4 2/5] connector: use __get_task_comm in proc_comm_connector Message-ID: <20211013222418.7ea9727d@oasis.local.home> In-Reply-To: References: <20211013102346.179642-1-laoar.shao@gmail.com> <20211013102346.179642-3-laoar.shao@gmail.com> <20211013101921.0843aaf0@gandalf.local.home> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 14 Oct 2021 09:48:09 +0800 Yafang Shao wrote: > > __get_task_comm() uses strncpy() which my understanding is, does not add > > the nul terminating byte when truncating. Which changes the functionality > > here. As all task comms have a terminating byte, the old method would copy > > that and include it. This won't add the terminating byte if the buffer is > > smaller than the comm, and that might cause issues. > > > > Right, that is a problem. > It seems that we should add a new helper get_task_comm_may_truncated(). Or simply change __get_task_comm() to: char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk) { task_lock(tsk); strncpy(buf, tsk->comm, buf_size); /* The copied value is always nul terminated */ buf[buf_size - 1] = '\0'; task_unlock(tsk); return buf; } But that should probably be a separate patch. -- Steve