Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 47f3be62 authored by Lin Ma's avatar Lin Ma Committed by Greg Kroah-Hartman
Browse files

scsi: qla4xxx: Add length check when parsing nlattrs



[ Upstream commit 47cd3770e31df942e2bb925a9a855c79ed0662eb ]

There are three places that qla4xxx parses nlattrs:

 - qla4xxx_set_chap_entry()

 - qla4xxx_iface_set_param()

 - qla4xxx_sysfs_ddb_set_param()

and each of them directly converts the nlattr to specific pointer of
structure without length checking. This could be dangerous as those
attributes are not validated and a malformed nlattr (e.g., length 0) could
result in an OOB read that leaks heap dirty data.

Add the nla_len check before accessing the nlattr data and return EINVAL if
the length check fails.

Fixes: 26ffd7b4 ("[SCSI] qla4xxx: Add support to set CHAP entries")
Fixes: 1e9e2be3 ("[SCSI] qla4xxx: Add flash node mgmt support")
Fixes: 00c31889 ("[SCSI] qla4xxx: fix data alignment and use nl helpers")
Signed-off-by: default avatarLin Ma <linma@zju.edu.cn>
Link: https://lore.kernel.org/r/20230723080053.3714534-1-linma@zju.edu.cn


Reviewed-by: default avatarChris Leech <cleech@redhat.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent bc66e701
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -939,6 +939,11 @@ static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
	memset(&chap_rec, 0, sizeof(chap_rec));

	nla_for_each_attr(attr, data, len, rem) {
		if (nla_len(attr) < sizeof(*param_info)) {
			rc = -EINVAL;
			goto exit_set_chap;
		}

		param_info = nla_data(attr);

		switch (param_info->param) {
@@ -2723,6 +2728,11 @@ qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
	}

	nla_for_each_attr(attr, data, len, rem) {
		if (nla_len(attr) < sizeof(*iface_param)) {
			rval = -EINVAL;
			goto exit_init_fw_cb;
		}

		iface_param = nla_data(attr);

		if (iface_param->param_type == ISCSI_NET_PARAM) {
@@ -8093,6 +8103,11 @@ qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,

	memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
	nla_for_each_attr(attr, data, len, rem) {
		if (nla_len(attr) < sizeof(*fnode_param)) {
			rc = -EINVAL;
			goto exit_set_param;
		}

		fnode_param = nla_data(attr);

		switch (fnode_param->param) {