Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1015119pxb; Tue, 26 Oct 2021 00:59:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx63Knl13FJ/Vse2S0kUZAAqZAfAxCtDTlfTJ/tdjnqD4WAuLQpM18JcSaQnbati42MWcmV X-Received: by 2002:a05:6a00:21c6:b0:44c:937:fbf3 with SMTP id t6-20020a056a0021c600b0044c0937fbf3mr24449697pfj.2.1635235149541; Tue, 26 Oct 2021 00:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635235149; cv=none; d=google.com; s=arc-20160816; b=isGsd70xOk4b5oPFycP+IPoihoMLiFMpHAl/ymzasN+jh2SQ0+CLPvc73R4FQhnK6j LhTI1wYHAtxaKxWV/c+MyFzyyFfUl2O68pdVjy3bFRKpYLrw5Roem4GmkdLetZRNDqid ApaDb+2YQdIUJEOD9UWRADm1fjxlrrwhRcSUr/WWhhuwKSeGIohfqGRnd+Ox8uyT2n0U ljuJIolAltYcOyLd/tS0J4PCT3K0DbBfVEMe/lzEx4pW264LnlmAnaSR+SeNt1j3oM40 ERTKCBaUlftb5lagcs/UA4yJOmJIYVf0Jb7CbGjr9QJr8F+Fx7PoffeN0qb1aFSzojZt Zx/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ScHBEadlhvXJ5Ux51PKGxkHvsss0u6ctZT9nDJJQkzo=; b=CbdbEA0ynUOka1ljag8TfCdo6r9KZg7EpVdt2cVYX0AujqvFlC6bjmlSY4+PfUmufP /lSnsKrEAlpClBTGTXMQUPcGB+YV5anwaN9Cui5YklU2gmQ2G+ciTd1QzDQPyXU9ARU6 uVyzqj+D/815MduAG+bsGOP0yeRedziinqe9zKnV9pAng2a99LQO+FAR13GKYcc05roM 12AuA/uJRN6U9TKxaqYB5BrZTj17I67nVletbn4PWM2jwdEo4d39vjBSfAoUBjmjSf/j XnAK7s9d5L8K0nAr5cVOskJYw6+XY1K2oU4EKw7K4RZKfpoSo3GZNBQ1oeQmQRcliwd8 Kn9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Fx3ncUFZ; 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 u8si4673348ple.379.2021.10.26.00.58.57; Tue, 26 Oct 2021 00:59:09 -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=Fx3ncUFZ; 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 S233308AbhJZBw3 (ORCPT + 99 others); Mon, 25 Oct 2021 21:52:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232987AbhJZBw2 (ORCPT ); Mon, 25 Oct 2021 21:52:28 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 569F4C061745; Mon, 25 Oct 2021 18:50:05 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id b188so18085760iof.8; Mon, 25 Oct 2021 18:50:05 -0700 (PDT) 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=ScHBEadlhvXJ5Ux51PKGxkHvsss0u6ctZT9nDJJQkzo=; b=Fx3ncUFZI8yO/PIUnaTNHz3IQgwVf1ec+igHEUtG3eIgKmfEYkRxJ6PWm0JQb9GuQJ aqs6xn44Rv1O5XW7VtN12VrTzhCaxBKC/PfNYDPfSoQub3BKKrGzdA+xia0FajoLpQUK gzWEKPB8cTjG/Y3XWkseihPfESzdoqy8tamnEgt/HF3kyWah44FujLVdRiQxa/nGOPqv V5X/RrU4l8zTncHMniSEs0frs++vuQNQDCHyvaBvwk6dtm8J5u9o73bEldNgR2ahmq5d vlDlYx7m4s4bXuNDVRCAFpjVAV9R7u69MCBK/1f4NJfFQ+r+FWxEU1+h/LLaXSTQpq6c k+oQ== 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=ScHBEadlhvXJ5Ux51PKGxkHvsss0u6ctZT9nDJJQkzo=; b=GzjhHSD3Mo9mJvhSyUmQOctOHEnlKq3VLl2b9kfpXoTUHrMvvYQsFn3QMso+6cpuZ0 Wv6haSwgtTbps6gykSYlaaVlwBXB32qu60ddhp7+Xe8zyT1LpYcvvKPEsUvWm4ebs3Pc 5uw/pWx1fiS8cEWxeoawddGG1KRZBkpuef6SMy5zL5X/BlCvorLoWjAIQUotY87qvbRI q6IU27sjFuheFjhtSuK+k+TeCZeqdypzjZk3HZFJ9tDiAhDo52ARjdA2Ktd452kvv+KH CQ2MIHfBWI9OIXMJXPbghcjcxVT41MxVyo5weQYr55Do4WWQAHmUoC50uY09hnYx/Dzl YzWg== X-Gm-Message-State: AOAM532kFIog0LmLXhKCro9EcBy9CcLC85csM9djXgF7yzka9Zv7vB6S XZdFWz3BhQvgH9z4AMOICYNhHT/uHbDOyts+JYs= X-Received: by 2002:a05:6602:2e05:: with SMTP id o5mr12805350iow.204.1635213004755; Mon, 25 Oct 2021 18:50:04 -0700 (PDT) MIME-Version: 1.0 References: <20211025083315.4752-1-laoar.shao@gmail.com> <20211025083315.4752-3-laoar.shao@gmail.com> <202110251408.2E661E70BC@keescook> In-Reply-To: <202110251408.2E661E70BC@keescook> From: Yafang Shao Date: Tue, 26 Oct 2021 09:49:28 +0800 Message-ID: Subject: Re: [PATCH v6 02/12] fs/exec: make __get_task_comm always get a nul terminated string To: Kees Cook Cc: Andrew Morton , Steven Rostedt , Mathieu Desnoyers , Arnaldo Carvalho de Melo , Petr Mladek , Peter Zijlstra , Al Viro , Valentin Schneider , Qiang Zhang , robdclark , christian , Dietmar Eggemann , Ingo Molnar , Juri Lelli , Vincent Guittot , David Miller , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org, netdev , bpf , "linux-perf-use." , linux-fsdevel@vger.kernel.org, Linux MM , LKML , kernel test robot , kbuild test robot , Andrii Nakryiko Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 5:08 AM Kees Cook wrote: > > On Mon, Oct 25, 2021 at 08:33:05AM +0000, Yafang Shao wrote: > > If the dest buffer size is smaller than sizeof(tsk->comm), the buffer > > will be without null ternimator, that may cause problem. We can make sure > > the buffer size not smaller than comm at the callsite to avoid that > > problem, but there may be callsite that we can't easily change. > > > > Using strscpy_pad() instead of strncpy() in __get_task_comm() can make > > the string always nul ternimated. > > > > Suggested-by: Kees Cook > > Suggested-by: Steven Rostedt > > Signed-off-by: Yafang Shao > > Cc: Mathieu Desnoyers > > Cc: Arnaldo Carvalho de Melo > > Cc: Andrii Nakryiko > > Cc: Peter Zijlstra > > Cc: Steven Rostedt > > Cc: Al Viro > > Cc: Kees Cook > > Cc: Petr Mladek > > --- > > fs/exec.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/fs/exec.c b/fs/exec.c > > index 404156b5b314..bf2a7a91eeea 100644 > > --- a/fs/exec.c > > +++ b/fs/exec.c > > @@ -1209,7 +1209,8 @@ static int unshare_sighand(struct task_struct *me) > > 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 null terminated */ > > This may could say "always NUL terminated and zero-padded" > Sure. I will change it. > > + strscpy_pad(buf, tsk->comm, buf_size); > > task_unlock(tsk); > > return buf; > > } > > -- > > 2.17.1 > > > > But for the replacement with strscpy_pad(), yes please: > > Reviewed-by: Kees Cook > > > -- > Kees Cook -- Thanks Yafang