Blame SOURCES/scsi-iscsi-kpatch-fixes-for-CVE-2021-27364-and-CVE-2.patch

0594d9
From 7627b7136546892ed803c6f41153d0674c05fc1f Mon Sep 17 00:00:00 2001
0594d9
From: Joe Lawrence <joe.lawrence@redhat.com>
0594d9
Date: Fri, 26 Mar 2021 13:24:17 -0400
0594d9
Subject: [PATCH] scsi: iscsi: kpatch fixes for CVE-2021-27364 and
0594d9
 CVE-2021-27365
0594d9
0594d9
Notes: backport CVE-2021-27363 to simplify patchset
0594d9
       see [JL] notes in commit msgs below correcting CVE numbers
0594d9
0594d9
Kernels:
0594d9
3.10.0-1160.el7
0594d9
3.10.0-1160.2.1.el7
0594d9
3.10.0-1160.2.2.el7
0594d9
3.10.0-1160.6.1.el7
0594d9
3.10.0-1160.11.1.el7
0594d9
3.10.0-1160.15.2.el7
0594d9
3.10.0-1160.21.1.el7
0594d9
0594d9
Changes since last build:
0594d9
arches: x86_64 ppc64le
0594d9
libiscsi.o: changed function: iscsi_conn_get_addr_param
0594d9
libiscsi.o: changed function: iscsi_conn_get_param
0594d9
libiscsi.o: changed function: iscsi_host_get_param
0594d9
libiscsi.o: changed function: iscsi_session_get_param
0594d9
scsi_transport_iscsi.o: changed function: iscsi_if_recv_msg
0594d9
scsi_transport_iscsi.o: changed function: show_ep_handle
0594d9
scsi_transport_iscsi.o: changed function: show_priv_session_creator
0594d9
scsi_transport_iscsi.o: changed function: show_priv_session_recovery_tmo
0594d9
scsi_transport_iscsi.o: changed function: show_priv_session_state
0594d9
scsi_transport_iscsi.o: changed function: show_priv_session_target_id
0594d9
scsi_transport_iscsi.o: changed function: show_transport_caps
0594d9
scsi_transport_iscsi.o: changed function: show_transport_handle
0594d9
---------------------------
0594d9
0594d9
Modifications: none
0594d9
0594d9
commit b307f0f6090743a904454f6ecc54d290ca18a693
0594d9
Author: Chris Leech <cleech@redhat.com>
0594d9
Date:   Thu Mar 4 09:55:32 2021 -0800
0594d9
0594d9
    scsi: iscsi: Restrict sessions and handles to admin capabilities
0594d9
0594d9
    Bugzilla: http://bugzilla.redhat.com/1930807
0594d9
    CVE: CVE-2021-27364		<< [JL] should be CVE-2021-27363
0594d9
0594d9
    commit 688e8128b7a92df982709a4137ea4588d16f24aa
0594d9
    Author: Lee Duncan <lduncan@suse.com>
0594d9
    Date:   Tue Feb 23 13:06:24 2021 -0800
0594d9
0594d9
        scsi: iscsi: Restrict sessions and handles to admin capabilities
0594d9
0594d9
        Protect the iSCSI transport handle, available in sysfs, by requiring
0594d9
        CAP_SYS_ADMIN to read it. Also protect the netlink socket by restricting
0594d9
        reception of messages to ones sent with CAP_SYS_ADMIN. This disables
0594d9
        normal users from being able to end arbitrary iSCSI sessions.
0594d9
0594d9
        Cc: stable@vger.kernel.org
0594d9
        Reported-by: Adam Nichols <adam@grimm-co.com>
0594d9
        Reviewed-by: Chris Leech <cleech@redhat.com>
0594d9
        Reviewed-by: Mike Christie <michael.christie@oracle.com>
0594d9
        Signed-off-by: Lee Duncan <lduncan@suse.com>
0594d9
        Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
0594d9
0594d9
    Signed-off-by: Chris Leech <cleech@redhat.com>
