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

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