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 0EA2045A7E; Tue, 1 Oct 2024 18:39:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0E3C44065B; Tue, 1 Oct 2024 18:37:44 +0200 (CEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mails.dpdk.org (Postfix) with ESMTP id E490A4069D for ; Tue, 1 Oct 2024 18:37:33 +0200 (CEST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-71798a15ce5so5170967b3a.0 for ; Tue, 01 Oct 2024 09:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727800653; x=1728405453; 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=AC6+8ukQue2BMq8mJkbAIhtSXLvqWNSJsJoOn0Ks0FQ=; b=bS0qQQ6BKZ0sUoGx81BWxQxPEAYhACtXvM/OgIIH4X2RIO1VSSUKktJgOI76xsc7Hh 93oBiXx3d0ksBlMx/n6xDPMb6H4kxs34IdtfEv24I8on1qIPeRFkEwK95sL0kmmgnuok 5Qadl9e8I3DKZ00Wlp5rPkuxT6l9sio7PMCUUMLs7BsVX0Z2NiHMSwUU/LNIXNt6irWC ovvBGRl0bwlUrKl+kpHWTiYpE6gyGqiSp0I0Hzvgwm7vrlY1vyb3nnfKBKxJVbyMxeW3 WXtBG/3LJVfJag9OQPSIx4f9co/L6QLMw1+PgyxfZXEkwBCkNT7GLWixktn5zC6Vh/DM z0Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727800653; x=1728405453; 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=AC6+8ukQue2BMq8mJkbAIhtSXLvqWNSJsJoOn0Ks0FQ=; b=t58F1CGL/IXYVjsT4fE5CWwq5QRu2uyOUhH0NFNMlUYkGQbQvYZPU782YrhSm9ODTD g3vIjybpiFaTxDegrqrKF9f4tcehi3ldm7mGSkR4XWdY0nLM+hh7GHeZ7Jak1MxxqxQ9 cse98gOIkMr+i6CkKshUnWN2+4KDtmU38nVszrwkCFVDBQMzHbrM3bXIwxFD6grXAP+5 Xx2y+Kcp81ZsNhY0htSj1x6cf7Soxrgl3FYspFk+ZaIw5vcJj1iXtA7YhBB967MSNJon 5+GZWaYPvBWjLicCbQws/pj4tkqLJEV0c8xIU5WLIQ8KR1bA2zDqbFbF7FIDbaYzZXSL FHXA== X-Gm-Message-State: AOJu0YzPCe4y+xyJsZAFvgKmF3LHtDHLvypu94kSTm6sxhg+JuDwmlPW 82hU4jeOLHYnxLmQKh79T1RXOrzn98/XzCqkYANiTmOJjQQlS/nwRUx1YBaNiFsfqvuh5rxU217 8Q1k= X-Google-Smtp-Source: AGHT+IFpggQWv9TIYsh0sddvlRSl27QbRwQyhD1rDvkiTagcx5r0EYwtFtl5jHB+qp1JK9AKV5cvJw== X-Received: by 2002:a05:6a00:2192:b0:719:110e:fc8f with SMTP id d2e1a72fcca58-71db79bb452mr7520244b3a.1.1727800653149; Tue, 01 Oct 2024 09:37:33 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b26518818sm8213565b3a.129.2024.10.01.09.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 09:37:32 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , junfeng.guo@intel.com, Jingjing Wu , Beilei Xing , Xiao Wang Subject: [PATCH v5 16/17] common/idpf: fix use after free due Date: Tue, 1 Oct 2024 09:35:39 -0700 Message-ID: <20241001163708.355128-17-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241001163708.355128-1-stephen@networkplumber.org> References: <20240927204742.546164-1-stephen@networkplumber.org> <20241001163708.355128-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 The macro in this driver was redefining LIST_FOR_EACH_ENTRY_SAFE as a simple LIST_FOR_EACH macro. But they are not the same the _SAFE variant guarantees that there will not be use after free. Fixes: fb4ac04e9bfa ("common/idpf: introduce common library") Cc: junfeng.guo@intel.com Signed-off-by: Stephen Hemminger --- drivers/common/idpf/base/idpf_osdep.h | 10 ++++++++-- drivers/common/idpf/idpf_common_device.c | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/common/idpf/base/idpf_osdep.h b/drivers/common/idpf/base/idpf_osdep.h index b2af8f443d..7dff9bc79c 100644 --- a/drivers/common/idpf/base/idpf_osdep.h +++ b/drivers/common/idpf/base/idpf_osdep.h @@ -341,10 +341,16 @@ idpf_hweight32(u32 num) #define LIST_ENTRY_TYPE(type) LIST_ENTRY(type) #endif +#ifndef LIST_FOREACH_SAFE +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST((head)); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) +#endif + #ifndef LIST_FOR_EACH_ENTRY_SAFE #define LIST_FOR_EACH_ENTRY_SAFE(pos, temp, head, entry_type, list) \ - LIST_FOREACH(pos, head, list) - + LIST_FOREACH_SAFE(pos, head, list, temp) #endif #ifndef LIST_FOR_EACH_ENTRY diff --git a/drivers/common/idpf/idpf_common_device.c b/drivers/common/idpf/idpf_common_device.c index 8403ed83f9..e9fa024850 100644 --- a/drivers/common/idpf/idpf_common_device.c +++ b/drivers/common/idpf/idpf_common_device.c @@ -136,8 +136,7 @@ idpf_init_mbx(struct idpf_hw *hw) if (ret != 0) return ret; - LIST_FOR_EACH_ENTRY_SAFE(ctlq, NULL, &hw->cq_list_head, - struct idpf_ctlq_info, cq_list) { + LIST_FOR_EACH_ENTRY(ctlq, &hw->cq_list_head, struct idpf_ctlq_info, cq_list) { if (ctlq->q_id == IDPF_CTLQ_ID && ctlq->cq_type == IDPF_CTLQ_TYPE_MAILBOX_TX) hw->asq = ctlq; -- 2.45.2