Vulnerability: Buffer overflow in the qeth_snmp_command function in drivers/s390/net/qeth_core_main.c in the Linux kernel through 3.12.1 allows local users to cause a denial of service or possibly have unspecified other impact via an SNMP ioctl call with a length value that is incompatible with the command-buffer size.
Vulnerability ID: CVE-2013-6381
CWE: CWE-119
Severity score: 10
Project: https://github.com/torvalds/linux
Published: 2013-11-27
File: drivers/s390/net/qeth_core_main.c
Commit message: qeth: avoid buffer overflow in snmp ioctl

Check user-defined length in snmp ioctl request and allow request
only if it fits into a qeth command buffer.

Signed-off-by: Ursula Braun <ursula.braun@de.ibm.com>
Signed-off-by: Frank Blaschka <frank.blaschka@de.ibm.com>
Reviewed-by: Heiko Carstens <heicars2@linux.vnet.ibm.com>
Reported-by: Nico Golde <nico@ngolde.de>
Reported-by: Fabian Yamaguchi <fabs@goesec.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Commit author: Ursula Braun

Vulnerable version (before fix):
 int qeth_snmp_command(struct qeth_card *card, char __user *udata) 	struct qeth_cmd_buffer *iob; 	struct qeth_ipa_cmd *cmd; 	struct qeth_snmp_ureq *ureq; 	int req_len; 	struct qeth_arp_query_info qinfo = {0, }; 	int rc = 0;  int qeth_snmp_command(struct qeth_card *card, char __user *udata) 	/* skip 4 bytes (data_len struct member) to get req_len */ 	if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int))) 		return -EFAULT; 	ureq = memdup_user(udata, req_len + sizeof(struct qeth_snmp_ureq_hdr)); 	if (IS_ERR(ureq)) { 		QETH_CARD_TEXT(card, 2, "snmpnome");

Fixed version (after fix):
 int qeth_snmp_command(struct qeth_card *card, char __user *udata) 	struct qeth_cmd_buffer *iob; 	struct qeth_ipa_cmd *cmd; 	struct qeth_snmp_ureq *ureq; 	unsigned int req_len; 	struct qeth_arp_query_info qinfo = {0, }; 	int rc = 0;  int qeth_snmp_command(struct qeth_card *card, char __user *udata) 	/* skip 4 bytes (data_len struct member) to get req_len */ 	if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int))) 		return -EFAULT; 	if (req_len > (QETH_BUFSIZE - IPA_PDU_HEADER_SIZE - 		       sizeof(struct qeth_ipacmd_hdr) - 		       sizeof(struct qeth_ipacmd_setadpparms_hdr))) 		return -EINVAL; 	ureq = memdup_user(udata, req_len + sizeof(struct qeth_snmp_ureq_hdr)); 	if (IS_ERR(ureq)) { 		QETH_CARD_TEXT(card, 2, "snmpnome");

Patch:
patch: @@ -4451,7 +4451,7 @@ int qeth_snmp_command(struct qeth_card *card, char __user *udata)
 	struct qeth_cmd_buffer *iob;
 	struct qeth_ipa_cmd *cmd;
 	struct qeth_snmp_ureq *ureq;
-	int req_len;
+	unsigned int req_len;
 	struct qeth_arp_query_info qinfo = {0, };
 	int rc = 0;
 
@@ -4467,6 +4467,10 @@ int qeth_snmp_command(struct qeth_card *card, char __user *udata)
 	/* skip 4 bytes (data_len struct member) to get req_len */
 	if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int)))
 		return -EFAULT;
+	if (req_len > (QETH_BUFSIZE - IPA_PDU_HEADER_SIZE -
+		       sizeof(struct qeth_ipacmd_hdr) -
+		       sizeof(struct qeth_ipacmd_setadpparms_hdr)))
+		return -EINVAL;
 	ureq = memdup_user(udata, req_len + sizeof(struct qeth_snmp_ureq_hdr));
 	if (IS_ERR(ureq)) {
 		QETH_CARD_TEXT(card, 2, "snmpnome");
path: drivers/s390/net/qeth_core_main.c