Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 59C9047012F; Tue, 21 Jul 2026 19:59:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784663966; cv=none; b=JJTiFicBdh86k14smIDIUaU3/+/ByEV7mYTkpF9FP870hbub6uRY8T73N3TFAzghpxFndw/Z96CKiHLi9MLyK1YVsCUR8xJC0yVnozXlImr3mGGCi8cr4OAijDH1/H5/uVQESyZzoduJQCDDDazO7fWc7YxWAxAfABugk+/hZ2A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784663966; c=relaxed/simple; bh=PXAAOm/i6lwu5QaOG03xrN2XZsYdEDLGXhMOoT61fxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e9OADE9kJb7cc6W+S5A3FUEGTiNafYx+Px8Y6dSGF1tD8TsD/ZNqG0Gt6iT79aqab+FxPCqgi1ZVeakPAWpjcAZuO6Dp7OWgSEp82kFbZtBIgT0C0fYfUZWv4/PhZod0obcRcsUBzUborgfiQozwWMWNtnBLo9ge9v/lOZq0qoA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TswT7X2c; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="TswT7X2c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DE0B1F00A3A; Tue, 21 Jul 2026 19:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784663961; bh=bOHwh+zzF8oaiHWoxrhZl5mqRES3hR4X+86gzInsvCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TswT7X2cPv+qjIH+U2G2GSc67OiT0/oWRvvIP4MysYW7zGtAcr+ne/LHYFVe1prfn sXsx35/Tb4xi1QN0g6uTJ1QCH3uQ4p0UtK0BN3tOfkC9Mv9/rZWtjOVHpQKIM+/AIk 7RmoMLPEFJrHR3BTIhYsRHVeNgbIJXugFd9+OzcI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mikulas Patocka Subject: [PATCH 6.12 1014/1276] dm-verity: make error counter atomic Date: Tue, 21 Jul 2026 17:24:17 +0200 Message-ID: <20260721152508.695517965@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152446.065700225@linuxfoundation.org> References: <20260721152446.065700225@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikulas Patocka commit 8ec4d9c5a5cf4b61fc087f871465b1f79b393325 upstream. The error counter "v->corrupted_errs" was not atomic, thus it could be subject to race conditions. The call to dm_audit_log_target("max-corrupted-errors") may be skipped due to the races. Signed-off-by: Mikulas Patocka Assisted-by: Claude:claude-opus-4.6 Fixes: 65ff5b7ddf05 ("dm verity: add error handling modes for corrupted blocks") Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-verity-target.c | 12 +++++++----- drivers/md/dm-verity.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -238,14 +238,16 @@ static int verity_handle_err(struct dm_v char *envp[] = { verity_env, NULL }; const char *type_str = ""; struct mapped_device *md = dm_table_get_md(v->ti->table); + int ce; /* Corruption should be visible in device status in all modes */ v->hash_failed = true; - if (v->corrupted_errs >= DM_VERITY_MAX_CORRUPTED_ERRS) - goto out; - - v->corrupted_errs++; + ce = atomic_read(&v->corrupted_errs); + do { + if (ce >= DM_VERITY_MAX_CORRUPTED_ERRS) + goto out; + } while (!atomic_try_cmpxchg(&v->corrupted_errs, &ce, ce + 1)); switch (type) { case DM_VERITY_BLOCK_TYPE_DATA: @@ -261,7 +263,7 @@ static int verity_handle_err(struct dm_v DMERR_LIMIT("%s: %s block %llu is corrupted", v->data_dev->name, type_str, block); - if (v->corrupted_errs == DM_VERITY_MAX_CORRUPTED_ERRS) { + if (ce + 1 == DM_VERITY_MAX_CORRUPTED_ERRS) { DMERR("%s: reached maximum errors", v->data_dev->name); dm_audit_log_target(DM_MSG_PREFIX, "max-corrupted-errors", v->ti, 0); } --- a/drivers/md/dm-verity.h +++ b/drivers/md/dm-verity.h @@ -65,7 +65,7 @@ struct dm_verity { unsigned int hash_reqsize; /* the size of temporary space for crypto */ enum verity_mode mode; /* mode for handling verification errors */ enum verity_mode error_mode;/* mode for handling I/O errors */ - unsigned int corrupted_errs;/* Number of errors for corrupted blocks */ + atomic_t corrupted_errs;/* Number of errors for corrupted blocks */ struct workqueue_struct *verify_wq;