Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68F203431F8 for ; Thu, 20 Aug 2026 02:26:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787192776; cv=none; b=kfkIkjWTVa2+U33tX5onByCnTNza9IAa4KyZg26HAUHPSGUcfuAoVNcI0m1spwDnbGndwhyXAaWf1/cSS2TdxHsAXN7gqmyOREMtGY8wbj92HeeDyfb95y6yg+JLs8r4pHP9nilg/2Yner8KJ+fUc6bhd3s/TDZHTR7sA/JEeIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787192776; c=relaxed/simple; bh=lPF61s3JsnHlatHg05b0kBF5D70tiSZQ9GgN64AghsU=; h=From:Subject:To:Cc:In-Reply-To:References:Content-Type:Date: Message-Id; b=Bl+xE/zH4Viti3j4b+Me9CrgW+aBQvlL7ZE3oJc9ZsvzQkeaeCHRaioyrRKMxySGaRPxDc8+pEGxRdUKom6bNflEO+CxEhVxCftswOkDbxATNUIMRyploaTs28/apHUEXu4PeQcKdmBrFNQStCtrnX7JH8XvUNMJzamRdC1llGM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c92Gw3hb; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c92Gw3hb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAEDD1F000E9; Thu, 20 Aug 2026 02:26:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787192775; bh=QE2Y6uX3XRX0AD9TfI+tpvYeiWiFwkcpD68Vp5tlQCw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=c92Gw3hbOF4hyyG/f0aLSbVGhLkSaH36w0r5soZM+rFqJXfHrdjAx5YMXz2iokx3a wOkzUN/+VLmkE7ESF7SfpiSyu8wACZ+ihx1PWliOgb58wXtYiNw6mDJzLDLUTq9u8K 8EHIKV/JZBM5bNonLMP+EaFNAho3dLcfTUmwAssdsNW8qoVdi9RMba/9rOmxHAQU7t g5UEXgVLaEoMeX4VtshL+WZ7D4hzLmeK5/x7aigvD0Vu6lGeUbYggoQq+JpMh4ifpj 0XfxABiAi/oP9IwUg2Nlk7fxY0UuDs9kE3/lSlbhucHQwQueM2ajKh660+Ha6kD9Vl 6kIQYwmIivNvA== From: sashiko-bot@kernel.org Subject: Re: [PATCH] scsi: iscsi: fix NULL pointer dereference in iscsi_sw_tcp_release_conn() Reply-To: sashiko-reviews@lists.linux.dev To: "Ye Bin" Cc: linux-scsi@vger.kernel.org In-Reply-To: <20260820020321.1537641-1-yebin@huaweicloud.com> References: <20260820020321.1537641-1-yebin@huaweicloud.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 20 Aug 2026 02:26:14 +0000 Message-Id: <20260820022614.CAEDD1F000E9@smtp.kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Thank you for your contribution! Sashiko AI review found 1 potential issue(= s) to consider: Pre-existing issues: - [High] Use-after-free of `iscsi_cls_conn` due to missing cancellation of = `cleanup_work` on release. -- --- Patch [1]: [PATCH] scsi: iscsi: fix NULL pointer dereference in iscsi_s= w_tcp_release_conn() --- commit bdfb05c9a6c008e559f81d0c3e5ffb712699e0cc Author: Ye Bin scsi: iscsi: fix NULL pointer dereference in iscsi_sw_tcp_release_conn() This commit fixes a NULL pointer dereference by setting the ISCSI_CLS_CONN_BIT_CLEANUP bit when userspace delivers STOP_CONN_TERM. This prevents concurrent execution of iscsi_stop_conn() and cancels or flushes the kernel connection cleanup work as needed. Fixes: 23d6fefbb3f6 ("scsi: iscsi: Fix in-kernel conn failure handling") > --- a/drivers/scsi/scsi_transport_iscsi.c > +++ b/drivers/scsi/scsi_transport_iscsi.c > @@ -2266,6 +2266,8 @@ static void iscsi_if_disconnect_bound_ep(struct isc= si_cls_conn *conn, > =20 > static int iscsi_if_stop_conn(struct iscsi_cls_conn *conn, int flag) > { > + bool cleanup; > + > ISCSI_DBG_TRANS_CONN(conn, "iscsi if conn stop.\n"); > /* > * For offload, iscsid may not know about the ep like when iscsid is [ ... ] > - if (flag =3D=3D STOP_CONN_TERM) { > - cancel_work_sync(&conn->cleanup_work); > - iscsi_stop_conn(conn, flag); > - } else { > + spin_lock_irq(&conn->lock); > + cleanup =3D test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags); > + spin_unlock_irq(&conn->lock); > + > + if (cleanup) { > /* > - * Figure out if it was the kernel or userspace initiating this. > + * If this is a termination we have to call stop_conn with > + * that flag so the correct states get set. If we haven't > + * run the work yet try to avoid the extra run. > */ > - spin_lock_irq(&conn->lock); > - if (!test_and_set_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) { > - spin_unlock_irq(&conn->lock); > + if (flag =3D=3D STOP_CONN_TERM) { > + ISCSI_DBG_TRANS_CONN(conn, > + "cancel kernel conn cleanup.\n"); > + cancel_work_sync(&conn->cleanup_work); [Severity: High] This is a pre-existing issue, but since we are modifying cleanup_work handling here, is there a risk of a use-after-free if the connection is destroyed before the work executes? Looking at iscsi_conn_error_event(), it queues conn->cleanup_work without taking a reference to the connection. If a session is torn down before the work executes (e.g. via device removal calling iscsi_remove_session()), iscsi_iter_destroy_conn_fn() drops the references: drivers/scsi/scsi_transport_iscsi.c:iscsi_iter_destroy_conn_fn() ... iscsi_remove_conn(iscsi_dev_to_conn(dev)); iscsi_put_conn(iscsi_dev_to_conn(dev)); This final reference drop triggers iscsi_conn_release(), which frees the connection memory: drivers/scsi/scsi_transport_iscsi.c:iscsi_conn_release() ... kfree(conn); Since iscsi_conn_release() does not call cancel_work_sync(&conn->cleanup_wo= rk), could iscsi_cleanup_conn_work_fn() execute and dereference the already freed conn struct? Should we be cancelling or flushing the work during iscsi_conn_release() to prevent this? > iscsi_stop_conn(conn, flag); > } else { > - spin_unlock_irq(&conn->lock); > ISCSI_DBG_TRANS_CONN(conn, > - "flush kernel conn cleanup.\n"); > + "flush kernel conn cleanup.\n"); > flush_work(&conn->cleanup_work); > } --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260820020321.1537= 641-1-yebin@huaweicloud.com?part=3D1