summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhong Jinghua <zhongjinghua@huawei.com>2023-03-29 15:17:39 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-04-13 16:48:24 +0200
commit5e5c5f472972c4bc9430adc08b36763a0fa5b9f7 (patch)
tree9736b3b1ba8d205aa1c88f1f34cad75ba96c200e
parentae73c4dd48f2c79d515d509a0cbe9efb0a197f44 (diff)
downloadlinux-stable-5e5c5f472972c4bc9430adc08b36763a0fa5b9f7.tar.gz
linux-stable-5e5c5f472972c4bc9430adc08b36763a0fa5b9f7.tar.bz2
linux-stable-5e5c5f472972c4bc9430adc08b36763a0fa5b9f7.zip
scsi: iscsi_tcp: Check that sock is valid before iscsi_set_param()
[ Upstream commit 48b19b79cfa37b1e50da3b5a8af529f994c08901 ] The validity of sock should be checked before assignment to avoid incorrect values. Commit 57569c37f0ad ("scsi: iscsi: iscsi_tcp: Fix null-ptr-deref while calling getpeername()") introduced this change which may lead to inconsistent values of tcp_sw_conn->sendpage and conn->datadgst_en. Fix the issue 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> Link: https://lore.kernel.org/r/20230329071739.2175268-1-zhongjinghua@huaweicloud.com Reviewed-by: Mike Christie <michael.christie@oracle.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/scsi/iscsi_tcp.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 594336004190..fe705b8bf464 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -767,13 +767,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);