From patchwork Wed Aug 9 03:29:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lin Ma X-Patchwork-Id: 713262 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DFA3EB64DD for ; Wed, 9 Aug 2023 03:30:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229634AbjHIDa4 (ORCPT ); Tue, 8 Aug 2023 23:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbjHIDaz (ORCPT ); Tue, 8 Aug 2023 23:30:55 -0400 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3225AE0 for ; Tue, 8 Aug 2023 20:30:54 -0700 (PDT) Received: from localhost.localdomain (unknown [39.174.92.167]) by mail-app3 (Coremail) with SMTP id cC_KCgBHLYoUCNNkDKuEDA--.19823S4; Wed, 09 Aug 2023 11:29:24 +0800 (CST) From: Lin Ma To: ketan.mukadam@broadcom.com, jejb@linux.ibm.com, martin.petersen@oracle.com, michaelc@cs.wisc.edu, JBottomley@Parallels.com, jayamohan.kallickal@emulex.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Lin Ma Subject: [PATCH v2] scsi: be2iscsi: Add nla_len check after nla_find Date: Wed, 9 Aug 2023 11:29:18 +0800 Message-Id: <20230809032918.767465-1-linma@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cC_KCgBHLYoUCNNkDKuEDA--.19823S4 X-Coremail-Antispam: 1UD129K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-Mailing-List: linux-scsi@vger.kernel.org The previous commit discussed at link https://lore.kernel.org/all/20230723075938.3713864-1-linma@zju.edu.cn/ adds length checks for the manual parsing loop in function beiscsi_iface_set_param(..) hence ensures the attribute being parsed has a valid length. However, the child function of beiscsi_iface_set_param, beiscsi_iface_config_ipv4 calls nla_find to locate and parse attributes ISCSI_NET_PARAM_IPV4_ADDR and ISCSI_NET_PARAM_IPV4_SUBNET. That is, if these two attributes are placed after the ISCSI_NET_PARAM command, they can bypass the added check and still cause an out-of-attribute access. Add extra nla_len checks after those two call sites to nla_find to keep malformed attributes away. Fixes: 0e43895ec1f4 ("[SCSI] be2iscsi: adding functionality to change network settings using iscsiadm") Signed-off-by: Lin Ma --- v1 -> v2: resent because the mail failed to reach public list drivers/scsi/be2iscsi/be_iscsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c index 8aeaddc93b16..acd3e587455b 100644 --- a/drivers/scsi/be2iscsi/be_iscsi.c +++ b/drivers/scsi/be2iscsi/be_iscsi.c @@ -374,7 +374,7 @@ beiscsi_iface_config_ipv4(struct Scsi_Host *shost, case ISCSI_NET_PARAM_IPV4_ADDR: ip = info->value; nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET); - if (nla) { + if (nla && nla_len(nla) >= sizeof(*info)) { info = nla_data(nla); subnet = info->value; } @@ -388,7 +388,7 @@ beiscsi_iface_config_ipv4(struct Scsi_Host *shost, */ subnet = info->value; nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR); - if (nla) { + if (nla && nla_len(nla) >= sizeof(*info)) { info = nla_data(nla); ip = info->value; }