From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 738DAA04FC; Thu, 11 Jun 2020 03:02:51 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 03F242BF1; Thu, 11 Jun 2020 03:02:50 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 610A12BAB; Thu, 11 Jun 2020 03:02:48 +0200 (CEST) IronPort-SDR: YlDos+gS40ExoeJhHIJVm2Q+d75sPigjbhm5c7IJpQX43zS9/rWrEHZnC0Ov5Ceh21Kg7V+dWt PzsL8AHj7WFQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 18:02:46 -0700 IronPort-SDR: 1qcTkfsqWM5a7MSlPolQfv8KWNv7P9Cmp2oYMczDf+ubog/tSJJLwhSyKbIx5fqtNg0GtOx9wK GawDXaV6xpiQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,497,1583222400"; d="scan'208";a="306768893" Received: from dpdk_yexl_af_xdp.sh.intel.com ([10.67.119.201]) by orsmga008.jf.intel.com with ESMTP; 10 Jun 2020 18:02:43 -0700 From: Xiaolong Ye To: Olivier Matz , Thomas Monjalon , Konstantin Ananyev Cc: dev@dpdk.org, Xiaolong Ye , stable@dpdk.org Date: Thu, 11 Jun 2020 08:48:01 +0800 Message-Id: <20200611004801.105736-1-xiaolong.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200610150845.82462-1-xiaolong.ye@intel.com> References: <20200610150845.82462-1-xiaolong.ye@intel.com> Subject: [dpdk-dev] [PATCH v2] mbuf: fix out-of-bounds access 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" We should make sure off + size < sizeof(struct rte_mbuf) to avoid possible out-of-bounds access of free_space array, there is no issue currently due to the low bits of free_flags (which is adjacent to free_space) are always set to 0. But we shouldn't rely on it since it's fragile and layout of struct mbuf_dyn_shm may be changed in the future. This patch adds boundary check explicitly to avoid potential risk of out-of-bounds access. Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags") Cc: stable@dpdk.org Signed-off-by: Xiaolong Ye --- V2: put the check before accessing free_space lib/librte_mbuf/rte_mbuf_dyn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c index d6931f847..9d6388cff 100644 --- a/lib/librte_mbuf/rte_mbuf_dyn.c +++ b/lib/librte_mbuf/rte_mbuf_dyn.c @@ -71,7 +71,8 @@ process_score(void) for (off = 0; off < sizeof(struct rte_mbuf); off++) { /* get the size of the free zone */ - for (size = 0; shm->free_space[off + size]; size++) + for (size = 0; (off + size) < sizeof(struct rte_mbuf) && + shm->free_space[off + size]; size++) ; if (size == 0) continue; -- 2.17.1