0594d9
0594d9
commit af581fe518f4d6a6f28064f932d9374e0444d706
0594d9
Author: Chris Leech <cleech@redhat.com>
0594d9
Date:   Thu Mar 4 09:57:23 2021 -0800
0594d9
0594d9
    scsi: iscsi: Ensure sysfs attributes are limited to PAGE_SIZE
0594d9
0594d9
    Bugzilla: http://bugzilla.redhat.com/1930849
0594d9
    CVE: CVE-2021-27363		<< [JL] should be CVE-2021-27365
0594d9
0594d9
    Conflicts: The sysfs_emit helper doesn't exist for backports, but other
0594d9
    than a sanity check on buf it's just a call to scnprintf with a
0594d9
    PAGE_SIZE limit.
0594d9
    converted with s/sysfs_emit(buf,/scnprintf(buf, PAGE_SIZE,/
0594d9
0594d9
    commit ec98ea7070e94cc25a422ec97d1421e28d97b7ee
0594d9
    Author: Chris Leech <cleech@redhat.com>
0594d9
    Date:   Tue Feb 23 18:00:17 2021 -0800
0594d9
0594d9
        scsi: iscsi: Ensure sysfs attributes are limited to PAGE_SIZE
0594d9
0594d9
        As the iSCSI parameters are exported back through sysfs, it should be
0594d9
        enforcing that they never are more than PAGE_SIZE (which should be more
0594d9
        than enough) before accepting updates through netlink.
0594d9
0594d9
        Change all iSCSI sysfs attributes to use sysfs_emit().
0594d9
0594d9
        Cc: stable@vger.kernel.org
0594d9
        Reported-by: Adam Nichols <adam@grimm-co.com>
0594d9
        Reviewed-by: Lee Duncan <lduncan@suse.com>
0594d9
        Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
0594d9
        Reviewed-by: Mike Christie <michael.christie@oracle.com>
0594d9
        Signed-off-by: Chris Leech <cleech@redhat.com>
0594d9
        Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
0594d9
0594d9
    Signed-off-by: Chris Leech <cleech@redhat.com>
0594d9
0594d9
commit 8026ca13e283db6175377fccf309e8c5239033be
0594d9
Author: Chris Leech <cleech@redhat.com>
0594d9
Date:   Thu Mar 4 09:58:33 2021 -0800
0594d9
0594d9
    scsi: iscsi: Verify lengths on passthrough PDUs
0594d9
0594d9
    Bugzilla: http://bugzilla.redhat.com/1930826
0594d9
    CVE: CVE-2021-27365		<< [JL] should be CVE-2021-27364
0594d9
0594d9
    commit f9dbdf97a5bd92b1a49cee3d591b55b11fd7a6d5
0594d9
    Author: Chris Leech <cleech@redhat.com>
0594d9
    Date:   Tue Feb 23 21:39:01 2021 -0800
0594d9
0594d9
        scsi: iscsi: Verify lengths on passthrough PDUs
0594d9
0594d9
        Open-iSCSI sends passthrough PDUs over netlink, but the kernel should be
0594d9
        verifying that the provided PDU header and data lengths fall within the
0594d9
        netlink message to prevent accessing beyond that in memory.
0594d9
0594d9
        Cc: stable@vger.kernel.org
0594d9
        Reported-by: Adam Nichols <adam@grimm-co.com>
0594d9
        Reviewed-by: Lee Duncan <lduncan@suse.com>
0594d9
        Reviewed-by: Mike Christie <michael.christie@oracle.com>
0594d9
        Signed-off-by: Chris Leech <cleech@redhat.com>
0594d9
        Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
0594d9
0594d9
    Signed-off-by: Chris Leech <cleech@redhat.com>
0594d9
0594d9
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
0594d9
Acked-by: Artem Savkov <asavkov@redhat.com>
0594d9
---
0594d9
 drivers/scsi/libiscsi.c             | 148 ++++++++++++++--------------
0594d9
 drivers/scsi/scsi_transport_iscsi.c |  38 +++++--
0594d9
 2 files changed, 104 insertions(+), 82 deletions(-)
0594d9
0594d9
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
0594d9
index bd36ead89f9d..5530662bd9ed 100644
0594d9
--- a/drivers/scsi/libiscsi.c
0594d9
+++ b/drivers/scsi/libiscsi.c
0594d9
@@ -3323,125 +3323,125 @@ int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
0594d9
 
0594d9
 	switch(param) {
0594d9
 	case ISCSI_PARAM_FAST_ABORT:
0594d9
-		len = sprintf(buf, "%d\n", session->fast_abort);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->fast_abort);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_ABORT_TMO:
0594d9
-		len = sprintf(buf, "%d\n", session->abort_timeout);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->abort_timeout);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_LU_RESET_TMO:
0594d9
-		len = sprintf(buf, "%d\n", session->lu_reset_timeout);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->lu_reset_timeout);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TGT_RESET_TMO:
0594d9
-		len = sprintf(buf, "%d\n", session->tgt_reset_timeout);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->tgt_reset_timeout);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_INITIAL_R2T_EN:
0594d9
-		len = sprintf(buf, "%d\n", session->initial_r2t_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->initial_r2t_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_MAX_R2T:
0594d9
-		len = sprintf(buf, "%hu\n", session->max_r2t);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%hu\n", session->max_r2t);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_IMM_DATA_EN:
0594d9
-		len = sprintf(buf, "%d\n", session->imm_data_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->imm_data_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_FIRST_BURST:
0594d9
-		len = sprintf(buf, "%u\n", session->first_burst);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->first_burst);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_MAX_BURST:
0594d9
-		len = sprintf(buf, "%u\n", session->max_burst);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->max_burst);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_PDU_INORDER_EN:
0594d9
-		len = sprintf(buf, "%d\n", session->pdu_inorder_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->pdu_inorder_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DATASEQ_INORDER_EN:
0594d9
-		len = sprintf(buf, "%d\n", session->dataseq_inorder_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->dataseq_inorder_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DEF_TASKMGMT_TMO:
0594d9
-		len = sprintf(buf, "%d\n", session->def_taskmgmt_tmo);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->def_taskmgmt_tmo);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_ERL:
0594d9
-		len = sprintf(buf, "%d\n", session->erl);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->erl);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TARGET_NAME:
0594d9
-		len = sprintf(buf, "%s\n", session->targetname);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->targetname);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TARGET_ALIAS:
0594d9
-		len = sprintf(buf, "%s\n", session->targetalias);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->targetalias);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TPGT:
0594d9
-		len = sprintf(buf, "%d\n", session->tpgt);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->tpgt);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_USERNAME:
0594d9
-		len = sprintf(buf, "%s\n", session->username);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->username);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_USERNAME_IN:
0594d9
-		len = sprintf(buf, "%s\n", session->username_in);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->username_in);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_PASSWORD:
0594d9
-		len = sprintf(buf, "%s\n", session->password);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->password);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_PASSWORD_IN:
0594d9
-		len = sprintf(buf, "%s\n", session->password_in);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->password_in);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_IFACE_NAME:
0594d9
-		len = sprintf(buf, "%s\n", session->ifacename);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->ifacename);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_INITIATOR_NAME:
0594d9
-		len = sprintf(buf, "%s\n", session->initiatorname);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->initiatorname);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_BOOT_ROOT:
0594d9
-		len = sprintf(buf, "%s\n", session->boot_root);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->boot_root);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_BOOT_NIC:
0594d9
-		len = sprintf(buf, "%s\n", session->boot_nic);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->boot_nic);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_BOOT_TARGET:
0594d9
-		len = sprintf(buf, "%s\n", session->boot_target);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->boot_target);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
0594d9
-		len = sprintf(buf, "%u\n", session->auto_snd_tgt_disable);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->auto_snd_tgt_disable);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DISCOVERY_SESS:
0594d9
-		len = sprintf(buf, "%u\n", session->discovery_sess);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->discovery_sess);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_PORTAL_TYPE:
0594d9
-		len = sprintf(buf, "%s\n", session->portal_type);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", session->portal_type);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_CHAP_AUTH_EN:
0594d9
-		len = sprintf(buf, "%u\n", session->chap_auth_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->chap_auth_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
0594d9
-		len = sprintf(buf, "%u\n", session->discovery_logout_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->discovery_logout_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_BIDI_CHAP_EN:
0594d9
-		len = sprintf(buf, "%u\n", session->bidi_chap_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->bidi_chap_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
0594d9
-		len = sprintf(buf, "%u\n", session->discovery_auth_optional);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->discovery_auth_optional);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DEF_TIME2WAIT:
0594d9
-		len = sprintf(buf, "%d\n", session->time2wait);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->time2wait);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DEF_TIME2RETAIN:
0594d9
-		len = sprintf(buf, "%d\n", session->time2retain);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", session->time2retain);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TSID:
0594d9
-		len = sprintf(buf, "%u\n", session->tsid);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->tsid);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_ISID:
0594d9
-		len = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%02x%02x%02x%02x%02x%02x\n",
0594d9
 			      session->isid[0], session->isid[1],
