Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp748896ybl; Wed, 4 Dec 2019 10:12:44 -0800 (PST) X-Google-Smtp-Source: APXvYqxcMNKVQ1GXX3V5CcjJIiZXg8xoKEGOW3QbMVWBUM5ns/NAZQb/4VPvZKT+ESyw0yjDuNsH X-Received: by 2002:aca:1817:: with SMTP id h23mr3755421oih.53.1575483163849; Wed, 04 Dec 2019 10:12:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575483163; cv=none; d=google.com; s=arc-20160816; b=rDvy8zy7JNi2uevikALHXyl00vtvXMiA5XYU4f+o8nd3VJRcCUogzCZPIZ8vvV+GJq /ox5Fhss0+wHRzuhb8AMux/oFc+jHAzHQ1TADDKz7NW/w5w4M20/syxs0LwD+Uz9LDYx 2OvFJBlCGyD0K4CURVB7QdYkNegZ/xC7DJ6WZ2XDFiIkaASanHMQkH3kBAuxbhw1sPCh ljY421FcNCCVhH4S55GDzSxxUtqgDtGafX8451cjI0KTxJrw/ig5YW8nVc3mP6KNnhvm 1JIb5ZHXZSlJHE37oYUciJbyZ79NsPxpPj8cFof3XvNlUQsdkiIOfiIUWC1JSiAKnTn4 +hhA== 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=Htoisbk+cPb0r2rGa8sW/V1yO3ELzeeknOzoHAJJf/o=; b=yUFqy5v6e2WCMUXkXA72DmhG4aW0aFLXmQno1ZAViCfToJoPUX6q+rJHgnXBOg79BJ 3wnGznT47DRli4q74aJgkPpGk9ggMoUl/oLeT8wjqrbobwRXvGelD7WRo6D+zx45ywvS ezyBQNgq1KD3nGbhDX0y8qmUFFay8GTmkVugqm7ED3/jLH+pApwdtyJXqk3rys8Du/n4 tKSqCG91iOJtc9bZQNDarNizIod3/nmzejis2biqxQ16c+tsoYP+eOEtsaFkNAQM5R+H BDv7gWTULxsifiU8McF92F+42j91zFUPkkJDIaKCWVnou8qdpvQCo7DGN8ocHGaqGW9e qC4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hbqJi9BG; 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 w131si3597339oif.240.2019.12.04.10.12.30; Wed, 04 Dec 2019 10:12:43 -0800 (PST) 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=hbqJi9BG; 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 S1731138AbfLDSL0 (ORCPT + 99 others); Wed, 4 Dec 2019 13:11:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:39508 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729804AbfLDSLW (ORCPT ); Wed, 4 Dec 2019 13:11:22 -0500 Received: from localhost (unknown [217.68.49.72]) (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 6C43F2086D; Wed, 4 Dec 2019 18:11:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575483081; bh=zZruYX87mevRMIX7WAXQ0HW9SLzcEcLIwjQKbU+516E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hbqJi9BGr7ug+K6uyRxGSkjL8K7Wp428gWG0L5UqhcocNPbSC4rSPQUQkBxio0qIs 6lj9BUH32p6P9XoZIcRMeot5ENavt+zHjKYDAwpESGhzxeU4HXxVeToJS4ghbSi4QJ BmXSSkSug8Cp36qFxfDyGNqP/LS0CwPLsjUvf1ak= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Dorminy , Mike Snitzer , Sasha Levin Subject: [PATCH 4.9 045/125] dm flakey: Properly corrupt multi-page bios. Date: Wed, 4 Dec 2019 18:55:50 +0100 Message-Id: <20191204175321.706574896@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204175308.377746305@linuxfoundation.org> References: <20191204175308.377746305@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: Sweet Tea [ Upstream commit a00f5276e26636cbf72f24f79831026d2e2868e7 ] The flakey target is documented to be able to corrupt the Nth byte in a bio, but does not corrupt byte indices after the first biovec in the bio. Change the corrupting function to actually corrupt the Nth byte no matter in which biovec that index falls. A test device generating two-page bios, atop a flakey device configured to corrupt a byte index on the second page, verified both the failure to corrupt before this patch and the expected corruption after this change. Signed-off-by: John Dorminy Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/dm-flakey.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c index 3643cba713518..742c1fa870dae 100644 --- a/drivers/md/dm-flakey.c +++ b/drivers/md/dm-flakey.c @@ -258,20 +258,31 @@ static void flakey_map_bio(struct dm_target *ti, struct bio *bio) static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc) { - unsigned bio_bytes = bio_cur_bytes(bio); - char *data = bio_data(bio); + unsigned int corrupt_bio_byte = fc->corrupt_bio_byte - 1; + + struct bvec_iter iter; + struct bio_vec bvec; + + if (!bio_has_data(bio)) + return; /* - * Overwrite the Nth byte of the data returned. + * Overwrite the Nth byte of the bio's data, on whichever page + * it falls. */ - if (data && bio_bytes >= fc->corrupt_bio_byte) { - data[fc->corrupt_bio_byte - 1] = fc->corrupt_bio_value; - - DMDEBUG("Corrupting data bio=%p by writing %u to byte %u " - "(rw=%c bi_opf=%u bi_sector=%llu cur_bytes=%u)\n", - bio, fc->corrupt_bio_value, fc->corrupt_bio_byte, - (bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf, - (unsigned long long)bio->bi_iter.bi_sector, bio_bytes); + bio_for_each_segment(bvec, bio, iter) { + if (bio_iter_len(bio, iter) > corrupt_bio_byte) { + char *segment = (page_address(bio_iter_page(bio, iter)) + + bio_iter_offset(bio, iter)); + segment[corrupt_bio_byte] = fc->corrupt_bio_value; + DMDEBUG("Corrupting data bio=%p by writing %u to byte %u " + "(rw=%c bi_opf=%u bi_sector=%llu size=%u)\n", + bio, fc->corrupt_bio_value, fc->corrupt_bio_byte, + (bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf, + (unsigned long long)bio->bi_iter.bi_sector, bio->bi_iter.bi_size); + break; + } + corrupt_bio_byte -= bio_iter_len(bio, iter); } } -- 2.20.1