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 C6BD745CFC; Thu, 14 Nov 2024 02:54:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 30B65427B9; Thu, 14 Nov 2024 02:54:21 +0100 (CET) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 1CE7E4161A for ; Thu, 14 Nov 2024 02:54:18 +0100 (CET) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-20cb7139d9dso593825ad.1 for ; Wed, 13 Nov 2024 17:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1731549257; x=1732154057; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Xbu7/x2u6B0f4NR7fqNiivoQ71uwlE5LuH1+ITHjMk8=; b=pw8LimuK+VjvkagZH+Wnr+oFMzJEzKwH8iu9/+eb8WElaWDrUVyd/adDUPx9/pAtlK Oh9jQ6HqfiMjhICc8H2VK4OzrDwYOjILAb2uZeC4MhsV46X/gG/Z2UWJKBzF1BvFJb6U 1xlx0YkVX0/Hdb79GDreSLvVJ5Cg8S+eq6/VDeGD2gGbvA6q305WmE/2ep4rKQpdRmBt ZRnV2u+Dl6I8jsfwj+NthXRJ6hxlPs/vlW+7T815pc8SdLnuYfz816XIIwx/TBcXtJ7o 0E7PvoXthdoYJGo0eIwt4YK46f/ZXABKukgdst9T27OXN7kwptyqBbPBqRux8YeB/miH ztNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731549257; x=1732154057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xbu7/x2u6B0f4NR7fqNiivoQ71uwlE5LuH1+ITHjMk8=; b=Jgwhn8YJUy/3GxHPno2zsb1TYvysaag14SUmarDTVwTvTqfOAObPC1wgqrWFSmFMl5 e4knEFhMpX+ItwrXTpdENZUYqv6cn75oFnFXQRJprZrVga4eSBF8j7DtAEV8+DOx06qY jVELD+gmyLhtvUMHiuHPs6aqHqnslWlKBaU1ELcEO2Fz+xtDpSXm95u6+0EnM4Wa8DFk rr9/MvT/LJLG39bwb/ReR0HLT6rxJ9iAIHLlwdUEF4UAiUfJa9n/sF7yCbkcveXUQ7dO Ov58M3cr1ZLte7zRyCKyqZt2sGsLmh9w3p3V354C65S9X4DAMTvgFBgva4xftby5j1Jy Txgw== X-Gm-Message-State: AOJu0YwmjA6R7TqgR6AD9KPddVJ1bOZGJSC2tRw3toYftIu2T2LF3ss/ mW6uTr6edDi/+FbluKzS3F0e5Sw8OSv764TOOtzmFFwRRohLjWIR6CjtjmKzCBmOdAki7AS2N7+ I X-Google-Smtp-Source: AGHT+IFeqzOUuQmD515v8mHVvwm58j8Jj23ipsDoq8a9TSIRHYSrS2TpH9AHRchP3+45nYYEBv/f5g== X-Received: by 2002:a17:902:f541:b0:20c:d76b:a7a0 with SMTP id d9443c01a7336-21183ccf4f5mr303926665ad.8.1731549257309; Wed, 13 Nov 2024 17:54:17 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ea02496eedsm210050a91.18.2024.11.13.17.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 17:54:16 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Anatoly Burakov , Tyler Retzlaff Subject: [PATCH v2 2/8] eal: add new secure free function Date: Wed, 13 Nov 2024 17:52:16 -0800 Message-ID: <20241114015405.77060-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241114015405.77060-1-stephen@networkplumber.org> References: <20241114011129.451243-1-stephen@networkplumber.org> <20241114015405.77060-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Although internally rte_free does poison the buffer in most cases, it is useful to have function that explicitly does this to avoid any security issues. Signed-off-by: Stephen Hemminger --- lib/eal/common/rte_malloc.c | 30 ++++++++++++++++++++++++------ lib/eal/include/rte_malloc.h | 18 ++++++++++++++++++ lib/eal/version.map | 3 +++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/eal/common/rte_malloc.c b/lib/eal/common/rte_malloc.c index 3eed4d4be6..bd543b46e8 100644 --- a/lib/eal/common/rte_malloc.c +++ b/lib/eal/common/rte_malloc.c @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -27,27 +28,44 @@ /* Free the memory space back to heap */ -static void -mem_free(void *addr, const bool trace_ena) +static inline void +mem_free(void *addr, const bool trace_ena, bool zero) { + struct malloc_elem *elem; + if (trace_ena) rte_eal_trace_mem_free(addr); - if (addr == NULL) return; - if (malloc_heap_free(malloc_elem_from_data(addr)) < 0) + if (addr == NULL) + return; + + elem = malloc_elem_from_data(addr); + if (zero) { + size_t data_len = elem->size - MALLOC_ELEM_OVERHEAD; + + rte_memset_sensative(addr, 0, data_len); + } + + if (malloc_heap_free(elem) < 0) EAL_LOG(ERR, "Error: Invalid memory"); } void rte_free(void *addr) { - mem_free(addr, true); + mem_free(addr, true, false); +} + +void +rte_free_sensative(void *addr) +{ + mem_free(addr, true, true); } void eal_free_no_trace(void *addr) { - mem_free(addr, false); + mem_free(addr, false, false); } static void * diff --git a/lib/eal/include/rte_malloc.h b/lib/eal/include/rte_malloc.h index c8836de67c..6675c3f405 100644 --- a/lib/eal/include/rte_malloc.h +++ b/lib/eal/include/rte_malloc.h @@ -51,6 +51,24 @@ struct rte_malloc_socket_stats { void rte_free(void *ptr); + +/** + * Frees the memory space pointed to by the provided pointer + * and guarantees it will be zero'd before reuse. + * + * This pointer must have been returned by a previous call to + * rte_malloc(), rte_zmalloc(), rte_calloc() or rte_realloc(). The behaviour of + * rte_free() is undefined if the pointer does not match this requirement. + * + * If the pointer is NULL, the function does nothing. + * + * @param ptr + * The pointer to memory to be freed. + */ +__rte_experimental +void +rte_free_sensative(void *ptr); + /** * This function allocates memory from the huge-page area of memory. The memory * is not cleared. In NUMA systems, the memory allocated resides on the same diff --git a/lib/eal/version.map b/lib/eal/version.map index a20c713eb1..4e0203053a 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -398,6 +398,9 @@ EXPERIMENTAL { # added in 24.11 rte_bitset_to_str; rte_lcore_var_alloc; + + # added in 25.03 + rte_free_sensative; }; INTERNAL { -- 2.45.2