All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhong Jinghua <zhongjinghua@huaweicloud.com>
To: lduncan@suse.com, cleech@redhat.com, jejb@linux.vnet.ibm.com,
	martin.petersen@oracle.com
Cc: open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org, zhongjinghua@huawei.com,
	yi.zhang@huawei.com, yukuai3@huawei.com, houtao1@huawei.com
Subject: [PATCH] scsi: iscsi_tcp: Check the sock is correct before iscsi_set_param
Date: Wed, 29 Mar 2023 15:17:39 +0800	[thread overview]
Message-ID: <20230329071739.2175268-1-zhongjinghua@huaweicloud.com> (raw)

From: Zhong Jinghua <zhongjinghua@huawei.com>

The correctness of sock should be checked before assignment to avoid
assigning wrong values.

Commit
"scsi: iscsi: iscsi_tcp: Fix null-ptr-deref while calling getpeername()"
introduced this change. This change may lead to inconsistent values of
tcp_sw_conn->sendpage and conn->datadgst_en.

Fix it by moving the position of the assignment.

Fixes: 57569c37f0ad ("scsi: iscsi: iscsi_tcp: Fix null-ptr-deref while calling getpeername()")
Signed-off-by: Zhong Jinghua <zhongjinghua@huawei.com>
---
 drivers/scsi/iscsi_tcp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 882e8b81b490..b32f3ca3e7d0 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -726,13 +726,12 @@ static int iscsi_sw_tcp_conn_set_param(struct iscsi_cls_conn *cls_conn,
 		iscsi_set_param(cls_conn, param, buf, buflen);
 		break;
 	case ISCSI_PARAM_DATADGST_EN:
-		iscsi_set_param(cls_conn, param, buf, buflen);
-
 		mutex_lock(&tcp_sw_conn->sock_lock);
 		if (!tcp_sw_conn->sock) {
 			mutex_unlock(&tcp_sw_conn->sock_lock);
 			return -ENOTCONN;
 		}
+		iscsi_set_param(cls_conn, param, buf, buflen);
 		tcp_sw_conn->sendpage = conn->datadgst_en ?
 			sock_no_sendpage : tcp_sw_conn->sock->ops->sendpage;
 		mutex_unlock(&tcp_sw_conn->sock_lock);
-- 
2.31.1


             reply	other threads:[~2023-03-29  7:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-29  7:17 Zhong Jinghua [this message]
2023-03-29 15:17 ` [PATCH] scsi: iscsi_tcp: Check the sock is correct before iscsi_set_param Mike Christie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230329071739.2175268-1-zhongjinghua@huaweicloud.com \
    --to=zhongjinghua@huaweicloud.com \
    --cc=cleech@redhat.com \
    --cc=houtao1@huawei.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=lduncan@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=open-iscsi@googlegroups.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    --cc=zhongjinghua@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.