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 E8F9745D07; Thu, 14 Nov 2024 19:45:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 00CC542EE0; Thu, 14 Nov 2024 19:45:07 +0100 (CET) Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by mails.dpdk.org (Postfix) with ESMTP id 95CA342ED4 for ; Thu, 14 Nov 2024 19:45:04 +0100 (CET) Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2ea0bf6bebbso565239a91.0 for ; Thu, 14 Nov 2024 10:45:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1731609904; x=1732214704; 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=czdff7aaeagxvVWtV/V8L5ENmVGkpd7qahkHslii834=; b=xyzgYncxMStWaIKwmfmwAS26LcBFZGEFd/qHZVsjHgvr+gG1HkIqv9FxmOHFqvwxEf oaOoyWNqnMv3v+6b53GNlyMuSI/+p0YYLzf/zYG4wrkosJijz8TTTPT7BfAA82NZzojx /eNNth5iSz/qIAhsVSWlFLh44N0oXuRqXntQZzOnUtMBpZmyV3Wky8DInsIZ1eY41hYW 3kbNZ4lJmO+1WmiDkw9tLHcYHSLbKvWGutfg5++zbgWdW97Tpf+Tn91JZG54ZIFmwjIw prYBFml2M69RGo1bEXiIJffif2/KqwfPTaO/OtyYEo+sY6YfoG9UO4khICHfeBE1lu/b CWrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731609904; x=1732214704; 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=czdff7aaeagxvVWtV/V8L5ENmVGkpd7qahkHslii834=; b=MOvs2eLufXnu76ta6mgSeLi1ACc6rdv5QgRKnEj2BgkZO0jD3FhJIf8vAv+avkk16q he7z7kQwPDZYBXqOc9gSGpsOkIfKBECrNBSUo53s0aNgYyXqfS+R66LFWBdwZcEAWw9T MR/q42LwwqDoaqTRLK9w4HLNXDcR5eW4pzTlNwCZbfrMQOUgChRxaKjAPNPe/AncChVt i+itN9MCYFnIIu9YUIGNbMAQDVdQLWs5HSjIVQtlHY/T4pYnOc6TwS5ZP9eXmnvEuOfJ 3esClkXcen4XW0Sw2REzwmeN6/ZEJ+LQkX1HIlIgT90nPbKHhnxD7Bl78tqIUQwxfmab 3ywQ== X-Gm-Message-State: AOJu0YxNmBJ97nJdFx8wkrS+LMnYUj8L/5N8TAP8jvGJCbWP+5rBv+Qm Z67r3Us9W9/16tprfHVjl41FJt7areswt/HTxZmkJtJ1B9iN1r+WCHZpzjbXKk+Px8eTo0e8cVH 7q2c= X-Google-Smtp-Source: AGHT+IG5JdMhVPT5F54fIN6YqFwDFs7Cm5zrixUzsavN15OfzHPy+sr2LWGoRtoJoaUJu6LfFCXExA== X-Received: by 2002:a17:90b:1a92:b0:2e2:c15f:1ffd with SMTP id 98e67ed59e1d1-2e9b171f18amr32282249a91.14.1731609903738; Thu, 14 Nov 2024 10:45:03 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ea06ef71a6sm1517611a91.8.2024.11.14.10.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 10:45:03 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Anatoly Burakov , Tyler Retzlaff Subject: [PATCH v4 02/12] eal: add new secure free function Date: Thu, 14 Nov 2024 10:43:24 -0800 Message-ID: <20241114184452.31854-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241114184452.31854-1-stephen@networkplumber.org> References: <20241114011129.451243-1-stephen@networkplumber.org> <20241114184452.31854-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..c9e0f4724f 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_sensitive(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_sensitive(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..d472ebb7db 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_sensitive(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..fa67ff44d5 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_sensitive; }; INTERNAL { -- 2.45.2