Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3519422pxf; Mon, 15 Mar 2021 11:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTYj40dqhxDNFAhwVcQuiNxG67TuAQrN2DPkUuXTEnVc4Es3LdG7nLEqGGegRVnovq3xmo X-Received: by 2002:a17:907:72d5:: with SMTP id du21mr25882761ejc.167.1615832484463; Mon, 15 Mar 2021 11:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832484; cv=none; d=google.com; s=arc-20160816; b=biEFh2X1ZbFFOdbdrHgY4NAyYeJLeE2Zmmeb3HwE5fDvnAB0mGFRylI0aFJGLkzZFb +H13wPC2zspJAX9uIgf7mGyqd0YiEqKgZ7eoGwO5b3Y3S+vF5is9OsGN7aZQE73fttjA 3i0misGbPWq2fNbONrazI29ETMAWCKRGx32246ur9pv1+ZRrw57h4VfQI1nV/jbBsfLq 6dL+zEX1nwtbrWDhqqoy/LHCSQ3bvWeYP9KToP/qM/DVFHqoAZugOMYBl3AOMQwhruC3 zxl2RvFXJwbgyLy/TEqPPHNuCKHA2DQBTCTF07EKlTp5yiwQ0Y+j6+Z05GIDslUnYeZe O8LQ== 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=R7dr0kGj59tqBbo+DZ7sUuESA1LRziDx32sWfH3SMRg=; b=VuWZ+RQU9zsQKK4hkE2wEgJ60kuBKvFM913fFJCo8+ZMhusNnMSPVHDpgxECXLdqPT SI9TyNgZc5ZT5cUBGE1IVWbI3b0HbwDAljp7oQL7dyGwYb7JrXV+yk+D8ERfnmBTXJKh fyeoPTaNwHcyeLDUgYJSmYIwNps77tkKZT1ECIqHfXTpns8EAHRkRpPciSrOuga/kUdf Sb+Vr8w4f+zYADb3SdE4QJIMnx3Mkv+pFTtuk1r5JqVOGaGgLepm/J7KeEP8u3ODQEn6 rHJ+0WQAik0B7XbysdBN15ZbKHITrjfSqcBptZJAKWx+94BPc+x5q2TA6zzxvxUxwUgG /sqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IolRXtIa; 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 w24si11784741eds.559.2021.03.15.11.21.02; Mon, 15 Mar 2021 11:21:24 -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=IolRXtIa; 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 S237739AbhCOOTv (ORCPT + 99 others); Mon, 15 Mar 2021 10:19:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:37612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232580AbhCON7w (ORCPT ); Mon, 15 Mar 2021 09:59:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AC15B64F09; Mon, 15 Mar 2021 13:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816774; bh=7fHTHlji+iBRajGsgGKwyju4FDbaMfVJyuI93txxrhg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IolRXtIap4NxhvuPdONjEvsARSAg4yb9wA/PBmd7jfN4v6fUHhaS5FGHlCpIBtEYw A9Pzcwrr5+ssJy6OoGD2qcvkLmsD1RbmszDYChHUn+craHP/fpDM9vNkwjrqNe5UdY ZxfQErE88ot+d68aiCnEOdIPdeHZORJHBkwlV8/E= 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 4.19 058/120] scsi: target: core: Prevent underflow for service actions Date: Mon, 15 Mar 2021 14:56:49 +0100 Message-Id: <20210315135721.887718757@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135720.002213995@linuxfoundation.org> References: <20210315135720.002213995@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 10db5656fd5d..949879f2f1d1 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -3742,6 +3742,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); @@ -3760,7 +3761,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" @@ -3778,8 +3779,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) @@ -3815,6 +3817,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); @@ -3833,7 +3837,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:" @@ -3845,7 +3849,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 */ @@ -3874,6 +3878,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; @@ -4034,6 +4040,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