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 12E1445A9F; Wed, 2 Oct 2024 20:40:48 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 58DC740A71; Wed, 2 Oct 2024 20:39:48 +0200 (CEST) Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) by mails.dpdk.org (Postfix) with ESMTP id 2A73C4067C for ; Wed, 2 Oct 2024 20:39:39 +0200 (CEST) Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3e03d17365bso125691b6e.1 for ; Wed, 02 Oct 2024 11:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727894378; x=1728499178; 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=a8TggGBBclbKESNHOQ2IUVYvKHqZZVyWx4BW00yeM0V/pxeJj1WRExURbCrbYPaM6c 5PyYyatsMVfgxnGoa9zOya6mSbQmfJzHZmMbmMhUMInhCCPGxvGH9DpIeLAbwdtlUCj7 u9mKXKnJ4/pNQjfrt9rOgbKGjB2akd0Nt9o4BRU5vpd8f1fyixmpZ3nm8BQRS+qDZmpT Re686KL26UHmjReiHaB3fU8FrceEIuQRwkjUU6oyXfTsxUPXX8hi6Z6y21eGqd/PbLxc qfqKbnpz/kgJeBhel8Gpwm4z277kwpvV7C4HZtCgy4V1EJvfjcQacKSuCEEa1q6BIOGx FLow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727894378; x=1728499178; 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=hgonzRad33B/HUg2ncACkz0oRWbCL9SpwdMfUQ0n3zG84a/M+29owS62c3QgltQE1O 72lJQhroPP0mZcfSNMtPUrc1RQvcc+Np3EI3iyY59TIjy5gwxMNdWBTjT/eEuyYIk4cm JqlatrWNdHYssEFTKluG+Hq5qdxqJov7p6BdF4Mn/VGxKtbsx0uP7EIWDrob61+Og2h4 YC2qVw9ukanjZSNJ0pn6z0HbYSHFviGZa6VwmtshjYuqjVhk86viYwZYjmz18liyqHJY r4uwI6tPaG5WDgZIJ5PFXhf5DdPy/uDc+rgMWmdW3jzB7eMXx8Khxz0nAK37dZlPtesG EWLQ== X-Gm-Message-State: AOJu0Yz9uhWPaqIumbd755yrxM5sceie3Bj4EnBjGgJhhTDNlqVZiyAy 35TLD2kHLHFLV/7YbMKd5KfNkTX7VXYMJXkc4aR8TWaV8ovBqvUBWRLHhEHiy47XnSToJy3DoPn t X-Google-Smtp-Source: AGHT+IGnyyPXdqWR2rNIW0Gm1aVmy5ep0yWsq5kVQV2gtcTagJMfZRIJeo+VbIAtj3ashZslGzOj1A== X-Received: by 2002:a05:6808:384b:b0:3e0:4546:49a1 with SMTP id 5614622812f47-3e3b4169f00mr4149164b6e.35.1727894378356; Wed, 02 Oct 2024 11:39:38 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b2649b0bdsm10104362b3a.34.2024.10.02.11.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 11:39:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , stable@dpdk.org, Rosen Xu , Andy Pei , Tianfei Zhang Subject: [PATCH v7 12/16] raw/ifpga/base: fix use after free Date: Wed, 2 Oct 2024 11:37:50 -0700 Message-ID: <20241002183918.161656-13-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241002183918.161656-1-stephen@networkplumber.org> References: <20240927204742.546164-1-stephen@networkplumber.org> <20241002183918.161656-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