From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) by dpdk.org (Postfix) with ESMTP id 00E6310A3 for ; Wed, 18 Jul 2018 23:44:38 +0200 (CEST) Received: by mail-pf0-f194.google.com with SMTP id c21-v6so2808564pfn.8 for ; Wed, 18 Jul 2018 14:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=8In44YRJb0JxnX4dKoCxmDEWRLs1g1WT+7kXsrEjsZw=; b=qEZpZvn2tLsbcdw8OyvdHNZy/xeZcp4cs8pdeJJZf/ISrD3E4SPOSr08UKnaDO2NIt LuLfrzD+vGV6pCGxGAV1NfNoYntTO3ttlMpjYJ/8T4fwTr/k5Xy2PuR0PtYq26AXLccx xD4CMMxPFbnd46pf7+0o6PSbBtwRfMUdXDk6MWJyw3fEe+I2HRzeZe3HQxqeQ7KWZco2 wWV6Hk9LgReozD7ettciBBpo2S48KKnSuW0w2ebyIbV4uvO++Lx+qH6wisAMNvkysivm Fx0kJqnGyV082JUHmYrgqIT0IC/erhFg28PRnk628VuiET4UxYNjy4VEzoYwZhKL5qL5 C8Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8In44YRJb0JxnX4dKoCxmDEWRLs1g1WT+7kXsrEjsZw=; b=tjSsY/bbZoKyNC6cLFflO5SrBrHEFLCfg1BykEtP1zIVwrHaOz+XIjmUaZqajvG/uY 9884nTpNuFVZW36saOahOkf+7nPLe3Go2WodxBrQrxJuv1Gq9Jkx4lGlYZlK7Ok1ATsl h0lqe9ylCNsG1eBPbZ8P5grqSJ1Z8QJwHWpnTqza0B5d6yEEBb6FGYryzw8Qk2dXCUE6 Skkj6uFUKtF/gQbNDwCqdymM8gJsjM3EFxrOD8wtPuaDXwuR+stYqVVGmr5jjAvS+IP4 BZqbSXmJuOKlSrOE4zuC2hd6KK19sE0OvpGYIM3mrSjw/KnSsBTiqZKxSh7XmGJMokvQ +KZA== X-Gm-Message-State: AOUpUlEpCmmxv26fAyk2Q1ST7RIXxa4oRFivJUrJrZYihphSnvof2Zli ulwGDfm9U+pPG/ERxmSVFadcxA== X-Google-Smtp-Source: AAOMgpeM+Ykm0aTkwtf2igfQxXxK+dx5O7nc/jXLwkmDLUKkKVHEeP0mxLppDItV/XPEnqOJtHvCxg== X-Received: by 2002:a63:8749:: with SMTP id i70-v6mr7458245pge.325.1531950277913; Wed, 18 Jul 2018 14:44:37 -0700 (PDT) Received: from xeon-e3.wavecable.com (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id u42-v6sm14864609pgn.1.2018.07.18.14.44.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 14:44:36 -0700 (PDT) From: Stephen Hemminger To: sergio.gonzalez.monroy@intel.com Cc: dev@dpdk.org, Stephen Hemminger Date: Wed, 18 Jul 2018 14:44:34 -0700 Message-Id: <20180718214434.608-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.18.0 Subject: [dpdk-dev] [RFC] mem: poison memory when freed X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jul 2018 21:44:39 -0000 DPDK malloc library allows broken programs to work because the semantics of zmalloc and malloc are the same. This patch changes to a more secure model which will catch (and crash) programs that reuse memory already freed. This supersedes earlier changes to zero memory on free and avoid zeroing memory in zmalloc. Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/malloc_elem.c | 5 ++++- lib/librte_eal/common/rte_malloc.c | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/malloc_elem.c b/lib/librte_eal/common/malloc_elem.c index efcb82677198..62cc0b385c0c 100644 --- a/lib/librte_eal/common/malloc_elem.c +++ b/lib/librte_eal/common/malloc_elem.c @@ -23,6 +23,8 @@ #include "malloc_elem.h" #include "malloc_heap.h" +#define MALLOC_POISON 0x6b /**< Free memory. */ + size_t malloc_elem_find_max_iova_contig(struct malloc_elem *elem, size_t align) { @@ -531,7 +533,8 @@ malloc_elem_free(struct malloc_elem *elem) /* decrease heap's count of allocated elements */ elem->heap->alloc_count--; - memset(ptr, 0, data_len); + /* poison memory */ + memset(ptr, MALLOC_POISON, data_len); return elem; } diff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c index b51a6d111bde..b33c936fd491 100644 --- a/lib/librte_eal/common/rte_malloc.c +++ b/lib/librte_eal/common/rte_malloc.c @@ -70,7 +70,11 @@ rte_malloc(const char *type, size_t size, unsigned align) void * rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket) { - return rte_malloc_socket(type, size, align, socket); + void *ptr = rte_malloc_socket(type, size, align, socket); + + if (ptr != NULL) + memset(ptr, 0, size); + return ptr; } /* -- 2.18.0