Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4127439pxb; Wed, 13 Oct 2021 21:54:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9O523+z922kxDccijtB7kVkDxTpFKpafAzmDEYcdvw1Ip2mm+x9MyyBcsD/aP3c/jAs85 X-Received: by 2002:a17:902:be0f:b0:13a:95e:a51 with SMTP id r15-20020a170902be0f00b0013a095e0a51mr3093372pls.44.1634187247754; Wed, 13 Oct 2021 21:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634187247; cv=none; d=google.com; s=arc-20160816; b=eeHNaYCQOTHmg+CEl/hVKqq2sr9t/1f1DkzEjuZ9JcC38hDHvpv3FCtt+SVdIuDiq+ V+tNuxX623Bb9JZUBPNOjwipc6yG9LJfLPVK2M4qgTN1c7j4gLi4Y+3diWlG50iqllkV ZeDjWkrl+a8uikDFlSQMTuV4Du65VfdJkIYsVBweo9yhWrWpHG1lG0ta9fxE0ufYMbI2 Yn4lD8NHzkqBZFpUsRpToSh/7qigZZSNL/ll947sDWws3UUy7piAV0kkw2EX5OJdVzcc 9NVIBvbZ+ISpGSYxCiojZk4TGvQSZdkJK55jx9F4Tx6od1M5wH6t4Q80kz3icYNYMPbG H1nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9DetIrTrPrsxfQH/lpQwqKA5J37Ffr1H8IrZdHL7xCE=; b=M1IVM2dOg0cmLxoLjcIEFtQNVLmtlC74XFG/YEgtCxTDIo4zrD3k1adYElhToUQLhJ C4PNeU3bp6dq0KNavsBJDJs6jutk1WG8SZ7DQCBrLv8m5oOhwgGUNqaSVlZMsft0uSPl qMLRwhXtxe22fCpj94DaVw7OntsRglgiWxdMHTDplz1TJdYJ3iTZ/bLU1HGu3H2qqTp4 iyrJEny56qBvgiRBJbcefaASh0KU6Y+WafjogZMo6cgiCllBtODWj3B3hO59IHc8L5+s 6migZKwaNaxRG2oXDCJ3/n+4y0z1L8tKAK86CKsafcl272jh3/opNA/hpHh4XbtbbQA2 /jWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WsrEMkAw; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c24si2453931pgj.447.2021.10.13.21.53.21; Wed, 13 Oct 2021 21:54:07 -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=@chromium.org header.s=google header.b=WsrEMkAw; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229498AbhJNEwu (ORCPT + 99 others); Thu, 14 Oct 2021 00:52:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbhJNEwt (ORCPT ); Thu, 14 Oct 2021 00:52:49 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84915C061570 for ; Wed, 13 Oct 2021 21:50:45 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id f5so4356003pgc.12 for ; Wed, 13 Oct 2021 21:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9DetIrTrPrsxfQH/lpQwqKA5J37Ffr1H8IrZdHL7xCE=; b=WsrEMkAwp69MeiqP4qdzJS2Cu3sPvWyv5NOCj3NZ+TxrWg4ZQGlJGvg4ZWOakEiT7j I+zdKBj69tzsr44ASBFXDKS8bkp6Sx6uu/M6sjMa+W7K4BFRQoOgAwFTufUt7SUG/Ev9 HjgCQd6g3J/I36Ip2M9329RNpOo0Bqusa86hQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9DetIrTrPrsxfQH/lpQwqKA5J37Ffr1H8IrZdHL7xCE=; b=7grEzWHi3791hoWefi8sNGs1haJ0g2eND/wNecnJa4qokOU8TzeFytWDW0O8p4yqeO RsRhShtJz0pfZcarNfIcOrcny4efCATdgydFbGDYL0aGyP2lzD+WxqvfKOakzEikbzAb 0ekoRH8ly0ZdFxkcVIDf9Eo7hJqYEXDPid+qCSq7hbM78slIOpNznkyhST9exaQRP0E4 UvuNyzRUX50Vgn+2PoSePigxBkkSomwRtlStg/8G0tzRTbElIkDiqGUs/k1cDE32s8rs FHgNexYTUOgYadGX3t4xzaCW8ntkT8GQ7EY6ZGQShYK3+iSHApiZkILyRLHcV88UYnHM VV0g== X-Gm-Message-State: AOAM532tHpMsCHnZ8tXt5QJOxqrzwG8GWDIdazzg7wLTFlyneIt2YDc9 pMX1QwpEHMVAy5q95SxRxMTDjw== X-Received: by 2002:a62:cd0f:0:b0:447:b8fe:d6c2 with SMTP id o15-20020a62cd0f000000b00447b8fed6c2mr3426171pfg.70.1634187044668; Wed, 13 Oct 2021 21:50:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i13sm1065037pgn.69.2021.10.13.21.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 21:50:44 -0700 (PDT) Date: Wed, 13 Oct 2021 21:50:43 -0700 From: Kees Cook To: Steven Rostedt Cc: Yafang Shao , 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: <202110132148.523C3EA@keescook> References: <20211013102346.179642-1-laoar.shao@gmail.com> <20211013102346.179642-3-laoar.shao@gmail.com> <20211013101921.0843aaf0@gandalf.local.home> <20211013222418.7ea9727d@oasis.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211013222418.7ea9727d@oasis.local.home> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 13, 2021 at 10:24:18PM -0400, Steven Rostedt wrote: > 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. strscpy_pad() is the right thing here -- it'll retain the NUL-fill properties of strncpy and terminate correctly. The use of non-terminating issue with strncpy() wasn't a problem here because get_task_comm() would always make sure task->comm was terminated. (It uses strlcpy(), which I think needs to be changed to strscpy_pad() too...) -- Kees Cook