Re: [PATCH] iscsi_tcp: fix the NULL pointer dereference

From: Li Feng
Date: Sun Oct 10 2021 - 22:04:05 EST


Thanks,
Feng Li

<michael.christie@xxxxxxxxxx> 于2021年10月11日周一 上午12:05写道:
>
> On 10/10/21 2:19 AM, Li Feng wrote:
> > drivers/scsi/iscsi_tcp.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
> > index 1bc37593c88f..2ec1405d272d 100644
> > --- a/drivers/scsi/iscsi_tcp.c
> > +++ b/drivers/scsi/iscsi_tcp.c
> > @@ -724,6 +724,8 @@ static int iscsi_sw_tcp_conn_set_param(struct iscsi_cls_conn *cls_conn,
> > break;
> > case ISCSI_PARAM_DATADGST_EN:
> > iscsi_set_param(cls_conn, param, buf, buflen);
> > + if (!tcp_sw_conn || !tcp_sw_conn->sock)
> > + return -ENOTCONN;
> > tcp_sw_conn->sendpage = conn->datadgst_en ?
> > sock_no_sendpage : tcp_sw_conn->sock->ops->sendpage;
> > break;
> >
>
> Hi,
>
> Thanks for the patch. This was supposed to be fixed in:
>
> commit 9e67600ed6b8565da4b85698ec659b5879a6c1c6
> Author: Gulam Mohamed <gulam.mohamed@xxxxxxxxxx>
> Date: Thu Mar 25 09:32:48 2021 +0000
>
> scsi: iscsi: Fix race condition between login and sync thread
>
> because it was not supposed to allow set_param to be called on
> an unbound connection. However, it looks like there was a mistake in
> the patch:
>
> err = transport->set_param(conn, ev->u.set_param.param,
> data, ev->u.set_param.len);
> + if ((conn->state == ISCSI_CONN_BOUND) ||
> + (conn->state == ISCSI_CONN_UP)) {
> + err = transport->set_param(conn, ev->u.set_param.param,
> + data, ev->u.set_param.len);
> + } else {
> + return -ENOTCONN;
> + }
>
>
> and that first set_param call was supposed to be deleted and
> replaced with the one that was added in the conn->state check.
>
> We should just need a patch to remove that first set_param call.

Yes, I have checked the upstream code, this is an obvious mistake here.
I encountered this issue on 5.11.12-300.fc34.x86_64, it doesn't
include this patch,
so I check the pointer like my patch.
Thanks.