0594d9
 			      session->isid[2], session->isid[3],
0594d9
 			      session->isid[4], session->isid[5]);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
0594d9
-		len = sprintf(buf, "%u\n", session->discovery_parent_idx);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", session->discovery_parent_idx);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
0594d9
 		if (session->discovery_parent_type)
0594d9
-			len = sprintf(buf, "%s\n",
0594d9
+			len = scnprintf(buf, PAGE_SIZE, "%s\n",
0594d9
 				      session->discovery_parent_type);
0594d9
 		else
0594d9
-			len = sprintf(buf, "\n");
0594d9
+			len = scnprintf(buf, PAGE_SIZE, "\n");
0594d9
 		break;
0594d9
 	default:
0594d9
 		return -ENOSYS;
0594d9
@@ -3473,16 +3473,16 @@ int iscsi_conn_get_addr_param(struct sockaddr_storage *addr,
0594d9
 	case ISCSI_PARAM_CONN_ADDRESS:
0594d9
 	case ISCSI_HOST_PARAM_IPADDRESS:
0594d9
 		if (sin)
0594d9
-			len = sprintf(buf, "%pI4\n", &sin->sin_addr.s_addr);
0594d9
+			len = scnprintf(buf, PAGE_SIZE, "%pI4\n", &sin->sin_addr.s_addr);
0594d9
 		else
0594d9
-			len = sprintf(buf, "%pI6\n", &sin6->sin6_addr);
0594d9
+			len = scnprintf(buf, PAGE_SIZE, "%pI6\n", &sin6->sin6_addr);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_CONN_PORT:
0594d9
 	case ISCSI_PARAM_LOCAL_PORT:
0594d9
 		if (sin)
0594d9
-			len = sprintf(buf, "%hu\n", be16_to_cpu(sin->sin_port));
0594d9
+			len = scnprintf(buf, PAGE_SIZE, "%hu\n", be16_to_cpu(sin->sin_port));
0594d9
 		else
0594d9
-			len = sprintf(buf, "%hu\n",
0594d9
+			len = scnprintf(buf, PAGE_SIZE, "%hu\n",
0594d9
 				      be16_to_cpu(sin6->sin6_port));
0594d9
 		break;
0594d9
 	default:
0594d9
@@ -3501,88 +3501,88 @@ int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
0594d9
 
0594d9
 	switch(param) {
0594d9
 	case ISCSI_PARAM_PING_TMO:
0594d9
-		len = sprintf(buf, "%u\n", conn->ping_timeout);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->ping_timeout);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_RECV_TMO:
0594d9
-		len = sprintf(buf, "%u\n", conn->recv_timeout);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->recv_timeout);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_MAX_RECV_DLENGTH:
0594d9
-		len = sprintf(buf, "%u\n", conn->max_recv_dlength);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->max_recv_dlength);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_MAX_XMIT_DLENGTH:
0594d9
-		len = sprintf(buf, "%u\n", conn->max_xmit_dlength);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->max_xmit_dlength);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_HDRDGST_EN:
0594d9
-		len = sprintf(buf, "%d\n", conn->hdrdgst_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", conn->hdrdgst_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_DATADGST_EN:
0594d9
-		len = sprintf(buf, "%d\n", conn->datadgst_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", conn->datadgst_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_IFMARKER_EN:
0594d9
-		len = sprintf(buf, "%d\n", conn->ifmarker_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", conn->ifmarker_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_OFMARKER_EN:
0594d9
-		len = sprintf(buf, "%d\n", conn->ofmarker_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", conn->ofmarker_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_EXP_STATSN:
0594d9
-		len = sprintf(buf, "%u\n", conn->exp_statsn);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->exp_statsn);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_PERSISTENT_PORT:
0594d9
-		len = sprintf(buf, "%d\n", conn->persistent_port);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%d\n", conn->persistent_port);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_PERSISTENT_ADDRESS:
0594d9
-		len = sprintf(buf, "%s\n", conn->persistent_address);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", conn->persistent_address);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_STATSN:
0594d9
-		len = sprintf(buf, "%u\n", conn->statsn);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->statsn);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_MAX_SEGMENT_SIZE:
0594d9
-		len = sprintf(buf, "%u\n", conn->max_segment_size);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->max_segment_size);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_KEEPALIVE_TMO:
0594d9
-		len = sprintf(buf, "%u\n", conn->keepalive_tmo);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->keepalive_tmo);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_LOCAL_PORT:
0594d9
-		len = sprintf(buf, "%u\n", conn->local_port);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->local_port);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
0594d9
-		len = sprintf(buf, "%u\n", conn->tcp_timestamp_stat);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->tcp_timestamp_stat);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TCP_NAGLE_DISABLE:
0594d9
-		len = sprintf(buf, "%u\n", conn->tcp_nagle_disable);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->tcp_nagle_disable);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TCP_WSF_DISABLE:
0594d9
-		len = sprintf(buf, "%u\n", conn->tcp_wsf_disable);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->tcp_wsf_disable);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TCP_TIMER_SCALE:
0594d9
-		len = sprintf(buf, "%u\n", conn->tcp_timer_scale);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->tcp_timer_scale);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TCP_TIMESTAMP_EN:
0594d9
-		len = sprintf(buf, "%u\n", conn->tcp_timestamp_en);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->tcp_timestamp_en);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
0594d9
-		len = sprintf(buf, "%u\n", conn->fragment_disable);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->fragment_disable);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_IPV4_TOS:
0594d9
-		len = sprintf(buf, "%u\n", conn->ipv4_tos);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->ipv4_tos);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_IPV6_TC:
0594d9
-		len = sprintf(buf, "%u\n", conn->ipv6_traffic_class);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->ipv6_traffic_class);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_IPV6_FLOW_LABEL:
0594d9
-		len = sprintf(buf, "%u\n", conn->ipv6_flow_label);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->ipv6_flow_label);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
0594d9
-		len = sprintf(buf, "%u\n", conn->is_fw_assigned_ipv6);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->is_fw_assigned_ipv6);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TCP_XMIT_WSF:
0594d9
-		len = sprintf(buf, "%u\n", conn->tcp_xmit_wsf);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->tcp_xmit_wsf);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_TCP_RECV_WSF:
0594d9
-		len = sprintf(buf, "%u\n", conn->tcp_recv_wsf);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", conn->tcp_recv_wsf);
0594d9
 		break;
