Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3525961pxf; Mon, 15 Mar 2021 11:30:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwenbkoT9I1UmHcaCbSCpsVA9JbRs1QgTH+miVed0u07nrrFgccVvE7joDNzEvfeAyew4A X-Received: by 2002:a17:906:b80c:: with SMTP id dv12mr25354470ejb.110.1615833043456; Mon, 15 Mar 2021 11:30:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833043; cv=none; d=google.com; s=arc-20160816; b=Kv8sygTWTymYEMxdMFHS6N7sKL4s0kVXjH7r7kSyWKfdL4FAxnaXjoscF3ylWpAPGx O90Dikr6z7bSZNpdrXUltjl5xP+VF18FfedOQq3Gz8e6RyjAUZFcXH/Sft29Ayj3E+dA Azejs2zRnkksRA7bw6AbQuG7e2Ep4/bl5rQ2BjUIe4rhxh3rvFc7NGZyH65QuHQy1KBH lVYvnja4r3snjL+RU0gfQyDLl/4EjFctGc8Xtao7MsmK5NdPh5FUnzjO/+3AbckrS9kS jEn9wkHUzU2epISnAUfuhWNq+zpxJbXiiL7EkIg9uyifuzSd5VEql3ODEgEXH0SEdUIn feNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=q8tvp6VnneSiFB4ievzOwP9nJHD8me+/PCd1IrdeeMI=; b=S3Z5WD427J8wFhHE2dtb2SaY1ucwpIKqJjfTWzi6f3XOWoo0x2U5ACcWMm5I9s+UqD ELd/+rJlDEDjAQXS/5UTlYsNuZEAqn98DDma7qyJihQWbo85iEC4afKHcBVQLtbL/BYS 9Vvs1nw5Iu+lm23D47feD+db7YfvYF3UPkT2SkNsazxSOfIMZXgCQIuZN1eOWDz1ktiG IqzBAP/O2C3aIH+f3n1o74/jfgwij+SaL7x2LvwX/qHwiWmRZhq62RbM2Qd5RPqhBf1t r7MtGuWh0m+eVRpZ6gf4lT0YdTCJHHToTF8MW6bYpZJGBkWFg9yUtHYN4+YHcBevUOrG xrvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nu5szF4H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ot6si12051747ejb.337.2021.03.15.11.30.04; Mon, 15 Mar 2021 11:30:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nu5szF4H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237284AbhCOOg4 (ORCPT + 99 others); Mon, 15 Mar 2021 10:36:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:37540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233426AbhCOOBk (ORCPT ); Mon, 15 Mar 2021 10:01:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 05FD264F3D; Mon, 15 Mar 2021 14:01:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816879; bh=9Bg45yhEXj+Qt3KVQm2ESh06iqsBR53soFVnVT3sQ2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nu5szF4HoK2WPxJLRy6nJIlK2ts0GgHMKONbVAtabaiEektCB8kF6LtUW5sAKMuXz 4RkYOfC8HTADcdS88QPoEtwT7zXkKXNbtXzqwAOhjr8+uz3nkCIb3/aXq+Nqp1oDGf Z+G/steZD341EUnSu1WePZ2aCrppoTq5JyS+/TwM= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roman Bolshakov , Bodo Stroesser , Aleksandr Miloserdov , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.10 165/290] scsi: target: core: Prevent underflow for service actions Date: Mon, 15 Mar 2021 14:54:18 +0100 Message-Id: <20210315135547.480540698@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Aleksandr Miloserdov [ Upstream commit 14d24e2cc77411301e906a8cf41884739de192de ] TCM buffer length doesn't necessarily equal 8 + ADDITIONAL LENGTH which might be considered an underflow in case of Data-In size being greater than 8 + ADDITIONAL LENGTH. So truncate buffer length to prevent underflow. Link: https://lore.kernel.org/r/20210209072202.41154-3-a.miloserdov@yadro.com Reviewed-by: Roman Bolshakov Reviewed-by: Bodo Stroesser Signed-off-by: Aleksandr Miloserdov Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/target/target_core_pr.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 5f79ea05f9b8..b42193c554fb 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -3738,6 +3738,7 @@ core_scsi3_pri_read_keys(struct se_cmd *cmd) spin_unlock(&dev->t10_pr.registration_lock); put_unaligned_be32(add_len, &buf[4]); + target_set_cmd_data_length(cmd, 8 + add_len); transport_kunmap_data_sg(cmd); @@ -3756,7 +3757,7 @@ core_scsi3_pri_read_reservation(struct se_cmd *cmd) struct t10_pr_registration *pr_reg; unsigned char *buf; u64 pr_res_key; - u32 add_len = 16; /* Hardcoded to 16 when a reservation is held. */ + u32 add_len = 0; if (cmd->data_length < 8) { pr_err("PRIN SA READ_RESERVATIONS SCSI Data Length: %u" @@ -3774,8 +3775,9 @@ core_scsi3_pri_read_reservation(struct se_cmd *cmd) pr_reg = dev->dev_pr_res_holder; if (pr_reg) { /* - * Set the hardcoded Additional Length + * Set the Additional Length to 16 when a reservation is held */ + add_len = 16; put_unaligned_be32(add_len, &buf[4]); if (cmd->data_length < 22) @@ -3811,6 +3813,8 @@ core_scsi3_pri_read_reservation(struct se_cmd *cmd) (pr_reg->pr_res_type & 0x0f); } + target_set_cmd_data_length(cmd, 8 + add_len); + err: spin_unlock(&dev->dev_reservation_lock); transport_kunmap_data_sg(cmd); @@ -3829,7 +3833,7 @@ core_scsi3_pri_report_capabilities(struct se_cmd *cmd) struct se_device *dev = cmd->se_dev; struct t10_reservation *pr_tmpl = &dev->t10_pr; unsigned char *buf; - u16 add_len = 8; /* Hardcoded to 8. */ + u16 len = 8; /* Hardcoded to 8. */ if (cmd->data_length < 6) { pr_err("PRIN SA REPORT_CAPABILITIES SCSI Data Length:" @@ -3841,7 +3845,7 @@ core_scsi3_pri_report_capabilities(struct se_cmd *cmd) if (!buf) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; - put_unaligned_be16(add_len, &buf[0]); + put_unaligned_be16(len, &buf[0]); buf[2] |= 0x10; /* CRH: Compatible Reservation Hanlding bit. */ buf[2] |= 0x08; /* SIP_C: Specify Initiator Ports Capable bit */ buf[2] |= 0x04; /* ATP_C: All Target Ports Capable bit */ @@ -3870,6 +3874,8 @@ core_scsi3_pri_report_capabilities(struct se_cmd *cmd) buf[4] |= 0x02; /* PR_TYPE_WRITE_EXCLUSIVE */ buf[5] |= 0x01; /* PR_TYPE_EXCLUSIVE_ACCESS_ALLREG */ + target_set_cmd_data_length(cmd, len); + transport_kunmap_data_sg(cmd); return 0; @@ -4030,6 +4036,7 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd) * Set ADDITIONAL_LENGTH */ put_unaligned_be32(add_len, &buf[4]); + target_set_cmd_data_length(cmd, 8 + add_len); transport_kunmap_data_sg(cmd); -- 2.30.1