From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CC02248867 for ; Tue, 30 Sep 2025 01:43:24 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A4A58402A2; Tue, 30 Sep 2025 01:43:24 +0200 (CEST) Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by mails.dpdk.org (Postfix) with ESMTP id A1262402A2 for ; Tue, 30 Sep 2025 01:43:23 +0200 (CEST) Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-4b109c6b9fcso52208571cf.3 for ; Mon, 29 Sep 2025 16:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1759189403; x=1759794203; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=5VduP5azQ5MY+2E5pEASrxTozJilAR1y+JilwXdLWug=; b=NN4o70ZFCwUYgCxatStbvb7yqyHvrrPheI8DhlMgTjffXFmr8KI3gjUHU/yIg82ZQ6 yN4iVsdApv+3TMg+GXQ5SVBdOOrTZ7rlYxIm4IFoFqEvnxmbsPJEdPYwqdHh88pH/hWX 1xiQH1tLXvbmhoXXYJcDqeQtt7stRns2K/x50cw2qsFACYbg3GH7b0KHvPtg87G+LQVF tx/TDAUURD+3YfEhZmL8S+h5840icLejCXSb4hbcIgyfFap+6eZtcPc5eilRVr5IrytI 9Uqyku07BASdqdaicb5stTBcOWd5rmsFh2GKgGGTIdvAw8F42dXGitLY3mZ+3Lc0UYus Dypg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759189403; x=1759794203; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5VduP5azQ5MY+2E5pEASrxTozJilAR1y+JilwXdLWug=; b=Jo6Mp29IaLhASdKvgA9PmPCmwrLKSU40LSVoZsY4q6GXutspbQ3+fuJb2bVphv51it 6AIjm55deoF+REGAgONyudrmTr9c/MRiJg1mb2XKAr7H8CJoLTdh4lEjghNZjcuhJFeP 2CETCdxBjWZpsD8mPWuSetE25VlpTNkmW1Px1xr5zYmP/gRgZcUFhQYLWRVCmitF0V69 vNMjLBWr/Poq1z78oQDisj4ngwpc60J13qgWA9v1yMF2uVjz+meCk55NoaH09r56uBsS 8TDdpZitaNjJqsQ5fO/MAJ4PvMdfBrm3Nge9CW9v/49p7iSGt6uEwdiXPow/PWCTnArY XbTA== X-Forwarded-Encrypted: i=1; AJvYcCXYiCCrEFX5wkDUwLNa6JUWZ2dHeg+FOKBnEiZJuiT5Q5X69r7ZpWcQhdfhW2K9J6ZiiNyioiI=@dpdk.org X-Gm-Message-State: AOJu0YypxfQU6A4m21y0h9u/1JwIDSdmPqAjWV8bd0/JRKzV3+lSsRvG dDsQk2jezltyWJmmcVFIPgQd+CT66MNsRAZh7KlzDunfPYqux79U0ZTt6It+BcNGvIY= X-Gm-Gg: ASbGncuaN6dBoaTIE+e1Hl60LDli8PvTVz0ucCfGozDHsfIa+Doan8f5kUrsTxTyCH8 fKmlz8wBiCD2tUzgicSZPujB+jwZbNg91111yQx2UBH9RIlBqoVCEJ0f29oR4B10/eiI1SQr6Ns eL6BGl4oU5/5XPbTBeoG7DDjhW0lzLc0WkDLDdDCccPQYVmVPHnHWTYns7U1RG9DhCg1RDu0YSX RrwxhKfhY9CrVG7uFzefqeVcV9e8G3S7m6U7z3duQ6c8LfTEeAxhBdmuoSGvgOKGD813N59HfFr 1u2x7EVGQ/XxAKbaWQUKLGTjm6lwEdBy0SXHLKvxXgfB1K3D7ZoU+3cBWMK0Wnl2C2OJSvPdMg9 D3EYnqtxtvQoS2TmMDqWl96xrz17M+lbBek1426uLx6Hk8Qxc2srkiFHxAqgj+w7VP4T3M301t9 6oE6pcqPSPKg== X-Google-Smtp-Source: AGHT+IE8tMtMfql8Hhi7Famc9a2CrSvhA+9hX52K41y8ZG7Ear59XFu7EbIiLSndLisgjdSH6d8AQw== X-Received: by 2002:a05:622a:212:b0:4b7:a8ce:a419 with SMTP id d75a77b69052e-4da486b7062mr287255561cf.26.1759189402659; Mon, 29 Sep 2025 16:43:22 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4db0b9458e1sm83652861cf.15.2025.09.29.16.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Sep 2025 16:43:22 -0700 (PDT) Date: Mon, 29 Sep 2025 16:43:18 -0700 From: Stephen Hemminger To: Kai Ji Cc: dev@dpdk.org, gakhil@marvell.com, konstantin.ananyev@huawei.com, bruce.richardson@intel.com, thomas@monjalon.net, stable@dpdk.org Subject: Re: [dpdk-dev v2 1/2] eal: Add rte_consttime_memsq() to prevent timing attacks memcmp. Message-ID: <20250929164318.33d6054c@hermes.local> In-Reply-To: <20250926154905.54416-1-kai.ji@intel.com> References: <20250925102223.145471-1-kai.ji@intel.com> <20250926154905.54416-1-kai.ji@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On Fri, 26 Sep 2025 15:49:04 +0000 Kai Ji wrote: > Bugzilla ID: 1773 > Cc: stable@dpdk.org > > [0] https://bugs.dpdk.org/show_bug.cgi?id=1773 > > Signed-off-by: Kai Ji > --- > lib/eal/include/rte_common.h | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h > index 9e7d84f929..ddbba083be 100644 > --- a/lib/eal/include/rte_common.h > +++ b/lib/eal/include/rte_common.h > @@ -700,6 +700,40 @@ rte_is_aligned(const void * const __rte_restrict ptr, const unsigned int align) > return ((uintptr_t)ptr & (align - 1)) == 0; > } > > +/** > + * Constant-time memory inequality comparison. > + * > + * This function compares two memory regions in constant time, making it > + * resistant to timing side-channel attacks. The execution time depends only > + * on the length parameter, not on the actual data values being compared. > + * > + * This is particularly important for cryptographic operations where timing > + * differences could leak information about secret keys, passwords, or other > + * sensitive data. > + * > + * @param a > + * Pointer to the first memory region to compare > + * @param b > + * Pointer to the second memory region to compare > + * @param n > + * Number of bytes to compare > + * @return > + * false if the memory regions are identical, true if they differ > + */ > +static inline bool > +rte_consttime_memneq(const void *a, const void *b, size_t n) > +{ > + const volatile uint8_t *pa = (const volatile uint8_t *)a; > + const volatile uint8_t *pb = (const volatile uint8_t *)b; > + uint8_t result = 0; > + size_t i; > + > + for (i = 0; i < n; i++) > + result |= pa[i] ^ pb[i]; > + > + return result != 0; > +} > + > /*********** Macros for compile type checks ********/ > > /* Workaround for toolchain issues with missing C11 macro in FreeBSD */ Also need functional tests for any new function in the functional test suites. Just some basic tests, suggest using random data, and lengths; validate with memcmp. And/or see what freebsd already has.