0594d9
 	case ISCSI_PARAM_LOCAL_IPADDR:
0594d9
-		len = sprintf(buf, "%s\n", conn->local_ipaddr);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", conn->local_ipaddr);
0594d9
 		break;
0594d9
 	default:
0594d9
 		return -ENOSYS;
0594d9
@@ -3600,13 +3600,13 @@ int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
0594d9
 
0594d9
 	switch (param) {
0594d9
 	case ISCSI_HOST_PARAM_NETDEV_NAME:
0594d9
-		len = sprintf(buf, "%s\n", ihost->netdev);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", ihost->netdev);
0594d9
 		break;
0594d9
 	case ISCSI_HOST_PARAM_HWADDRESS:
0594d9
-		len = sprintf(buf, "%s\n", ihost->hwaddress);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", ihost->hwaddress);
0594d9
 		break;
0594d9
 	case ISCSI_HOST_PARAM_INITIATOR_NAME:
0594d9
-		len = sprintf(buf, "%s\n", ihost->initiatorname);
0594d9
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", ihost->initiatorname);
0594d9
 		break;
0594d9
 	default:
0594d9
 		return -ENOSYS;
0594d9
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
0594d9
index 2265611b7e37..f0738bb165f2 100644
0594d9
--- a/drivers/scsi/scsi_transport_iscsi.c
0594d9
+++ b/drivers/scsi/scsi_transport_iscsi.c
0594d9
@@ -119,7 +119,11 @@ show_transport_handle(struct device *dev, struct device_attribute *attr,
0594d9
 		      char *buf)
0594d9
 {
0594d9
 	struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
0594d9
-	return sprintf(buf, "%llu\n", (unsigned long long)iscsi_handle(priv->iscsi_transport));
0594d9
+
0594d9
+	if (!capable(CAP_SYS_ADMIN))
0594d9
+		return -EACCES;
0594d9
+	return scnprintf(buf, PAGE_SIZE, "%llu\n",
0594d9
+		  (unsigned long long)iscsi_handle(priv->iscsi_transport));
0594d9
 }
0594d9
 static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL);
