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 6B9F445A6D; Mon, 30 Sep 2024 20:47:53 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7B52B40DD2; Mon, 30 Sep 2024 20:46:39 +0200 (CEST) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by mails.dpdk.org (Postfix) with ESMTP id CC4CD4069D for ; Mon, 30 Sep 2024 20:46:24 +0200 (CEST) Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7db908c9c83so2898405a12.2 for ; Mon, 30 Sep 2024 11:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727721984; x=1728326784; 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=vTDAOq9sZl6RcrZrgnNFhZwuoC9LrV8s8SNPYB62+ln61SYorJd+bunTPkjWkRrJlP uFMp7/ikigo9AIGQD+QLusI6UZQlDLcSDSxnjq18hmPALSQ4l6I+dw3eyO7Sq0qAIy6Q 0xtvKU6DqJTaPI2VUoVEhUWjcEzit254QFqGHSxatkHu/TzexXiWpqrxy2ayZXQVY4E9 Mu519SEGrPxvkgJj3IGWcOVheTMVvVmM4pHVtM0IPL6Jll3Wd3QCkEpHxFFuS7VfoqcW G/ptQWkFU9ngOe1+72qCaIo/xe7aWODUb4/9dO1QWub4GSaDiipsaWvuuDrlMYWXxIZx JQQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727721984; x=1728326784; 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=xTeOIMI615XusN0/gm4EsvKDqXls+k3Dq1izKEZCOJXVbGwnpY85oQ9tv/ADDY4nKm OpJKphXlIOIftruOBUeOBsmO6zJsebZ4XvrCPugNafGK/cKSF43Ree17fBVKEdLKmPmz uAzqMo51byZi1ZvEytX2qwqke0hvftM8zqtCFXOQpECgjv/6c+YcSNat3o73goMYZPuz 1Pwf/jN/FYSlST5gTjSGmRCxBFvAkKZhu5FGTETPZQggZUnj3+CW0jZ1v62g/xl8pFAy nPoeHGAnbCcjeWUWdJrObEotbYlGJccR3/1qRrzgT9LH6r6oJG0vtFjAG99VAtLnmTGV P6Sg== X-Gm-Message-State: AOJu0YwP/7ZQpBgTknvFdVOzNJIuJ382YooXe+HLsquJ4nmMpJOCxqE9 GdL67MqW974EciTyL/FpZEy2lTOXHL/9LHiGyuERZ4+mas7/bFa1XS1dbK57hztY8DeIBSo2rlk F5HMbZQ== X-Google-Smtp-Source: AGHT+IHwoWbtT3uMqrpPV8E/rmViESw0jr/xbBWad71R0J0YkhtitNDGWupql6uoT1DIVpo+jjcekQ== X-Received: by 2002:a05:6a20:c990:b0:1d0:7df2:cf39 with SMTP id adf61e73a8af0-1d4fa64d6bamr18024260637.7.1727721984056; Mon, 30 Sep 2024 11:46:24 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b264bcca6sm6581895b3a.78.2024.09.30.11.46.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 11:46:23 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , junfeng.guo@intel.com, Jingjing Wu , Xiao Wang , Beilei Xing Subject: [PATCH v4 16/17] common/idpf: fix use after free due Date: Mon, 30 Sep 2024 11:44:10 -0700 Message-ID: <20240930184600.7092-17-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240930184600.7092-1-stephen@networkplumber.org> References: <20240927204742.546164-1-stephen@networkplumber.org> <20240930184600.7092-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