[v1] scsi: be2iscsi: Add length check when parsing nlattrs

Message ID 20230723075938.3713864-1-linma@zju.edu.cn
State New
Headers
Series [v1] scsi: be2iscsi: Add length check when parsing nlattrs |

Commit Message

Lin Ma July 23, 2023, 7:59 a.m. UTC
  beiscsi_iface_set_param parses nlattr with nla_for_each_attr and assumes
every attributes can be viewed as struct iscsi_iface_param_info.

This is not true because there is no any nla_policy to validate the
attributes passed from the upper function iscsi_set_iface_params.

This patch adds the nla_len check before accessing the nlattr data and
error return EINVAL if the length check fails.

Fixes: 0e43895ec1f4 ("[SCSI] be2iscsi: adding functionality to change network settings using iscsiadm")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
---
 drivers/scsi/be2iscsi/be_iscsi.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Chris Leech July 25, 2023, 5:27 p.m. UTC | #1
On Sun, Jul 23, 2023 at 03:59:38PM +0800, Lin Ma wrote:
> beiscsi_iface_set_param parses nlattr with nla_for_each_attr and assumes
> every attributes can be viewed as struct iscsi_iface_param_info.
> 
> This is not true because there is no any nla_policy to validate the
> attributes passed from the upper function iscsi_set_iface_params.
> 
> This patch adds the nla_len check before accessing the nlattr data and
> error return EINVAL if the length check fails.

Reviewed-by: Chris Leech <cleech@redhat.com>
  
Martin K. Petersen July 26, 2023, 1:56 a.m. UTC | #2
Lin,

> beiscsi_iface_set_param parses nlattr with nla_for_each_attr and assumes
> every attributes can be viewed as struct iscsi_iface_param_info.

Applied to 6.6/scsi-staging, thanks!
  
Martin K. Petersen July 31, 2023, 7:45 p.m. UTC | #3
On Sun, 23 Jul 2023 15:59:38 +0800, Lin Ma wrote:

> beiscsi_iface_set_param parses nlattr with nla_for_each_attr and assumes
> every attributes can be viewed as struct iscsi_iface_param_info.
> 
> This is not true because there is no any nla_policy to validate the
> attributes passed from the upper function iscsi_set_iface_params.
> 
> This patch adds the nla_len check before accessing the nlattr data and
> error return EINVAL if the length check fails.
> 
> [...]

Applied to 6.6/scsi-queue, thanks!

[1/1] scsi: be2iscsi: Add length check when parsing nlattrs
      https://git.kernel.org/mkp/scsi/c/ee0268f230f6
  

Patch

diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c
index 8aeaddc93b16..8d374ae863ba 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.c
+++ b/drivers/scsi/be2iscsi/be_iscsi.c
@@ -450,6 +450,10 @@  int beiscsi_iface_set_param(struct Scsi_Host *shost,
 	}
 
 	nla_for_each_attr(attrib, data, dt_len, rm_len) {
+		/* ignore nla_type as it is never used */
+		if (nla_len(attrib) < sizeof(*iface_param))
+			return -EINVAL;
+
 		iface_param = nla_data(attrib);
 
 		if (iface_param->param_type != ISCSI_NET_PARAM)