0594d9
 
0594d9
@@ -129,7 +133,7 @@ show_transport_##name(struct device *dev, 				\
0594d9
 		      struct device_attribute *attr,char *buf)		\
0594d9
 {									\
0594d9
 	struct iscsi_internal *priv = dev_to_iscsi_internal(dev);	\
0594d9
-	return sprintf(buf, format"\n", priv->iscsi_transport->name);	\
0594d9
+	return scnprintf(buf, PAGE_SIZE, format"\n", priv->iscsi_transport->name);\
0594d9
 }									\
0594d9
 static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
0594d9
 
0594d9
@@ -170,7 +174,7 @@ static ssize_t
0594d9
 show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf)
0594d9
 {
0594d9
 	struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
0594d9
-	return sprintf(buf, "%llu\n", (unsigned long long) ep->id);
0594d9
+	return scnprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long) ep->id);
0594d9
 }
0594d9
 static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL);
0594d9
 
0594d9
@@ -2779,6 +2783,9 @@ iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
0594d9
 	struct iscsi_cls_session *session;
0594d9
 	int err = 0, value = 0;
0594d9
 
0594d9
+	if (ev->u.set_param.len > PAGE_SIZE)
0594d9
+		return -EINVAL;
0594d9
+
0594d9
 	session = iscsi_session_lookup(ev->u.set_param.sid);
