From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00195C433EF for ; Thu, 14 Oct 2021 02:24:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD8DB610E8 for ; Thu, 14 Oct 2021 02:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbhJNC01 (ORCPT ); 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