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 E4EE945A7E; Tue, 1 Oct 2024 18:38:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E468C40DD3; Tue, 1 Oct 2024 18:37:38 +0200 (CEST) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mails.dpdk.org (Postfix) with ESMTP id 34C2C4069F for ; Tue, 1 Oct 2024 18:37:30 +0200 (CEST) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-71dc4451fffso355737b3a.2 for ; Tue, 01 Oct 2024 09:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727800649; x=1728405449; 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=kXH/pUywnL3F195bWRszKKkx1NC1oIJgmdXXUPGOHF/6PO1j7ea/jL7iHXREEDUcfk AGMEE2iP2dCoT4FINBGyTh8YHLmB1MGALyxP1ERbkz+A0F+0UldZIXacwWUvZV9nARrs 8FohBFRoN/12F20x9nCqeNp78S7zhNwwWc4QZmoE3HYSHM1wZDAsE5OySCIB586igvbq Yka5zaO3eladAG9GFD25DhMH2V0EElb6BzfLS0oZFm8cORG/CkNhTutibJgcvVEKGyva Ub+W78PxYd/Q1e57JT3RzSmc0+dU5oPziBH9OBV3yrDwpWgMv/ekgF0oii7kSZjWcgAV /KeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727800649; x=1728405449; 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=K/dtswQMvFMTiy1PdzVdiL25MnD4gTwzd2sXrs7iIP/a41BcOekqxVa0+KIhyzrgd+ USrLe06Pi/ysqFbS2x5/38r98Ae7mgpzAv7bywPiSWn+Wnu6CR4QbKBpn7uvEuXUWuvc 9y+Tnd2eqcx1TAPtMmILXR/L6pgLsOqyxauYBpKK/fT2rJE9Z6C6j6dw6c/35rYZpHqt m4UPcgbvPuNX1JTD04r9NNT1rkSwn4vJyH4XXKhjdCM2EijnnNjRPcmqvqmby2QCHJ1B ositFUNoPLn6gsyQEr9DaC5B4xecsFba+ewSURCFe5bxm2TTTitATYOqzFejqeicIj4C iuQg== X-Gm-Message-State: AOJu0YwxJk3ISLBjSwFRd42bYDwLAtd21Q/NZ1nZZe9Sj/xjYBpo6vJh Xat1S9wRn8La7V2RVJWVNVS3Ev3es5FDCsX38HNNFScB8DHoU23fv5639RgaclWIyELbRALw5GZ QZ/A= X-Google-Smtp-Source: AGHT+IG4E6wkCNsNGZKROwh0VteCGzcvCEWNXSNvC0fQM3u1Pc7762AKp+R1NJBm41vFL5yboTE1JQ== X-Received: by 2002:a05:6a00:10d2:b0:714:1ca1:7134 with SMTP id d2e1a72fcca58-71dc5d42599mr342621b3a.18.1727800649392; Tue, 01 Oct 2024 09:37:29 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b26518818sm8213565b3a.129.2024.10.01.09.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 09:37:29 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , stable@dpdk.org, Rosen Xu , Tianfei Zhang , Andy Pei Subject: [PATCH v5 12/17] raw/ifpga/base: fix use after free Date: Tue, 1 Oct 2024 09:35:35 -0700 Message-ID: <20241001163708.355128-13-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241001163708.355128-1-stephen@networkplumber.org> References: <20240927204742.546164-1-stephen@networkplumber.org> <20241001163708.355128-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