0594d9
 	conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
0594d9
 	if (!conn || !session)
0594d9
@@ -2926,6 +2933,9 @@ iscsi_set_host_param(struct iscsi_transport *transport,
0594d9
 	if (!transport->set_host_param)
0594d9
 		return -ENOSYS;
0594d9
 
0594d9
+	if (ev->u.set_host_param.len > PAGE_SIZE)
0594d9
+		return -EINVAL;
0594d9
+
0594d9
 	shost = scsi_host_lookup(ev->u.set_host_param.host_no);
0594d9
 	if (!shost) {
0594d9
 		printk(KERN_ERR "set_host_param could not find host no %u\n",
0594d9
@@ -3495,6 +3505,7 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
0594d9
 {
0594d9
 	int err = 0;
0594d9
 	u32 portid;
0594d9
+	u32 pdu_len;
0594d9
 	struct iscsi_uevent *ev = nlmsg_data(nlh);
0594d9
 	struct iscsi_transport *transport = NULL;
0594d9
 	struct iscsi_internal *priv;
0594d9
@@ -3502,6 +3513,9 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
0594d9
 	struct iscsi_cls_conn *conn;
0594d9
 	struct iscsi_endpoint *ep = NULL;
0594d9
 
0594d9
+	if (!netlink_capable(skb, CAP_SYS_ADMIN))
0594d9
+		return -EPERM;
0594d9
+
0594d9
 	if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE)
0594d9
 		*group = ISCSI_NL_GRP_UIP;
0594d9
 	else
0594d9
@@ -3607,6 +3621,14 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
0594d9
 			err = -EINVAL;
0594d9
 		break;
0594d9
 	case ISCSI_UEVENT_SEND_PDU:
0594d9
+		pdu_len = nlh->nlmsg_len - sizeof(*nlh) - sizeof(*ev);
0594d9
+
0594d9
+		if ((ev->u.send_pdu.hdr_size > pdu_len) ||
0594d9
+		    (ev->u.send_pdu.data_size > (pdu_len - ev->u.send_pdu.hdr_size))) {
0594d9
+			err = -EINVAL;
0594d9
+			break;
0594d9
+		}
0594d9
+
0594d9
 		conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
0594d9
 		if (conn)
0594d9
 			ev->r.retcode =	transport->send_pdu(conn,
0594d9
@@ -4013,7 +4035,7 @@ show_priv_session_state(struct device *dev, struct device_attribute *attr,
0594d9
 			char *buf)
0594d9
 {
0594d9
 	struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
0594d9
-	return sprintf(buf, "%s\n", iscsi_session_state_name(session->state));
0594d9
+	return scnprintf(buf, PAGE_SIZE, "%s\n", iscsi_session_state_name(session->state));
0594d9
 }
0594d9
 static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
0594d9
 			NULL);
0594d9
@@ -4022,7 +4044,7 @@ show_priv_session_creator(struct device *dev, struct device_attribute *attr,
0594d9
 			char *buf)
0594d9
 {
0594d9
 	struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
0594d9
-	return sprintf(buf, "%d\n", session->creator);
0594d9
+	return scnprintf(buf, PAGE_SIZE, "%d\n", session->creator);
0594d9
 }
0594d9
 static ISCSI_CLASS_ATTR(priv_sess, creator, S_IRUGO, show_priv_session_creator,
0594d9
 			NULL);
0594d9
@@ -4031,7 +4053,7 @@ show_priv_session_target_id(struct device *dev, struct device_attribute *attr,
0594d9
 			    char *buf)
0594d9
 {
0594d9
 	struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
0594d9
-	return sprintf(buf, "%d\n", session->target_id);
0594d9
+	return scnprintf(buf, PAGE_SIZE, "%d\n", session->target_id);
0594d9
 }
0594d9
 static ISCSI_CLASS_ATTR(priv_sess, target_id, S_IRUGO,
0594d9
 			show_priv_session_target_id, NULL);
0594d9
@@ -4044,8 +4066,8 @@ show_priv_session_##field(struct device *dev, 				\
0594d9
 	struct iscsi_cls_session *session = 				\
0594d9
 			iscsi_dev_to_session(dev->parent);		\
0594d9
 	if (session->field == -1)					\
0594d9
-		return sprintf(buf, "off\n");				\
0594d9
-	return sprintf(buf, format"\n", session->field);		\
0594d9
+		return scnprintf(buf, PAGE_SIZE, "off\n");			\
0594d9
+	return scnprintf(buf, PAGE_SIZE, format"\n", session->field);		\
0594d9
 }
0594d9
 
0594d9
 #define iscsi_priv_session_attr_store(field)				\
0594d9
-- 
0594d9
2.26.2
0594d9