Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp857156lqh; Thu, 28 Mar 2024 21:05:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVfri1HlbhNJ9dk2F20quecX+Qe7Q+F7R5pjE02+PnfRQ6q32eg/5wOQyVtPzwDkddi34IIgjU8eI8K2lzJ1xQGeadPCx7b8zD1qSrsQA== X-Google-Smtp-Source: AGHT+IEtZhne6Z+/QAk5ifmDVJGE9Sj5H099L+Iy8e7fsU731/P2/EQ29Vz92HirHjxfG7dODLAi X-Received: by 2002:a05:6820:208:b0:5a4:7696:6ba8 with SMTP id bw8-20020a056820020800b005a476966ba8mr1066612oob.7.1711685158201; Thu, 28 Mar 2024 21:05:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711685158; cv=pass; d=google.com; s=arc-20160816; b=pQ09Bn1cBjtPL7r/pISUuYdF8Yq3PeoQm1tzCr5Od174fce0nqOSbleeMEvJUblxLM c9d1SbFSEwdHilBPXBuA8+k9e7PI8ydN5n7yIEyfhQbKCxtBs5WRxCXeDQ55mWWEVBqE GGDz54jZr3lpr1jxWhAj0wY6kB14O+9j5hFYlPpE1JtVg1frLqeh+gtYpPbhr6zbSdP8 BhMm3e2SPD/6Vz4Mz+OO3jMIaI5bhuyCbLvMH7ANuo50UxXocOQiIbhFQRnNev+RQXwR QDsSoVqvx/nmPhZuAriwGu3gMZzyZYJ6MdesIDIuaAlmLhumIk5zy4giJe9W5IWiXyhh CR9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8ChZsgQ1Elm6q3+e9M0QuKvut1I0AizgGhlSGf+ASGQ=; fh=omWM2GlFILd8E5tvebhreqLRbzP6SfLUrSrTfIZ8Yvs=; b=N1KvO45qDMmM1qNAETc1b+iUMuJuRj65g2o2OSVCB+OtBsa3Yauq87KLNA5e7v4GVk SpV8sc7ScXj1DPrVcfuBQEB1wYCd8Rx7b2EIqqHkFFn8WtOQgT4zkYPZv3V239egPT3I qH5E5Jwat5Nn6tnyu3H5lQPf6+2LNK4TnhmzxQdoLY7kNtp7UKLhceKcpxkHjhiiWjWG TqCiG2VcEydNBBc22Fr5Rjhl9SAlx3f35EfCl02S6ZbdzpKkA489kPK7YfvKfdWVQ+Xw uxLq0eTgxc93Bvcf3pbXtB6N8HaUhp8PnZKZkJylE5LWDZwO4L7JmyUfSBJpPkZShn6p OPCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="cbCphAJ/"; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-124106-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q8-20020a05622a04c800b004313b320b0bsi2878726qtx.542.2024.03.28.21.05.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 21:05:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124106-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="cbCphAJ/"; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-124106-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E3A7E1C23642 for ; Fri, 29 Mar 2024 04:05:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E0CB3A1CF; Fri, 29 Mar 2024 04:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="cbCphAJ/" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A7B039FFD for ; Fri, 29 Mar 2024 04:05:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711685152; cv=none; b=pd20vAUKsYJcHDeJ1xE6sGmrQnyI+sl/WUzdFgH9T339kgDR1L8Jo4zrftLYzhiiyQVNFw3JruxMgPaKl4PU1nzi75BZzHalJ0sb2eQH/Gu1HKlS+PFNx3lOeSygL2gmCm/eyObx9fo2gadF8TTzyX0bma0u/jBp3074KVFETnI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711685152; c=relaxed/simple; bh=ugCIfDN+OS9coGjwoiaf4ai/m8GH8gwnqHmA5Gon2/s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uAIR0kAV/eHGr3XDdxKvDHuRQ4TUIt9+PK6tcQ8TwCIcuH1af2bC9M09BCihm1/dIjoQK7SalpTGoEj6qtRE62UOn09yTRgDX4rNdrb063i0M7CHVpvt1O7qBNqn2fNdQ3byFdHn1vfXSo7jIbnL3MpLuz0g5ulIUJMIWwaLS8E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=cbCphAJ/; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1e223025ccbso6262905ad.3 for ; Thu, 28 Mar 2024 21:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711685150; x=1712289950; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8ChZsgQ1Elm6q3+e9M0QuKvut1I0AizgGhlSGf+ASGQ=; b=cbCphAJ/SIsKeYMvVlUUKVR3hb6BCeqlG8dh8614+n6QCNMHn/Ot/lm8RxZJJ8ZbCS l/5ABluekQarr3bXfg2Ypc0+JxbEkYda5VV5rWLVYEAyR7Fl9UnCHUz2e7uGL+7i7voh AE3OW9uf08XQJRxj/2rh9/sCUvntaH3rIHevo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711685150; x=1712289950; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8ChZsgQ1Elm6q3+e9M0QuKvut1I0AizgGhlSGf+ASGQ=; b=R8qCBjd8pArvKoOeO0nY8cskADgaddwqgfu2yoH1qjup1k7SEJwkIv5ybg7zHTUZ8o Jxe2jhAixGVw6sRh+ec8tNJMqcK3XVfuMT9rFnv9mLCJ0A2sq6cjHm8VDnU9syLtTdck a04LK5I8zuHEMw8ab+51MGPmbQ6a2r1VbclUnPDzZO0kBdxxtb063YohqfScv2/TiHWj UoSRcFsSUMXR/ex95g+N6+YNGE8APvwlTpHVyJfF4iwfmlH+gmro2m8U3yoQLGNb1Go3 oVujBt8ZkAX2aoPEjsJbWMMnkG8pIzbRFCiA0qqwPkCXKAuUrQ0btiqGiXstawCfrm4+ uGLg== X-Forwarded-Encrypted: i=1; AJvYcCUoY/NHClKpYLsajJg1YZP/l5OhDD7v4ZBXHUuL4pz64uVIWljz2eT2//1d+R/OF7/MXPCWpoDheJlLhQ0hOkHbBnBSzmNSZNJnB+je X-Gm-Message-State: AOJu0YxztEu/F7ImaouGHmjhkaKEQpzCp8GhXgKYefcH7Z2DQjOB/y10 pZcNlTnffafFiFIFSJ8K2wagYxo0hDdgArXGvthlbpO6urijuAkM37ADLUppQA== X-Received: by 2002:a17:902:ec8f:b0:1e0:bddf:7ed0 with SMTP id x15-20020a170902ec8f00b001e0bddf7ed0mr1612364plg.27.1711685150349; Thu, 28 Mar 2024 21:05:50 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id u13-20020a170902e80d00b001e211a291d6sm2465575plg.260.2024.03.28.21.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 21:05:49 -0700 (PDT) Date: Thu, 28 Mar 2024 21:05:49 -0700 From: Kees Cook To: Justin Stitt Cc: Fei Li , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] virt: acrn: replace deprecated strncpy with strscpy Message-ID: <202403282105.321DAF619B@keescook> References: <20240320-strncpy-drivers-virt-acrn-ioreq-c-v1-1-db6996770341@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240320-strncpy-drivers-virt-acrn-ioreq-c-v1-1-db6996770341@google.com> On Wed, Mar 20, 2024 at 11:27:09PM +0000, Justin Stitt wrote: > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > We can see that client->name should be NUL-terminated based on its usage > with a %s C-string format specifier. > | client->thread = kthread_run(ioreq_task, client, "VM%u-%s", > | client->vm->vmid, client->name); > > NUL-padding is not required as client is already zero-allocated: > | client = kzalloc(sizeof(*client), GFP_KERNEL); > > Considering the above, a suitable replacement is `strscpy` [2] due to > the fact that it guarantees NUL-termination on the destination buffer > without unnecessarily NUL-padding. > > Note that this patch relies on the _new_ 2-argument version of strscpy() > introduced in Commit e6584c3964f2f ("string: Allow 2-argument > strscpy()"). > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt Reviewed-by: Kees Cook -- Kees Cook