Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3518444pxf; Mon, 15 Mar 2021 11:19:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE8k+zsZEMbamDI+9DcffTQP6IzKi8cR/ICl27jTD+TU32e/8anUABJV8WGAZQNMTBbTHa X-Received: by 2002:a17:906:c1d7:: with SMTP id bw23mr24600281ejb.554.1615832392924; Mon, 15 Mar 2021 11:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832392; cv=none; d=google.com; s=arc-20160816; b=GhB3ocIJ5zOgyhLsHPw+C49vjezUQvmyIiCDj89q1/Citzjli+vpBDIuRMmm5TfKS6 3Da9zi9n/Q85na3qy34gXZB8/Iutq1dsuOUKaZYdu2FdyrNQ2tNQgf/YsRauYDoD/vrg TpT4Xoi6wSUrTPuMaN/vZmXB16ABUgpcaK8R6R72a3/GsFreYC22J3lKdti0GfbWrP97 FEgVl1KJBvgUyyni1YS6vhaBFp8+JOeR5VyN5MGLdRT8YGiKvqp7od1TnjkxcliR0Xkf z3cbR1VB/6rKH+MiPMk2BUW77fxQmRKTMPFug0HliHO9jCiUhl+vwe48B+dV6u7IK8+Q RHAw== 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=e5huWzrFEw+KCwPQVWPSZBTAi6273E9IUS2RxwszvV4=; b=dLUc+DZyDhK1yrKSJWqiJuxeH2W0sdpxKWQTviVlyYvhmVhk7giTSXG5bC+NUzCgnY gpIn0It+lnBw7KGM4KPmoLhxgcXQq1A+6IkViPn7SQRA50c/f4VH/w/uF7u5cGGDSuTv 9ZiIlfkZ8SH3v/ZFgkruH6LcT+HD7KMRA9cybcTqdV9iEQBLRha8s2YqySTKUhUkmIay wAlIVGCS6CtDSazSQsmGV0pd/EEd35LCxo/uTEsABBrejxOtUy4rqnmVYkjniEHZ0nSB DnoPFxm8X3lluslTpOTjdLCHG3+FabNuKKnDny8HrPK8ErQhEPOFho+NMSR+Ucp0k/SO 1DMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TQsZN2yT; 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 c17si5836889ede.535.2021.03.15.11.19.29; Mon, 15 Mar 2021 11:19:52 -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=TQsZN2yT; 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 S232743AbhCOOSL (ORCPT + 99 others); Mon, 15 Mar 2021 10:18:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:35904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230301AbhCON7e (ORCPT ); Mon, 15 Mar 2021 09:59:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 013E564F27; Mon, 15 Mar 2021 13:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816753; bh=zK4at9k5Dm8F1q5zVGnHRvNLo57LWKGfx8uZ+FjbCQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TQsZN2yTTmR6XAe71sa7KFHzz89bgkOFMPZelfx77Vea5o8GVejHtS1/oV4y+Bg4+ wQkgiY2jMPUV0c7JVGWKmp0XHt5FPiO4w0MUSu2FFau+jpQ0rxISqnnCWC/6KOfLZz wiBD9bb7YQVf0rkjrnMSrwkQyKZ6C+dEIRNAcKpo= 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.4 086/168] scsi: target: core: Add cmd length set before cmd complete Date: Mon, 15 Mar 2021 14:55:18 +0100 Message-Id: <20210315135553.210000175@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@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 1c73e0c5e54d5f7d77f422a10b03ebe61eaed5ad ] TCM doesn't properly handle underflow case for service actions. One way to prevent it is to always complete command with target_complete_cmd_with_length(), however it requires access to data_sg, which is not always available. This change introduces target_set_cmd_data_length() function which allows to set command data length before completing it. Link: https://lore.kernel.org/r/20210209072202.41154-2-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_transport.c | 15 +++++++++++---- include/target/target_core_backend.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index b1f4be055f83..a16835c0bb1d 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -873,11 +873,9 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) } EXPORT_SYMBOL(target_complete_cmd); -void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length) +void target_set_cmd_data_length(struct se_cmd *cmd, int length) { - if ((scsi_status == SAM_STAT_GOOD || - cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) && - length < cmd->data_length) { + if (length < cmd->data_length) { if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { cmd->residual_count += cmd->data_length - length; } else { @@ -887,6 +885,15 @@ void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int len cmd->data_length = length; } +} +EXPORT_SYMBOL(target_set_cmd_data_length); + +void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length) +{ + if (scsi_status == SAM_STAT_GOOD || + cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) { + target_set_cmd_data_length(cmd, length); + } target_complete_cmd(cmd, scsi_status); } diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h index 51b6f50eabee..0deeff9b4496 100644 --- a/include/target/target_core_backend.h +++ b/include/target/target_core_backend.h @@ -69,6 +69,7 @@ int transport_backend_register(const struct target_backend_ops *); void target_backend_unregister(const struct target_backend_ops *); void target_complete_cmd(struct se_cmd *, u8); +void target_set_cmd_data_length(struct se_cmd *, int); void target_complete_cmd_with_length(struct se_cmd *, u8, int); void transport_copy_sense_to_cmd(struct se_cmd *, unsigned char *); -- 2.30.1