From nobody Thu Mar 5 06:32:15 2026 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4C631A83F9 for ; Mon, 16 Feb 2026 20:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771273871; cv=none; b=G3kGFLQ3wT9gb4/6hohLI0VgwiUPy8jj/I6yEzqNUb42iisPeThEWKb3Ibpe5sWllwT2x+L/2wSg/hKrXkx/k+AXNMerfddWmnxi7AHX0yIW6nzvl+yhtoM1N4g5pw+7db38dJiTPW7xayIcJbmBH8F8AbSLfjaDAE2LXhu8FeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771273871; c=relaxed/simple; bh=nW1kcY+TgJdL+e/kVHTD86xB9DuQqwF/pa2u8gzwvpo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DSJR4EQTgMAup+iIuUlwz2g1xEUjEmZZ3dTBZR4TO9f1DEZfbUeY+8cEoVrzTQK+BL7StWJskW1Zjx65zYAzjm09BCzX+OMseOrKb8E8OPF1CttTr9RKRo/vM5FcEKjPpJ9C36IWF50TR/AgIN1pDTEqLzfQK62bLFNi4NhgP50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GU4vFCwq; arc=none smtp.client-ip=209.85.210.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GU4vFCwq" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-7d18d02af68so2408881a34.2 for ; Mon, 16 Feb 2026 12:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771273869; x=1771878669; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pvIiweXEOPmG0CyDttbFAF8NZzA7a2gxvmfbKv0pvxQ=; b=GU4vFCwqekeu4g03NytUrBVRlu6IQ36yNbr3ixEgt7FbxwQpxvRQN0SvRTIFFdFK42 Pkz4+TykvODO07LxNdusgOqkax+QUCYO2vYzfOQwOa7T2mDChJaY9kNtf6nw7ZohSMnr rrfyicmd11LbUtSA4ftsbAVdDBYBHQBtWV2dktJGr8kxUCybDwTzXEbKg+IxpUXPAn7x KR5+yklrJclHDZr0czr22/VE0gLi7psh+hxX3Xi9FQv+nFE7KxQVNzC9j8n0ulwWc85/ 2aR/RNdmITLxpYg+5k7JZe5onB5kVhYnz8ntCij5ENve+jrMtPrMH+6ovTJK/yU2TyYy vXgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771273869; x=1771878669; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pvIiweXEOPmG0CyDttbFAF8NZzA7a2gxvmfbKv0pvxQ=; b=TE0w7ziedt4QyhAFfM/QcxrPmDr4mzLQrZRyL2LLjVtyVILNha7VqRcKSgvBHuzQ/9 mAfYHPkpnFngki1gl/KBXFxACrhuQV9g+xV9JewL7bwcAhLNA+u4nIZ3OPbg9Z5BGboG Obzsu+VUyMm0rlcn2PpSzMi/vPYVV+DzmYrpgXT7YyuhjTkr4nd6T13mqZNLzzQtam4i l8pjaMqy5CvJ90RfuB4+CfBHzO9mz3n9wjBiJTFKcBC9RZ4FHI1r+AHuqb+OjdmKA1yz fpg7v2u1Q/d0DT7SoFO9m7SGGpwCi6XJT8VLYNNT8nnwXMT00M8w5lIielTBQEJ/VNfk DTNQ== X-Forwarded-Encrypted: i=1; AJvYcCViw6vJSSnKx6nSgaomcwSWtshmPzVPV7L8/zWCdM1HDCxDLaUz2+3IiAZZgx5he65aYUhMpdSXa3oadtU=@vger.kernel.org X-Gm-Message-State: AOJu0YyQ4DrgPiFnAXfAhenbKtN9/GuzxWnLOoPCN667RPZiEX2uSc1D 9X5Yr8zjK9M3TJ6l+wizV8Di2gojIjGYpnDx0CKVvWHBhQAeE5Gi4WeC X-Gm-Gg: AZuq6aJ2bAXuo58HaSUCCtUF9ehWnGr1envBgcnPLZyduViUyU9yn5zsWhK55b6RakN D2imkIBbKqHu9i32e+6cRumStbDvDEQgGM6wHz9TCxU2fmmOTgyWc+QybOkxvNbZpoHez1s/h36 5sdqWrvdGsPUei9c7u0YmDt858am4N28zwQ7jhOFDfuhuXhbFyJepoxfNiPu2gnq9xJ2vZMEyuj JfgFHJLAzAU6EA/u1ZXL8JK4MAhA3lqsfp1gI8xLLFoVqk+ivZrRt9zQLT9+xmU7w3hyNQMl/LK BkqbiEwKu1zQuzEq8VKm2TQbaYIE93L1hGPOGUkAVobWZlSQ7y429Ze5qHHTF6gcjCJiUI1/53Z cpS0HPuwE6uwpCD5Jbq133d1oXzscbDnNvA3zHNbedoK75FKvkbgqhYxYf/VAr8gBUn5TXN5gyZ rIjM7d1GnWVeZnYIWsONPrhIJVCZF3sZwGAcUMFXIszOZfcC5+2q8dFwU= X-Received: by 2002:a05:6830:6419:b0:7d1:586a:32a2 with SMTP id 46e09a7af769-7d4c2c20cd9mr9645370a34.0.1771273869567; Mon, 16 Feb 2026 12:31:09 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7d4a7530a8bsm14343667a34.4.2026.02.16.12.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Feb 2026 12:31:09 -0800 (PST) From: Jiasheng Jiang To: Nilesh Javali , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , Himanshu Madhani , Arun Easi , Shyam Sundar , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jiasheng Jiang Subject: [PATCH] scsi: qla2xxx: Fix resource leak and metadata corruption in default_item cleanup Date: Mon, 16 Feb 2026 20:31:05 +0000 Message-Id: <20260216203105.9056-1-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The qla2xxx driver utilizes a pre-allocated fallback item (vha->default_item) to handle purex items during low memory (OOM) conditions. Its lifecycle is managed via an atomic counter (in_use). However, the cleanup paths for this item exhibit two critical inconsistencies that lead to resource leaks and potential crashes: 1. In `qla24xx_free_purex_list()`, when the default_item is encountered, it is removed from the list and skipped via `continue`, but its `in_use` atomic counter is never decremented. Consequently, once the default_item is used for the first time, its reference count remains elevated permanently, rendering the fallback mechanism dead in all subsequent OOM scenarios. 2. In `qla24xx_free_purex_item()`, the function attempts to reset the default_item using a blanket `memset()`. This non-atomic operation not only clobbers the `in_use` counter but also zeroes out essential metadata pointers, most notably `item->vha`. If this default_item is subsequently reallocated, any dereference of `item->vha` will result in a NULL pointer dereference and a kernel panic. Fix both issues by replacing the destructive `memset()` and the leaky `continue` path with a unified, safe atomic reset of the `in_use` counter (`atomic_set(&item->vha->default_item.in_use, 0)`). This properly relinquishes the item for future allocations while preserving its structural integrity. Fixes: 0972252450f9 ("scsi: qla2xxx: Fix crash during module load unload te= st") Fixes: 62e9dd177732 ("scsi: qla2xxx: Change in PUREX to handle FPIN ELS req= uests") Signed-off-by: Jiasheng Jiang --- drivers/scsi/qla2xxx/qla_os.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c index a88b460641f2..a424dc6b093e 100644 --- a/drivers/scsi/qla2xxx/qla_os.c +++ b/drivers/scsi/qla2xxx/qla_os.c @@ -3984,8 +3984,10 @@ qla24xx_free_purex_list(struct purex_list *list) spin_lock_irqsave(&list->lock, flags); list_for_each_entry_safe(item, next, &list->head, list) { list_del(&item->list); - if (item =3D=3D &item->vha->default_item) + if (item =3D=3D &item->vha->default_item) { + atomic_set(&item->vha->default_item.in_use, 0); continue; + } kfree(item); } spin_unlock_irqrestore(&list->lock, flags); @@ -6467,7 +6469,7 @@ void qla24xx_free_purex_item(struct purex_item *item) { if (item =3D=3D &item->vha->default_item) - memset(&item->vha->default_item, 0, sizeof(struct purex_item)); + atomic_set(&item->vha->default_item.in_use, 0); else kfree(item); } --=20 2.25.1