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 CDD9C45AE3; Tue, 8 Oct 2024 18:51:06 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C8FC941140; Tue, 8 Oct 2024 18:49:19 +0200 (CEST) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mails.dpdk.org (Postfix) with ESMTP id 236B440DDC for ; Tue, 8 Oct 2024 18:49:08 +0200 (CEST) Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-20ba9f3824fso44736025ad.0 for ; Tue, 08 Oct 2024 09:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1728406147; x=1729010947; 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=oUVqBA9TkOKHy45oGSv7pOvWAx2ksBqPQlUyI811wtk=; b=qQfpoaf26UEb7ZhSzyKtvFz7o32GfP0ksIQ+7kN7hhG5uk6LuFvXIdLk1O7reSP7UM thu+1VkqjxZO55hZL/Nkv9Z+7PSxIDNR79tcLRHL+XTM3/uA3gJFPm7Ymjp7QLDucahH NUVNEi6r6Dw+mupfkU4YbW6bpwHps2QAcOfFf99AzTowS7QoRO+Q3RZHaVifNYU5zbY8 EqNenkvtwnrY37fGCCLmcmyShb7bPh8xWHnr8BglC/EIgkqGpI8lzn2cmlXT9aabP4AO 1aisuXrO0Aqu9psEJZetHssMXXLHecBYov+8999EoZXGf5LACN3DR6JoSKqDHnlhu1Xx /UeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728406147; x=1729010947; 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=oUVqBA9TkOKHy45oGSv7pOvWAx2ksBqPQlUyI811wtk=; b=t14TlqnawacZ4zuTkL2YDRSiMDjO6OkN1YupXSD6ovgI7HNfmXj7zNxItgKtpcbPMp aj52Wad+SAwY787V6jpHFFMK2Tpbc8EqQCT+Hl+HKKcWZtB8uqn/l9LOJZYtV/+39wts UnTcQeoi+hwvSaPJY2oLPrwWZ9kiybw9g/f/VACfVMxVdOQO4N8JI7WBFrRon7Fw7U8j LcxdRQJtZ1ap6xFQYq3GHnc0uxH1OxB378lwnVFujUIc1LmWV4EMW4oan0I/9Ptj8R4u sJzqQra0Cj0TPoproRdD3VAzkdnYIwZOtmC+armdrTF9+HfbDC+izCZLNiziyAyjDYgf XO8Q== X-Gm-Message-State: AOJu0Yxwf0Ih3Qci0QX1/cqSd8MZNS5wRxdLYdIo8zr7X2RXgnvePQWq tXWr0Dxx4y0TKMu0iDeQBOxH0W3rjv5oZ+Tpfax4M3KFDaA9/iBW9BZ0FYVHDnt+TYaveuVeVOH Orbx5fA== X-Google-Smtp-Source: AGHT+IGHAFkcQPFVdPKi9Oy/a3oHaVWlAK/IznH2eqMu8OV6ShXjmaSvYDgVR0ebaKLT9SMBuTjGyw== X-Received: by 2002:a17:903:228a:b0:20b:78de:c62c with SMTP id d9443c01a7336-20bfe29281amr250530435ad.39.1728406147352; Tue, 08 Oct 2024 09:49:07 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c54056bd9sm13832965ad.85.2024.10.08.09.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 09:49:06 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , junfeng.guo@intel.com, Jingjing Wu , Xiao Wang , Beilei Xing Subject: [PATCH v9 16/17] common/idpf: fix use after free due Date: Tue, 8 Oct 2024 09:47:20 -0700 Message-ID: <20241008164842.139045-17-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241008164842.139045-1-stephen@networkplumber.org> References: <20240927204742.546164-1-stephen@networkplumber.org> <20241008164842.139045-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 e042ef871c..cf9e553906 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