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 D4FED45A5D; Sun, 29 Sep 2024 17:43:04 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8C6AF40A77; Sun, 29 Sep 2024 17:41:45 +0200 (CEST) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id 733F540615 for ; Sun, 29 Sep 2024 17:41:33 +0200 (CEST) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-718816be6cbso3105013b3a.1 for ; Sun, 29 Sep 2024 08:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727624492; x=1728229292; 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=lBnCEROfs656ZmQYSub5rAbfdK6Glh0mxOvcKbXNfuw=; b=ZGZxcVVjKCYT9kvs4GBGUTCiTs2WWwOBK/EK/uedDYVKmhMxjqGG1W6yiUQyMxRnjS BBInLlrn5K6qJ7FFEx6IxIQGbVJJ7JgnAAVn+jMkUAN6o4I1cgvPlrXZfThugGIKs2lm rj5GNDUz3osPL4+C/Z21SikloVex9LNfuDp29gi1a3GNz1EUM5TD2FcI6weZAYLHLH8O g6nYEucGxSB3B4dtf/55a1nN+PRx6IvxeL6oan0G9GUw/6fHLmui7BS4yBSOWAJzVaMT O+11lf/sDdqm5R3lQp7WN0aqUj+MTZrj2JMMAJxAPn8sfaLMq9UnjQwIWjEIfSHXsq+I Va+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727624492; x=1728229292; 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=lBnCEROfs656ZmQYSub5rAbfdK6Glh0mxOvcKbXNfuw=; b=fttC26S7htwyE3BOnlgYVps7He/q7ytH4knpcxLEQF7OOPh478ecn0JjPyWoi3GTEl o2RWHbPDa8IJ9FBXsc9cdkJdDNE153LQKFUmEF77k9tjSwIT+gyxX6Yf6k1eyqWfys/d vxbDPXjP527XqOipUDD9rWZcDZfUsO7a0q/+rlhqbVZaM8cTCjZRl8SSeiusqZw3sSXO zfqhxTHQFgy6KVTbKY9g9TBQjVP3W3jgk9w1FSHI3zCWlzGiInvXRopuDGlvV+YBB3s1 hC2gUCA6m68dmFgJVq3w2iOTWMiFPV6q2QMfJQC6abJCYkjKhbpO63AvFqPMRXT0VRDL hAeg== X-Gm-Message-State: AOJu0Yy3F5zJhglwinPHWK1Agy+JAJNGvLXYx6y/WaUbPMihbKzqsfhH yrwW0Xr52iQ0ng6N+ABShKIFd2Zt3NICSyvL3LzGc5y4YyaVXPf5jTGUylu9p7fDycQBtEv/3tO SNBk= X-Google-Smtp-Source: AGHT+IGrs+1ZgpyA9hjZA4++KN7kZsvx/6wIAlnqdCmhXNbgIjuTUCDxN//IBlaUOHGm0kkXMFHNtQ== X-Received: by 2002:a05:6a21:e590:b0:1cf:2862:beca with SMTP id adf61e73a8af0-1d4fa6a148amr14437270637.13.1727624492651; Sun, 29 Sep 2024 08:41:32 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b2649c775sm4707416b3a.29.2024.09.29.08.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Sep 2024 08:41:32 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , junfeng.guo@intel.com, Jingjing Wu , Xiao Wang , Beilei Xing Subject: [PATCH v3 16/18] common/ipdf: fix use after free due Date: Sun, 29 Sep 2024 08:34:41 -0700 Message-ID: <20240929154107.62539-17-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240929154107.62539-1-stephen@networkplumber.org> References: <20240927204742.546164-1-stephen@networkplumber.org> <20240929154107.62539-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. One other place was using LIST_FOR_EACH_ENTRY_SAFE() incorrectly. 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..1491e2bd0d 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