Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp105977lqp; Mon, 10 Jun 2024 20:50:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWGnkJdUTeN00KdUY1utsPExGoutGCzd/v7kUYRaODPLlBugJliiqoocZDK+Mmsowy5ZfmAM8/BHiDfKdhl1rVeEXgmBVGwycJGwakIrg== X-Google-Smtp-Source: AGHT+IF01NPG2OLiBuon2pHfqaxtbxihBAksbdH8hw30j7uZ9YB/HoJvEtidm+ZU9QS9MB5qFWQh X-Received: by 2002:a50:cd51:0:b0:57a:27e8:deb with SMTP id 4fb4d7f45d1cf-57c90d2f88dmr924245a12.12.1718077817569; Mon, 10 Jun 2024 20:50:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718077817; cv=pass; d=google.com; s=arc-20160816; b=XT69SimkDlH4YfABUFyqgQCuzhRkOJd4x7+sB166sViiwLtcbm1ro/WqhGIMJO1qup bK/M3q0kXu6XW9UNrHCn2Wj6hcKKKRPtLvwpgFuekrO24YL8IYa7pCI7LXILIYsgtC91 1EGiHHbIONjL1yn38qLIWMrS01aG5QoBwg7VGRUFvK/psWWdSLvDiaYDsmSTLlTLZ54p QYXKj+TY3afY60hnEFFF9GknAvqoKAYD9Bknn3nOfoMdOsJ5cujMarSWO+MeecYXS9m6 aYun+MX8XwfVic97LWOwZScPwIrvMH2W4lIAvjqYcCgCyD22Qj4gtCBq44cYW8ZZ3fED 6LYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=69W17gLZpAACfZtOJqDyysx9mmEjR6dZlcNfzSr6Sp8=; fh=VNAK3rZTmzGmLjsPiuN/ds8cSSZe1Uv1lmlL2pGWyq4=; b=DML8HR3ALO0a4wBjGsC43jhRL17iOsNQmCkhpEnqGRuPtWJiFoOZuStw8mUa7hKzRA U+Ff3CtwuVqdShW9j76Epq2CghrMFMSvMV3YLdZnRQvGVCp4SxuiZYnZOgS3U37W+7Eo oI4R65xwn3BjokBeSDWTQXw6h4cDYqj3rBhefM/QHhDNbgMjn1982ARZn0U7PVrAkzPI SC9D2xiSRm9W4oTYmkgujtQZXrBuSujlXw/exCtYbpE58szyJssSMzs6VJacyb64AWRw O0Zc4oVF5+eHs0VZgurrLwYbOHej9E8ZsYWg9G/qXvkxxRAxdI8sRM829LscSvf3hc7C DxMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EamG2Rwy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4883-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4883-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c60033b57si3810283a12.85.2024.06.10.20.50.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 20:50:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4883-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EamG2Rwy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4883-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4883-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 24CE71F23812 for ; Tue, 11 Jun 2024 03:50:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4DA0171079; Tue, 11 Jun 2024 03:49:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EamG2Rwy" X-Original-To: linux-crypto@vger.kernel.org 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 5C9E616FF23; Tue, 11 Jun 2024 03:49:14 +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=1718077754; cv=none; b=s9OLW1UsQo/JSt6mB7u5WQX88k3RhYaQXlYDVvXxYEUSsIcodUVdwO0ci7vx7z4DJB1nTNntZAG1cYMd64bWz8Ggo2Z8te0JIDUXNJcyK+F+058ra82c63fkYzLWbmEQSSsNaPKzfqQnAUcl3KWD1hXSKYtuFIxkKLDDniaQjII= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718077754; c=relaxed/simple; bh=2pM8Bh/k5bufZBnNYlFVpUc6AsryaPnDFJJisGkWbN0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hUKPf3OOA04AWSz4qxaSGdyYBLjlh9ipk2I+JKWLnQoKUrxlyRFAsRToifLqSywH8gH62DWJMARWuBanzrf1t12qItg9TqXl1c8/boUO+J0kCcF1bKbq2dfXLiAeQxcHMaTxleA5l1CP1CwleJC1tvT6hgBGqRunEjmrzgsP0tE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EamG2Rwy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1C1BC4AF48; Tue, 11 Jun 2024 03:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718077754; bh=2pM8Bh/k5bufZBnNYlFVpUc6AsryaPnDFJJisGkWbN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EamG2RwyXGvbjbh4MMQC4xjGsPU9IK2HaOrMRT1//WIbymwcVaSopdZW7v4JFwGJU UDoPCJecKhonShVEmJPhPrJdXc3NyYodQ/RJNXYsGDvdgf6D508CXHC550GwG675sa m/UMf+FblEQeIYj17AfIXnBXP0px50LqZsms6pS9S8pAQmNrl62rxyJwbQqaTqUwe5 9k2kvMYsnTeG4VVVW0VMn22xG6JXnSads1CsRk8lfh+tghXNjzRO51H6HocdBmLESq mMOV7aaRQYsf4XW17GN9gPtaeJOVmn5MuOALuBCPpjirtVt1zd/AFai8F7vNoI2441 3RWQDO+TUS1qg== From: Eric Biggers To: linux-crypto@vger.kernel.org, fsverity@lists.linux.dev, dm-devel@lists.linux.dev Cc: x86@kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Sami Tolvanen , Bart Van Assche , Herbert Xu Subject: [PATCH v5 08/15] dm-verity: move data hash mismatch handling into its own function Date: Mon, 10 Jun 2024 20:48:15 -0700 Message-ID: <20240611034822.36603-9-ebiggers@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240611034822.36603-1-ebiggers@kernel.org> References: <20240611034822.36603-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Eric Biggers Move the code that handles mismatches of data block hashes into its own function so that it doesn't clutter up verity_verify_io(). Signed-off-by: Eric Biggers --- drivers/md/dm-verity-target.c | 64 ++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index 88d2a49dca43..796d85526696 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -540,10 +540,42 @@ static noinline int verity_recheck(struct dm_verity *v, struct dm_verity_io *io, mempool_free(page, &v->recheck_pool); return r; } +static int verity_handle_data_hash_mismatch(struct dm_verity *v, + struct dm_verity_io *io, + struct bio *bio, sector_t blkno, + struct bvec_iter *start) +{ + if (static_branch_unlikely(&use_bh_wq_enabled) && io->in_bh) { + /* + * Error handling code (FEC included) cannot be run in the + * BH workqueue, so fallback to a standard workqueue. + */ + return -EAGAIN; + } + if (verity_recheck(v, io, *start, blkno) == 0) { + if (v->validated_blocks) + set_bit(blkno, v->validated_blocks); + return 0; + } +#if defined(CONFIG_DM_VERITY_FEC) + if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_DATA, blkno, + NULL, start) == 0) + return 0; +#endif + if (bio->bi_status) + return -EIO; /* Error correction failed; Just return error */ + + if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA, blkno)) { + dm_audit_log_bio(DM_MSG_PREFIX, "verify-data", bio, blkno, 0); + return -EIO; + } + return 0; +} + static int verity_bv_zero(struct dm_verity *v, struct dm_verity_io *io, u8 *data, size_t len) { memset(data, 0, len); return 0; @@ -632,39 +664,15 @@ static int verity_verify_io(struct dm_verity_io *io) if (likely(memcmp(verity_io_real_digest(v, io), verity_io_want_digest(v, io), v->digest_size) == 0)) { if (v->validated_blocks) set_bit(cur_block, v->validated_blocks); continue; - } else if (static_branch_unlikely(&use_bh_wq_enabled) && io->in_bh) { - /* - * Error handling code (FEC included) cannot be run in a - * tasklet since it may sleep, so fallback to work-queue. - */ - return -EAGAIN; - } else if (verity_recheck(v, io, start, cur_block) == 0) { - if (v->validated_blocks) - set_bit(cur_block, v->validated_blocks); - continue; -#if defined(CONFIG_DM_VERITY_FEC) - } else if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_DATA, - cur_block, NULL, &start) == 0) { - continue; -#endif - } else { - if (bio->bi_status) { - /* - * Error correction failed; Just return error - */ - return -EIO; - } - if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA, - cur_block)) { - dm_audit_log_bio(DM_MSG_PREFIX, "verify-data", - bio, cur_block, 0); - return -EIO; - } } + r = verity_handle_data_hash_mismatch(v, io, bio, cur_block, + &start); + if (unlikely(r)) + return r; } return 0; } -- 2.45.1