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 F1E55C433EF for ; Wed, 10 Nov 2021 09:06:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8356B6113D for ; Wed, 10 Nov 2021 09:06:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8356B6113D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1E49E6B006C; Wed, 10 Nov 2021 04:06:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 195086B0075; Wed, 10 Nov 2021 04:06:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 035AF6B007D; Wed, 10 Nov 2021 04:06:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id E8E536B006C for ; Wed, 10 Nov 2021 04:06:21 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B43197CB24 for ; Wed, 10 Nov 2021 09:06:21 +0000 (UTC) X-FDA: 78792439362.25.2809938 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf16.hostedemail.com (Postfix) with ESMTP id 9029CF00009C for ; Wed, 10 Nov 2021 09:06:11 +0000 (UTC) Received: by mail-qk1-f177.google.com with SMTP id br39so1837827qkb.8 for ; Wed, 10 Nov 2021 01:06:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ImnqB797AKnJuD4oPIYf8Tox3YCxcvXVphwHiRaIbIY=; b=oMfCBYvauO8zRBwa2KehEw6l9I/gVh/IsHK2ianpEu/xIihkSVB/V6SY3F/ttzaM9E nezbT4CmBgHKehn2yU5PaH/ZIe37KBZYxptntmlE84NkrCX9sBVx5fvOJ97WuHyjLu81 ySMip7zDVDJzC8Ud+eLEDqMIyFDT68YJu/vMGfrUMMkvIb9Gy3UDZ9KieYePa59ndf9w 2iNH/0Swtlcmca7uxTSVZ6+cgn0aA6kyAsyRtDOUv343TMFcvYUnDbmDYL36Evv24Use DEXFPEpNZYt0Ltjw511zdD5Yt5ts2oQXhSF1bjzx+hLVoi83rzncSdyXWjhsWQZSkQMW 9DAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ImnqB797AKnJuD4oPIYf8Tox3YCxcvXVphwHiRaIbIY=; b=RxA5hGb7/Y1vYsy2K4wEW27kYye1yXm2+s8i4iavh5UEIGYC6qrSRDeCnkqR8EIZmo wykJTtjHCVPO28U9y/RHpN62S30kdfhVjmy/jBU5qgvtx9mKKboHHpKyHqxihs7RZZQC KVGpN5HP946jGOtU5xihILhSsSfB0iKIIGGHTh4TBrGjJwzOKO1zyUdG43fVmsuJ+M6E 2OnMFlK9Af/I5eQFWxd0H/6HcVtj/1m8KGT5b1D2aEgCsELa6x0CwgCF4eekhTL5G3qs c78fM18Pnxre5V7W0wRFa5+pGdMW+FFgrd7ObTkKjwIM5X3iBrOyDbSwFkgqOW+gZMeF c56Q== X-Gm-Message-State: AOAM5308V69ZxJHs5sOycNCmxJvIgK5Efzyv8wexUZuywAcixI1bUiX9 9/w3KsojEeYzo7opH8IZlnsnvIcapudJI71rJ6E= X-Google-Smtp-Source: ABdhPJxecwxlgh5Be+apIVbyhK9b5EOBmc1BMU6ZqqxInFojT85GAhLJhs4ImfIMb89COAJxX42mTS13PbNiDO5tpM0= X-Received: by 2002:a37:e97:: with SMTP id 145mr11499308qko.116.1636535180801; Wed, 10 Nov 2021 01:06:20 -0800 (PST) MIME-Version: 1.0 References: <20211108083840.4627-1-laoar.shao@gmail.com> <20211108083840.4627-2-laoar.shao@gmail.com> In-Reply-To: From: Yafang Shao Date: Wed, 10 Nov 2021 17:05:44 +0800 Message-ID: Subject: Re: [PATCH 1/7] fs/exec: make __set_task_comm always set a nul terminated string To: David Hildenbrand Cc: Andrew Morton , netdev , bpf , "linux-perf-use." , linux-fsdevel@vger.kernel.org, Linux MM , LKML , kernel test robot , kbuild test robot , Kees Cook , Mathieu Desnoyers , Arnaldo Carvalho de Melo , Alexei Starovoitov , Andrii Nakryiko , Michal Miroslaw , Peter Zijlstra , Steven Rostedt , Matthew Wilcox , Al Viro , Petr Mladek Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9029CF00009C X-Stat-Signature: z444wnsnyo3yexp99xnxu1heed4j569i Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=oMfCBYva; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-HE-Tag: 1636535171-878063 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Nov 10, 2021 at 4:28 PM David Hildenbrand wrote: > > On 08.11.21 09:38, Yafang Shao wrote: > > Make sure the string set to task comm is always nul terminated. > > > > strlcpy: "the result is always a valid NUL-terminated string that fits > in the buffer" > > The only difference seems to be that strscpy_pad() pads the remainder > with zeroes. > > Is this description correct and I am missing something important? > In a earlier version [1], the checkpatch.py found a warning: WARNING: Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/ So I replaced strlcpy() with strscpy() to fix this warning. And then in v5[2], the strscpy() was replaced with strscpy_pad() to make sure there's no garbade data and also make get_task_comm() be consistent with get_task_comm(). This commit log didn't clearly describe the historical changes. So I think we can update the commit log and subject with: Subject: use strscpy_pad with strlcpy in __set_task_comm Commit log: strlcpy is not suggested to use by the checkpatch.pl, so we'd better recplace it with strscpy. To avoid leaving garbage data and be consistent with the usage in __get_task_comm(), the strscpy_pad is used here. WDYT? [1]. https://lore.kernel.org/lkml/20211007120752.5195-3-laoar.shao@gmail.com/ [2]. https://lore.kernel.org/lkml/20211021034516.4400-2-laoar.shao@gmail.com/ > > Signed-off-by: Yafang Shao > > Reviewed-by: Kees Cook > > Cc: Mathieu Desnoyers > > Cc: Arnaldo Carvalho de Melo > > Cc: Alexei Starovoitov > > Cc: Andrii Nakryiko > > Cc: Michal Miroslaw > > Cc: Peter Zijlstra > > Cc: Steven Rostedt > > Cc: Matthew Wilcox > > Cc: David Hildenbrand > > Cc: Al Viro > > Cc: Kees Cook > > Cc: Petr Mladek > > --- > > fs/exec.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/exec.c b/fs/exec.c > > index a098c133d8d7..404156b5b314 100644 > > --- a/fs/exec.c > > +++ b/fs/exec.c > > @@ -1224,7 +1224,7 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) > > { > > task_lock(tsk); > > trace_task_rename(tsk, buf); > > - strlcpy(tsk->comm, buf, sizeof(tsk->comm)); > > + strscpy_pad(tsk->comm, buf, sizeof(tsk->comm)); > > task_unlock(tsk); > > perf_event_comm(tsk, exec); > > } > > > > > -- > Thanks, > > David / dhildenb > -- Thanks Yafang