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 E8D2145A6D; Mon, 30 Sep 2024 20:47:33 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2EA5840B9F; Mon, 30 Sep 2024 20:46:35 +0200 (CEST) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTP id C19EB40697 for ; Mon, 30 Sep 2024 20:46:22 +0200 (CEST) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-718816be6cbso4028885b3a.1 for ; Mon, 30 Sep 2024 11:46:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727721982; x=1728326782; 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=DdmWrgw09tadbkT7NdxbMIVnjX7ZkAUu8O2SQsLsM2k=; b=GqFObUvTMt0GUgM0UGcsYq9IWr4Bll4ke0kN9US30HRS5ZKHmFTYpKfwEo2kearPGV wd8rwfansJlZIE3/QoyUpFAtpG82qDB77FiX0y3zcntdvOux7GT7CQt24czSSMzBGhEh eoEmhDKVebO3fkvxq5yRjxhmCLpVek9r2na9FzhjECShX8tewOsLXfBXQkQN1h2YUTJo Gem/oguGPU0N+sNd1bZGWCwtzjjOmC8rE6IBM9I7v9n+tzrHP2f/6B1niI0/ZBfpOGwO +4b+cMa94ZOz0TDoYn5BIi3uQXcmGt6cuLRuP6fsxUXYpntuxtGDkqA4Mxc4/r+lPR8D isMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727721982; x=1728326782; 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=DdmWrgw09tadbkT7NdxbMIVnjX7ZkAUu8O2SQsLsM2k=; b=NBkGvcUGjKRMZy/Q1H9uLHlfNPJTcgndMEB6Vea9yRE+fMyDUKXkbfm12Qst6t5nUm jeLJ4hOPwfj4oQz02X/ZkbhxnJ0JtYlSuU+qsKo9i141iSOyIsH6zOH2yjJfyfp6Qwc8 dtffRLU8NjA5FmHLupCAsRlkpjWKIThAtxyldfKOMByK42wgie2AssxJVkJiwkPGHi4Q EGWsGzDgiLUE+YuYl73HD2W3C2DWKtcYnodaKexf7wfIIfMEzZFCFroSofhrbSia294d 5ezL23IL67W0ZYBnyXlYmwrJb0hx8IIg2x44XAi99fNk3kFntRok3P3g6T24HlwysQ56 K5+w== X-Gm-Message-State: AOJu0YxxY9wmQjkY3rVECMB8mxwL8Hx2TPs5vqbjwXIg3bxEjxLYsTuV sd33cP4dfvOQzKJfRiW3MlsPh78ks8rrd48uJnT3Em2VI55opDCi3xmqzTFcgtOIhVl3ioWoBxQ elJ/4CQ== X-Google-Smtp-Source: AGHT+IG2dGLcl2apzH07OQo+UlQ5zBGOxCElR5DnqYtB3LawHCPb9T48GsOrWTrgLh//POXFHTNB8A== X-Received: by 2002:a05:6a00:a14:b0:718:d5e5:2661 with SMTP id d2e1a72fcca58-71b25dbfb34mr22126821b3a.0.1727721980495; Mon, 30 Sep 2024 11:46:20 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 11:46:20 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , stable@dpdk.org, Rosen Xu , Tianfei Zhang , Andy Pei Subject: [PATCH v4 12/17] raw/ifpga/base: fix use after free Date: Mon, 30 Sep 2024 11:44:06 -0700 Message-ID: <20240930184600.7092-13-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 TAILQ_FOREACH() macro would refer to info after it had been freed. Fix by introducing TAILQ_FOREACH_SAFE here. Fixes: 4a19f89104f8 ("raw/ifpga/base: support multiple cards") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger --- drivers/raw/ifpga/base/opae_intel_max10.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/raw/ifpga/base/opae_intel_max10.c b/drivers/raw/ifpga/base/opae_intel_max10.c index dd97a5f9fd..d5a9ceb6e3 100644 --- a/drivers/raw/ifpga/base/opae_intel_max10.c +++ b/drivers/raw/ifpga/base/opae_intel_max10.c @@ -6,6 +6,13 @@ #include #include "opae_osdep.h" +#ifndef TAILQ_FOREACH_SAFE +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) +#endif + int max10_sys_read(struct intel_max10_device *dev, unsigned int offset, unsigned int *val) { @@ -746,9 +753,9 @@ static int fdt_get_named_reg(const void *fdt, int node, const char *name, static void max10_sensor_uinit(struct intel_max10_device *dev) { - struct opae_sensor_info *info; + struct opae_sensor_info *info, *next; - TAILQ_FOREACH(info, &dev->opae_sensor_list, node) { + TAILQ_FOREACH_SAFE(info, &dev->opae_sensor_list, node, next) { TAILQ_REMOVE(&dev->opae_sensor_list, info, node); opae_free(info); } -- 2.45.2