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 1B94A481245; Thu, 20 Aug 2026 17:49:52 +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=1787248194; cv=none; b=b0kg92FTtAZv8DSYmoCLwuI6a7eUo12/gGN4r1o6bLcYkxeKzq4ud1mrC3LzCkthJzBaT+QX1l3rTKUNHZfgsPrRq3BndncbgvC12rfGoTFtq2pww6JVmYqHFMUcnmOS9jZhZbTGNROSTaJnA49psmEXZdxaioG9ffUKdQMbBx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787248194; c=relaxed/simple; bh=7/OguQ5aGkzt9JwCZgvJ2xImXS/ZigPramLgP+QWj60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i596yLnJVt2bzZIGyisMa5GzIXONR70itMiW7SfCiU0R6RGk5sXeuShPOdrjFK94Y0v1otqjHBiii3Z+qZJ0+tnXXhCtmMamGqjEbklgxBUAFhsVITxRkWs317RIqz4EuZOfk6aLEhe+Wo+uVIc5v4MxyrRBP1Hq8fKkFJJI8nw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=RlZAUgfB; 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="RlZAUgfB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 277441F000E9; Thu, 20 Aug 2026 17:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787248192; bh=uoXRI4U7nkYuOgT2k2v5KBYFljQDg/DIlL+cfcq9A2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RlZAUgfBKJwAV6SCNquRRdD4/dmQ2ju+iYumYkaplRi3O7hvPh+uff8X+PukFZ6MM J+hzl6Rk+tVp/ngvlEwf8SGka2iH0bH26nNm0Ho8FHRXbkI/4Bz9CtV69dpmYIPkhk AadVH7tra7NvVw2rlsO7xBxBbDjTB7PWvM4ojxWM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mikulas Patocka , Sasha Levin Subject: [PATCH 6.1 141/303] dm-verity: make error counter atomic Date: Thu, 20 Aug 2026 16:54:37 +0200 Message-ID: <20260820145257.519478382@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260820145253.200766705@linuxfoundation.org> References: <20260820145253.200766705@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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikulas Patocka [ Upstream commit 8ec4d9c5a5cf4b61fc087f871465b1f79b393325 ] 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: Sasha Levin 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 @@ -225,14 +225,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: @@ -248,7 +250,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); snprintf(verity_env, DM_VERITY_ENV_LENGTH, "%s=%d,%llu", --- a/drivers/md/dm-verity.h +++ b/drivers/md/dm-verity.h @@ -58,7 +58,7 @@ struct dm_verity { unsigned int digest_size; /* digest size for the current hash algorithm */ unsigned int ahash_reqsize;/* the size of temporary space for crypto */ enum verity_mode mode; /* mode for handling verification 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;