From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4911C77B6C for ; Tue, 4 Apr 2023 18:30:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235282AbjDDSau (ORCPT ); Tue, 4 Apr 2023 14:30:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235922AbjDDSaO (ORCPT ); Tue, 4 Apr 2023 14:30:14 -0400 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A2C4975A for ; Tue, 4 Apr 2023 11:26:38 -0700 (PDT) Received: by mail-qt1-x82c.google.com with SMTP id cn12so29338397qtb.8 for ; Tue, 04 Apr 2023 11:26:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680632736; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZsI89aBxoNjXwhryh0Y5XhntM/4A2U2YcKa3v6rBxI8=; b=k3pzOvcHL2pDMPwLLkxG2MqKArQprEK2GzphbnmZ4ZnAxTPH5ihcscmS6D5mTx+TE7 TjqrqIWY/V1otnWslO4z5AEvOPoC6jDwJCECeFx4tMcwUi1Ub5QQ0sX7p8lOmL2kYIc8 PQsecET1eeKrj8ISWKhKnRBprrtWWf0mo0XefA5x5reS7GWWqLA+tE4JD262BmNc6unq n813KXBj/37v4kHEf7R1RLHZx1CJUBAheJisJslxK42+ciF0zJ4I2G7NheQBtsWa7MFH 2SzjbjZokJSffRrtzt1e4XBIp4r89WR9ALW4tvWx3rDNy6GuOhLj37nbS2/k2YOCWIeB gyWA== X-Gm-Message-State: AAQBX9dVYasCybXayFuw552lc9eZ3KsRM1XbrsaNyMGxoHRXKRbsqUpR SWgiMJP0BSp/uZYQmHSNv5MI X-Google-Smtp-Source: AKy350Yec29feyEXNVi14lFt7bOYrZ93ajKnUVjq3UUW/e4C61nOpSWfVWjceniGfdwjb3A+s+WAbQ== X-Received: by 2002:ac8:5988:0:b0:3e6:4094:8a9b with SMTP id e8-20020ac85988000000b003e640948a9bmr675413qte.58.1680632736607; Tue, 04 Apr 2023 11:25:36 -0700 (PDT) Received: from localhost (pool-68-160-166-30.bstnma.fios.verizon.net. [68.160.166.30]) by smtp.gmail.com with ESMTPSA id o24-20020a05620a229800b00748448d9a7dsm3769329qkh.106.2023.04.04.11.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:25:36 -0700 (PDT) From: Mike Snitzer To: gregkh@linuxfoundation.org Cc: stable@vger.kernel.org, bmarzins@redhat.com, Mike Snitzer Subject: [PATCH 6.1+] dm: fix improper splitting for abnormal bios Date: Tue, 4 Apr 2023 14:25:32 -0400 Message-Id: <20230404182532.34579-1-snitzer@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <2023040334-attire-drone-2c8b@gregkh> References: <2023040334-attire-drone-2c8b@gregkh> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Benjamin Marzinski Conflicts: Code changes due to missing upstream commit 86a3238c7b9b ('dm: change "unsigned" to "unsigned int"') commit f7b58a69fad9d2c4c90cab0247811155dd0d48e7 Author: Mike Snitzer Date: Thu Mar 30 14:56:38 2023 -0400 dm: fix improper splitting for abnormal bios "Abnormal" bios include discards, write zeroes and secure erase. By no longer passing the calculated 'len' pointer, commit 7dd06a2548b2 ("dm: allow dm_accept_partial_bio() for dm_io without duplicate bios") took a senseless approach to disallowing dm_accept_partial_bio() from working for duplicate bios processed using __send_duplicate_bios(). It inadvertently and incorrectly stopped the use of 'len' when initializing a target's io (in alloc_tio). As such the resulting tio could address more area of a device than it should. For example, when discarding an entire DM striped device with the following DM table: vg-lvol0: 0 159744 striped 2 128 7:0 2048 7:1 2048 vg-lvol0: 159744 45056 striped 2 128 7:2 2048 7:3 2048 Before this fix: device-mapper: striped: target_stripe=0, bdev=7:0, start=2048 len=102400 blkdiscard: attempt to access beyond end of device loop0: rw=2051, sector=2048, nr_sectors = 102400 limit=81920 device-mapper: striped: target_stripe=1, bdev=7:1, start=2048 len=102400 blkdiscard: attempt to access beyond end of device loop1: rw=2051, sector=2048, nr_sectors = 102400 limit=81920 After this fix; device-mapper: striped: target_stripe=0, bdev=7:0, start=2048 len=79872 device-mapper: striped: target_stripe=1, bdev=7:1, start=2048 len=79872 Fixes: 7dd06a2548b2 ("dm: allow dm_accept_partial_bio() for dm_io without duplicate bios") Cc: stable@vger.kernel.org Reported-by: Orange Kao Signed-off-by: Mike Snitzer Signed-off-by: Benjamin Marzinski Signed-off-by: Mike Snitzer --- drivers/md/dm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index f9a402c04666..e624a919fe55 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1460,7 +1460,8 @@ static void setup_split_accounting(struct clone_info *ci, unsigned len) } static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci, - struct dm_target *ti, unsigned num_bios) + struct dm_target *ti, unsigned num_bios, + unsigned *len) { struct bio *bio; int try; @@ -1471,7 +1472,7 @@ static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci, if (try) mutex_lock(&ci->io->md->table_devices_lock); for (bio_nr = 0; bio_nr < num_bios; bio_nr++) { - bio = alloc_tio(ci, ti, bio_nr, NULL, + bio = alloc_tio(ci, ti, bio_nr, len, try ? GFP_NOIO : GFP_NOWAIT); if (!bio) break; @@ -1507,7 +1508,7 @@ static int __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti, break; default: /* dm_accept_partial_bio() is not supported with shared tio->len_ptr */ - alloc_multiple_bios(&blist, ci, ti, num_bios); + alloc_multiple_bios(&blist, ci, ti, num_bios, len); while ((clone = bio_list_pop(&blist))) { dm_tio_set_flag(clone_to_tio(clone), DM_TIO_IS_DUPLICATE_BIO); __map_bio(clone); -- 2.30.0