Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp538300rdh; Wed, 7 Feb 2024 12:02:33 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXkgbB20z4K67PLltd67n7lKXV58A3SI+20bXZpWDKT/PeufeDe5d+fjpuJcbIC/E711Xt3wIH+EkUI7u7H0m2XNlOe08nYSfSj2eZE4g== X-Google-Smtp-Source: AGHT+IGZ9ZEldJm/QbYgnLz3cycO/fE235YMDmwkRK1e4LbEBxING4r3CdrnjAkwySOykMH3Z+hj X-Received: by 2002:a05:622a:244:b0:42c:3041:3bb7 with SMTP id c4-20020a05622a024400b0042c30413bb7mr7823623qtx.22.1707336152908; Wed, 07 Feb 2024 12:02:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXEGyubNXW0gLDhwmzw4H3/5hIEiiQwdd7Rkme27SKenZbxOWceoPfSmak07m6NZGSAyF7b228ITOlky4WpXF25mENZIA1t5C8/9cSf4g== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 21-20020ac85955000000b0042c2d941f5esi1845115qtz.40.2024.02.07.12.02.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 12:02:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56998-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-56998-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56998-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 985CA1C24EE8 for ; Wed, 7 Feb 2024 20:02:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8776126F06; Wed, 7 Feb 2024 20:02:25 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E98D48662E; Wed, 7 Feb 2024 20:02:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707336145; cv=none; b=aV/J4KGiVBgyExuzU9r/wV4CN/WGqQrQGCwqlj4gOfdEU5+4PH2gGZPHj9Z8aYUJLovz9MSAOAzxAxQfWDIC4spFhGDDXmLWly0eUicHHCEi8JvzPAYMkH6r2d4+exAk5jCm1Te99dDNH0CDtjtL71oJAZngjGPSz4TVssPCo7M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707336145; c=relaxed/simple; bh=TrjEqjLvOxUxtg4GqmJF1cp5iazOi1slhQk9UHFTM38=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QExhm6ULN4R5oU9NH/j0hAbyTSIgMm1PtWZgHoTpLqYYm54+a0m7r2RfLdL5OeMsiKtqlJoe4deo6yHNFnwc43hcKhNThH4gFD7UqcY6VdBQt0oO7qarhLpIReHtew7hTD14+LJqR7KXjlflzibSgNulGyQ4DL0EMz9N1+jOrDM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=black.fi.intel.com; spf=pass smtp.mailfrom=intel.com; arc=none smtp.client-ip=198.175.65.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=black.fi.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="982540" X-IronPort-AV: E=Sophos;i="6.05,251,1701158400"; d="scan'208";a="982540" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 12:02:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="933895627" X-IronPort-AV: E=Sophos;i="6.05,251,1701158400"; d="scan'208";a="933895627" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 07 Feb 2024 12:02:19 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 74EB94C4; Wed, 7 Feb 2024 16:03:35 +0200 (EET) Date: Wed, 7 Feb 2024 16:03:35 +0200 From: Andy Shevchenko To: Ingo Molnar Cc: Justin Stitt , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Kees Cook Subject: Re: [PATCH v2] x86/tdx: replace deprecated strncpy with strtomem_pad Message-ID: References: <20231003-strncpy-arch-x86-coco-tdx-tdx-c-v2-1-0bd21174a217@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: On Wed, Oct 04, 2023 at 09:32:54AM +0200, Ingo Molnar wrote: .. > > Note: Ingo Molnar has some concerns about the comment being out of sync > > [1] but I believe the comment still has a place as we can still > > theoretically copy 64 bytes into our destination buffer without a > > NUL-byte. The extra information about the 65th byte being NUL may serve > > helpful to future travelers of this code. What do we think? I can drop > > the comment in a v3 if needed. > > > /* VMM assumes '\0' in byte 65, if the message took all 64 bytes */ > > - strncpy(message.str, msg, 64); > > + strtomem_pad(message.str, msg, '\0'); > > My concern was that with the old code it was obvious that the size > of message.str was 64 bytes - but I judged this based on the > patch context alone, which seemingly lost context due to the change. > > In reality it's easy to see it when reading the code, because the > length definition is right before the code: > > union { > /* Define register order according to the GHCI */ > struct { u64 r14, r15, rbx, rdi, rsi, r8, r9, rdx; }; > > char str[64]; > ^^^^^^^^^^^^^ > } message; > > /* VMM assumes '\0' in byte 65, if the message took all 64 bytes */ > strtomem_pad(message.str, msg, '\0'); This comment and size of union seems not in agreement. How does the previous code work if message indeed takes 64 bytes? By luck? -- With Best Regards, Andy Shevchenko