* [PATCH 1/2] iscsi_tcp: do not bind sockets that already have extra callbacks
@ 2024-03-18 19:49 Khazhismel Kumykov
2024-03-18 19:49 ` [PATCH 2/2] iscsi_tcp: disallow binding the same connection twice Khazhismel Kumykov
2024-03-19 19:28 ` [PATCH 1/2] iscsi_tcp: do not bind sockets that already have extra callbacks Mike Christie
0 siblings, 2 replies; 5+ messages in thread
From: Khazhismel Kumykov @ 2024-03-18 19:49 UTC (permalink / raw
To: Lee Duncan, Chris Leech, Mike Christie, James E . J . Bottomley,
Martin K . Petersen
Cc: open-iscsi, linux-scsi, linux-kernel, Khazhismel Kumykov
This attempts to avoid a situation where a misbehaving iscsi daemon
passes a socket for a different iSCSI connection to BIND_CONN - which
would result in infinite recursion and stack overflow. This will
also prevent passing *other* sockets which had sk_user_data overridden,
but that wouldn't have been safe anyways - since we throw away that
pointer anyways. This does not cover all hypothetical scenarios where we
pass bad sockets to BIND_CONN.
This also papers over a different bug - we allow a daemon to call
BIND_CONN twice for the same connection - which would result in, at the
least, failing to uninitialize/teardown the previous socket, which will
be addressed separately.
Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
---
drivers/scsi/iscsi_tcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 8e14cea15f98..e8ed60b777c6 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -725,7 +725,7 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
}
err = -EINVAL;
- if (!sk_is_tcp(sock->sk))
+ if (!sk_is_tcp(sock->sk) || sock->sk->sk_user_data)
goto free_socket;
err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
--
2.44.0.291.gc1ea87d7ee-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] iscsi_tcp: disallow binding the same connection twice
2024-03-18 19:49 [PATCH 1/2] iscsi_tcp: do not bind sockets that already have extra callbacks Khazhismel Kumykov
@ 2024-03-18 19:49 ` Khazhismel Kumykov
2024-03-19 19:33 ` Mike Christie
2024-03-19 19:28 ` [PATCH 1/2] iscsi_tcp: do not bind sockets that already have extra callbacks Mike Christie
1 sibling, 1 reply; 5+ messages in thread
From: Khazhismel Kumykov @ 2024-03-18 19:49 UTC (permalink / raw
To: Lee Duncan, Chris Leech, Mike Christie, James E . J . Bottomley,
Martin K . Petersen
Cc: open-iscsi, linux-scsi, linux-kernel, Khazhismel Kumykov
iscsi_sw_tcp_conn_bind does not check or cleanup previously bound
sockets, nor should we allow binding the same connection twice.
Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
---
drivers/scsi/iscsi_tcp.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index e8ed60b777c6..8cf5dc203a82 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -716,6 +716,9 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
struct socket *sock;
int err;
+ if (tcp_sw_conn->sock)
+ return -EINVAL;
+
/* lookup for existing socket */
sock = sockfd_lookup((int)transport_eph, &err);
if (!sock) {
--
2.44.0.291.gc1ea87d7ee-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] iscsi_tcp: do not bind sockets that already have extra callbacks
2024-03-18 19:49 [PATCH 1/2] iscsi_tcp: do not bind sockets that already have extra callbacks Khazhismel Kumykov
2024-03-18 19:49 ` [PATCH 2/2] iscsi_tcp: disallow binding the same connection twice Khazhismel Kumykov
@ 2024-03-19 19:28 ` Mike Christie
1 sibling, 0 replies; 5+ messages in thread
From: Mike Christie @ 2024-03-19 19:28 UTC (permalink / raw
To: Khazhismel Kumykov, Lee Duncan, Chris Leech,
James E . J . Bottomley, Martin K . Petersen
Cc: open-iscsi, linux-scsi, linux-kernel, Khazhismel Kumykov
On 3/18/24 2:49 PM, Khazhismel Kumykov wrote:
> This attempts to avoid a situation where a misbehaving iscsi daemon
> passes a socket for a different iSCSI connection to BIND_CONN - which
> would result in infinite recursion and stack overflow. This will
> also prevent passing *other* sockets which had sk_user_data overridden,
> but that wouldn't have been safe anyways - since we throw away that
> pointer anyways. This does not cover all hypothetical scenarios where we
> pass bad sockets to BIND_CONN.
>
> This also papers over a different bug - we allow a daemon to call
> BIND_CONN twice for the same connection - which would result in, at the
> least, failing to uninitialize/teardown the previous socket, which will
> be addressed separately.
>
> Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
> ---
> drivers/scsi/iscsi_tcp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
> index 8e14cea15f98..e8ed60b777c6 100644
> --- a/drivers/scsi/iscsi_tcp.c
> +++ b/drivers/scsi/iscsi_tcp.c
> @@ -725,7 +725,7 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
> }
>
> err = -EINVAL;
> - if (!sk_is_tcp(sock->sk))
> + if (!sk_is_tcp(sock->sk) || sock->sk->sk_user_data)
> goto free_socket;
>
> err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
Reviewed-by: Mike Christie <michael.christie@oracle.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] iscsi_tcp: disallow binding the same connection twice
2024-03-18 19:49 ` [PATCH 2/2] iscsi_tcp: disallow binding the same connection twice Khazhismel Kumykov
@ 2024-03-19 19:33 ` Mike Christie
2024-05-23 22:25 ` Khazhy Kumykov
0 siblings, 1 reply; 5+ messages in thread
From: Mike Christie @ 2024-03-19 19:33 UTC (permalink / raw
To: Khazhismel Kumykov, Lee Duncan, Chris Leech,
James E . J . Bottomley, Martin K . Petersen
Cc: open-iscsi, linux-scsi, linux-kernel, Khazhismel Kumykov
On 3/18/24 2:49 PM, Khazhismel Kumykov wrote:
> iscsi_sw_tcp_conn_bind does not check or cleanup previously bound
> sockets, nor should we allow binding the same connection twice.
>
This looks like a problem for all the iscsi drivers.
I think you could:
1. Add a check for ISCSI_CONN_FLAG_BOUND in iscsi_conn_bind.
2. Have iscsi_sw_tcp_conn_stop do:
/* stop xmit side */
- iscsi_suspend_tx(conn);
+ iscsi_conn_unbind(cls_conn, true);
to clear the flag when we clean up the conn for relogin.
3. Fix up the other iscsi drivers so they call:
iscsi_conn_unbind(cls_conn, true);
in their failure paths so when they fail they clear ISCSI_CONN_FLAG_BOUND and
iscsi_conn_bind can be called on the retry.
> Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
> ---
> drivers/scsi/iscsi_tcp.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
> index e8ed60b777c6..8cf5dc203a82 100644
> --- a/drivers/scsi/iscsi_tcp.c
> +++ b/drivers/scsi/iscsi_tcp.c
> @@ -716,6 +716,9 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
> struct socket *sock;
> int err;
>
> + if (tcp_sw_conn->sock)
> + return -EINVAL;
> +
> /* lookup for existing socket */
> sock = sockfd_lookup((int)transport_eph, &err);
> if (!sock) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] iscsi_tcp: disallow binding the same connection twice
2024-03-19 19:33 ` Mike Christie
@ 2024-05-23 22:25 ` Khazhy Kumykov
0 siblings, 0 replies; 5+ messages in thread
From: Khazhy Kumykov @ 2024-05-23 22:25 UTC (permalink / raw
To: Mike Christie
Cc: Lee Duncan, Chris Leech, James E . J . Bottomley,
Martin K . Petersen, open-iscsi, linux-scsi, linux-kernel
On Tue, Mar 19, 2024 at 12:34 PM Mike Christie
<michael.christie@oracle.com> wrote:
>
> On 3/18/24 2:49 PM, Khazhismel Kumykov wrote:
> > iscsi_sw_tcp_conn_bind does not check or cleanup previously bound
> > sockets, nor should we allow binding the same connection twice.
> >
>
> This looks like a problem for all the iscsi drivers.
>
> I think you could:
>
> 1. Add a check for ISCSI_CONN_FLAG_BOUND in iscsi_conn_bind.
> 2. Have iscsi_sw_tcp_conn_stop do:
>
> /* stop xmit side */
> - iscsi_suspend_tx(conn);
> + iscsi_conn_unbind(cls_conn, true);
>
> to clear the flag when we clean up the conn for relogin.
>
> 3. Fix up the other iscsi drivers so they call:
>
> iscsi_conn_unbind(cls_conn, true);
I took a look, and it seems like the other drivers in-tree all use
iscsi_conn_unbind already, and iscsi_tcp is the odd one out - only
supporting stop_conn, and not setting ep_disconnect. Just swapping the
iscsi_suspend_tx call for iscsi_conn_unbind works, and makes sense to
me - but makes me wonder why we were using suspend_tx directly in the
first place.
The only other side effects I see are we set the session to failed
momentarily if we stop the conn while still logging in (iscsi_tcp will
quickly change this to _TERMINATE or _IN_RECOVERY once we hit the
stop_conn), which seems OK.
>
> in their failure paths so when they fail they clear ISCSI_CONN_FLAG_BOUND and
> iscsi_conn_bind can be called on the retry.
>
>
>
> > Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
> > ---
> > drivers/scsi/iscsi_tcp.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
> > index e8ed60b777c6..8cf5dc203a82 100644
> > --- a/drivers/scsi/iscsi_tcp.c
> > +++ b/drivers/scsi/iscsi_tcp.c
> > @@ -716,6 +716,9 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
> > struct socket *sock;
> > int err;
> >
> > + if (tcp_sw_conn->sock)
> > + return -EINVAL;
> > +
> > /* lookup for existing socket */
> > sock = sockfd_lookup((int)transport_eph, &err);
> > if (!sock) {
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-05-23 22:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-18 19:49 [PATCH 1/2] iscsi_tcp: do not bind sockets that already have extra callbacks Khazhismel Kumykov
2024-03-18 19:49 ` [PATCH 2/2] iscsi_tcp: disallow binding the same connection twice Khazhismel Kumykov
2024-03-19 19:33 ` Mike Christie
2024-05-23 22:25 ` Khazhy Kumykov
2024-03-19 19:28 ` [PATCH 1/2] iscsi_tcp: do not bind sockets that already have extra callbacks Mike Christie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).