Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7150795ybi; Mon, 8 Jul 2019 15:40:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZqRAQh2jvoFtJ8SV4PjyN4e+dbq9CNMRoF76++b1AAUVPeskYvU6tv+DOK51HCuRBY0RO X-Received: by 2002:a63:6904:: with SMTP id e4mr8448836pgc.321.1562625607278; Mon, 08 Jul 2019 15:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625607; cv=none; d=google.com; s=arc-20160816; b=yvDN/W0tGX2OBlwLdsyKYXgUyB5FgPpXrW2heznF0jt57VoqQodorW2+WrvTW4lj6q 0oNUx++DGxkeOvAzASLJ9sqtIrjvT8+ksITp66u5x7Ot+ZHSnLeNAd4MOeXN36QrdYXY fhzSAORdbLqqtbzBdJpghOBC9fgIOY19jkcdyEqqvTwzp5Aw9Fimy72xtcovNJkwCKZR wTRLyl1aCL8BYj7W6va80LqR+yyms60CYtiYZEBXII5K0u/lLcXC0BPx6gbpeuFF4G+x x5uSb1CERT3FqMKIrTBtWLdb0wP2QHkfa6aFHolRCmFF+Hl/gqhUyTvbnuP3thN+q/fj FtjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pX2hP4hXr49DZ3cO0D+cVrA9oK+Ajn+OaZRo/q2V7nA=; b=hPmlFWYY0NenYoAsRmRZbiGTENsccz+jm4zCUuwU23V6cxTKNzntTk8WyiRsoaDw4/ PRXDxWo5JDMan1D0L4vAOvDRRqZLr8Pr54qEflmw7A0YP6JLBbe7WZkMmHZeinNk89Af mmJpt75BDqqq5jH24voyZIbpth7PwFF49bGytv7J4vEt8IGX17T607tH5abhkzhgF6vK hbh5l19Cu08ZZ/OhDa0Qs+tTpaOiSROD328OhT3Hz6jAxHK/YKjrcu2owyFQ3WuIOApZ xBHfIsoAMMHBTR2PuV17uIqTTsngnb+iwZ2DuSNjeBoFsAHoksn+04Snd0b4m8E7mP5V MLvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="OL1Sw7/M"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si710749pju.64.2019.07.08.15.39.52; Mon, 08 Jul 2019 15:40:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="OL1Sw7/M"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390646AbfGHPfZ (ORCPT + 99 others); Mon, 8 Jul 2019 11:35:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:37968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390631AbfGHPfY (ORCPT ); Mon, 8 Jul 2019 11:35:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A7861204EC; Mon, 8 Jul 2019 15:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562600123; bh=aNaYjnq15d5e7OzdjIviYRdikdrCKjgey/wUG1Q66SA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OL1Sw7/MO55X878KuvUaYh8Dt5WPxCFMzwiBMTCatm8KtRpRdlVeBGZcjlB0ABNr+ /yXwx19nVEJdUE0tzgkLqc6sNV8IOnV2ZqKQJnqOZZSv2OggjNIahIh+YljeRcTT6E iKDAq7IOdnVsmkHdaK2jQHPqFliy6c8yXv8skpls= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roman Bolshakov , Bart Van Assche , "Martin K. Petersen" Subject: [PATCH 5.1 96/96] scsi: target/iblock: Fix overrun in WRITE SAME emulation Date: Mon, 8 Jul 2019 17:14:08 +0200 Message-Id: <20190708150531.612248263@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150526.234572443@linuxfoundation.org> References: <20190708150526.234572443@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roman Bolshakov commit 5676234f20fef02f6ca9bd66c63a8860fce62645 upstream. WRITE SAME corrupts data on the block device behind iblock if the command is emulated. The emulation code issues (M - 1) * N times more bios than requested, where M is the number of 512 blocks per real block size and N is the NUMBER OF LOGICAL BLOCKS specified in WRITE SAME command. So, for a device with 4k blocks, 7 * N more LBAs gets written after the requested range. The issue happens because the number of 512 byte sectors to be written is decreased one by one while the real bios are typically from 1 to 8 512 byte sectors per bio. Fixes: c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6") Cc: Signed-off-by: Roman Bolshakov Reviewed-by: Bart Van Assche Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/target/target_core_iblock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/target/target_core_iblock.c +++ b/drivers/target/target_core_iblock.c @@ -515,7 +515,7 @@ iblock_execute_write_same(struct se_cmd /* Always in 512 byte units for Linux/Block */ block_lba += sg->length >> SECTOR_SHIFT; - sectors -= 1; + sectors -= sg->length >> SECTOR_SHIFT; } iblock_submit_bios(&list);