From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08AFC13B2B8; Tue, 27 Feb 2024 14:25:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709043901; cv=none; b=Eo+E97+FegwPHDKl36ILtWJrLNZAJWtuwR39NV4bdw/ysKex205kHad3n37BMPhXZh5cFlKO40d1Ui6OZG2jK3aglR+1Ur727TljDtvpmJJq8d4irjYndJ0Ovr7QBmrDKXHIWb0Kw5PhNIxEMxCpOJ6GezeUYE8pscVD96SqdQ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709043901; c=relaxed/simple; bh=SsFKL5kUxnYBMCRlebLm6t0sR32ljhtGJgEabGzZlEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NlH07IRkuc39TmtMAnvJ0tH6FpXQrLr8z+6bj36lCUHxyFz1pVLdauxV6cdKNHUYms6aNIb9QO9dOq8/Aatln5i3SNxnc2sumxsFEJYB5m7xIB1LjamU+0OvuaMZRwHkYN37ccwTU2SRdJzBoFkieXJVI02ShrNwnepE1GqJ0Jg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JVy71mx1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JVy71mx1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57818C433C7; Tue, 27 Feb 2024 14:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709043900; bh=SsFKL5kUxnYBMCRlebLm6t0sR32ljhtGJgEabGzZlEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JVy71mx1HyL38BI0oiJ7qLke3X4wTdRughwFxtrSmturSVPw/VssylPQrUnzySixP 0uTaR2SHdyEXzBNO57ApG+PWAZ7pW9iy4VCyOu3+XZltfVIl12eUa6x6McKq90cJe2 QvxfmoPixWa+PFb2zcusc1H2XruaDHsOJ009z+Fs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mikulas Patocka , Mike Snitzer , Sasha Levin Subject: [PATCH 5.4 47/84] dm-integrity: dont modify bios immutable bio_vec in integrity_metadata() Date: Tue, 27 Feb 2024 14:27:14 +0100 Message-ID: <20240227131554.401660652@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227131552.864701583@linuxfoundation.org> References: <20240227131552.864701583@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikulas Patocka commit b86f4b790c998afdbc88fe1aa55cfe89c4068726 upstream. __bio_for_each_segment assumes that the first struct bio_vec argument doesn't change - it calls "bio_advance_iter_single((bio), &(iter), (bvl).bv_len)" to advance the iterator. Unfortunately, the dm-integrity code changes the bio_vec with "bv.bv_len -= pos". When this code path is taken, the iterator would be out of sync and dm-integrity would report errors. This happens if the machine is out of memory and "kmalloc" fails. Fix this bug by making a copy of "bv" and changing the copy instead. Fixes: 7eada909bfd7 ("dm: add integrity target") Cc: stable@vger.kernel.org # v4.12+ Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/md/dm-integrity.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c index 81157801a3dc6..f3246f7407d61 100644 --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -1582,11 +1582,12 @@ static void integrity_metadata(struct work_struct *w) } __bio_for_each_segment(bv, bio, iter, dio->bio_details.bi_iter) { + struct bio_vec bv_copy = bv; unsigned pos; char *mem, *checksums_ptr; again: - mem = (char *)kmap_atomic(bv.bv_page) + bv.bv_offset; + mem = (char *)kmap_atomic(bv_copy.bv_page) + bv_copy.bv_offset; pos = 0; checksums_ptr = checksums; do { @@ -1595,7 +1596,7 @@ static void integrity_metadata(struct work_struct *w) sectors_to_process -= ic->sectors_per_block; pos += ic->sectors_per_block << SECTOR_SHIFT; sector += ic->sectors_per_block; - } while (pos < bv.bv_len && sectors_to_process && checksums != checksums_onstack); + } while (pos < bv_copy.bv_len && sectors_to_process && checksums != checksums_onstack); kunmap_atomic(mem); r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset, @@ -1615,9 +1616,9 @@ static void integrity_metadata(struct work_struct *w) if (!sectors_to_process) break; - if (unlikely(pos < bv.bv_len)) { - bv.bv_offset += pos; - bv.bv_len -= pos; + if (unlikely(pos < bv_copy.bv_len)) { + bv_copy.bv_offset += pos; + bv_copy.bv_len -= pos; goto again; } } -- 2.43.0