Project

General

Profile

Actions

Bug #80848

closed
LS LS

erasure-code/clay: wrong parity and garbage reconstruction since tentacle (SIMD_ALIGN 32 -> 64)

Bug #80848: erasure-code/clay: wrong parity and garbage reconstruction since tentacle (SIMD_ALIGN 32 -> 64)

Added by Lumir Sliva 2 months ago. Updated about 2 months ago.

Status:
Resolved
Priority:
High
Assignee:
Category:
EC Pools
Target version:
-
Due date:
% Done:

0%

Source:
Community (user)
Backport:
tentacle,umbrella
Regression:
Yes
Severity:
2 - major
Reviewed:
ceph-qa-suite:
Component(RADOS):
OSD
Pull request ID:
Tags (freeform):
Fixed In:
v21.3.0-3786-gdffaf99066
Released In:
Upkeep Timestamp:
2026-10-14T13:08:37+00:00

Description

Since tentacle, CLAY computes wrong parity and returns garbage whenever it has to rebuild a lost data shard, for profiles where the sub-chunk size isn't a multiple of 64 bytes. With the default 4 KiB stripe unit that's k=12 m=4, k=10 m=4, k=16 m=4 and k=6 m=3. squid is not affected. FastEC doesn't support CLAY, so this is the legacy EC path.

Reported against a production 19.2.3 to 20.2.4 upgrade with CLAY 12+4 RGW and RBD pools, allow_ec_optimizations=false. RGW clients got EIO, RBD clients got corrupted filesystems, and the cluster log shows a different CRC on every read of the same object:

cluster [ERR]  full-object read crc 0x1190e9bb != expected 0x4361438b on <obj>:head
cluster [ERR]  full-object read crc 0x4882653b != expected 0x4361438b on <obj>:head
cluster [ERR]  full-object read crc 0x8439aaf3 != expected 0x4361438b on <obj>:head

Cause

commit 216eb2635c2 ("erasure-code: Increase SIMD_ALIGN from 32 to 64", https://github.com/ceph/ceph/pull/60246) is in every tentacle release. CLAY works plane by plane on sub-chunks, which are substr_of() views into U_buf and the coupled chunks, and before every inner jerasure call it runs rebuild_aligned[_size_and_memory](..., SIMD_ALIGN) on those views. For k=12 m=4 d=15 a chunk has 256 sub-chunks of 32 bytes. With SIMD_ALIGN=32 the views stayed in place; with 64 every odd sub-chunk gets copied, the inner decode writes into the copy, and the result is lost.

Parity goes through the same decode_layered() path (the parity shards are the erasures), so:

  • encode writes wrong parity. Data shards are fine, so healthy reads look fine, and deep-scrub can't see it because hinfo is computed over the wrong parity
  • decode returns the lost shard's output buffer unwritten (uninitialised memory plus stale U_buf planes), which is why the CRC changes on every read. With a data digest that's EIO; without one (after partial writes, e.g. RBD) the client gets the garbage
  • recovery and backfill write corrupt shards (deep-scrub reports ec_hash_error on non-overwrite pools)
  • partial writes to a degraded stripe rebuild the rest of the stripe from parity and write it back as data

Reproducer

vstart, 17 OSDs, CLAY k=12 m=4, no overwrites, allow_ec_optimizations=false. Write objects of 100 B to 4 MiB with rados put, stop one OSD with noout set, read them back:

  • v19.2.3: all reads correct
  • v20.2.4: EIO on every object that needs the lost data shard, a different CRC per read in the cluster log
  • jerasure and ISA 12+4 on the same cluster: all reads correct

Plugin-only, no cluster: load CLAY through ErasureCodePluginRegistry, encode one 98304 byte stripe, decode it repeatedly from the same 12 shards. v20.2.4 gives 20/20 wrong results with 12 distinct CRCs; the same plugin rebuilt with only SIMD_ALIGN = 32 is 20/20 correct and matches 19.2.3. Parity shards pulled off BlueStore with ceph-objectstore-tool match what the plugin computes outside the OSD, with the wrong sub-chunks at exactly the misaligned offsets.

profile sub-chunk bytes v20.2.4
k=2 m=2, k=4 m=2, k=4 m=3/4 256-1024 ok
k=8 m=3, k=8 m=4, k=6 m=4 64 ok
k=6 m=3 d=8 160 broken
k=10 m=4, k=12 m=4, k=16 m=4 32 broken

CI didn't catch this: the CLAY round-trip tests in TestErasureCodeClay.cc have been DISABLED_ since commit 0a9e718d41e and only used k=2..4, and ceph-erasure-code-corpus has no CLAY entries.

Fix

Stop realigning the sub-chunk views in ErasureCodeClay.cc. The outputs are written in place, so they get a contiguity assert instead; the inner codes ran on 32-byte aligned sub-chunks for all of squid. Plus an enabled round-trip test with 32-byte sub-chunks, which fails without the fix. PR to follow.

Existing data

The fix doesn't repair anything already written. Objects written or modified on 20.x in an affected pool have bad parity and need a whole-object rewrite with a fixed OSD; partial rewrites only fix the stripes they touch. Until then, losing a data shard of such an object means losing that data, so affected clusters should keep every OSD up and avoid pg repair on the unpatched version. Probably needs a release note.


Files

README.md (5.59 KB) README.md Lumir Sliva, 09/24/2026 12:57 PM
evidence.txt (6 KB) evidence.txt Lumir Sliva, 09/24/2026 12:57 PM
unittest-main.txt (2.28 KB) unittest-main.txt Lumir Sliva, 09/24/2026 12:57 PM
clay-subchunk-in-place-decode.patch (7.13 KB) clay-subchunk-in-place-decode.patch Lumir Sliva, 09/24/2026 12:57 PM
clay_decode.cc (4.06 KB) clay_decode.cc Lumir Sliva, 09/24/2026 12:57 PM
clay_repro.sh (1.14 KB) clay_repro.sh Lumir Sliva, 09/24/2026 12:57 PM
getshard.sh (895 Bytes) getshard.sh Lumir Sliva, 09/24/2026 12:57 PM
swap_plugin.sh (1.16 KB) swap_plugin.sh Lumir Sliva, 09/24/2026 12:57 PM
vstart-cluster-log-crc-lines.txt (5.99 KB) vstart-cluster-log-crc-lines.txt Lumir Sliva, 09/24/2026 12:57 PM

Related issues 2 (0 open — 2 closed)

Copied to RADOS - Backport #81138: umbrella: erasure-code/clay: wrong parity and garbage reconstruction since tentacle (SIMD_ALIGN 32 -> 64)ResolvedRadoslaw Zarzynski

Actions
Copied to RADOS - Backport #81139: tentacle: erasure-code/clay: wrong parity and garbage reconstruction since tentacle (SIMD_ALIGN 32 -> 64)ResolvedRadoslaw Zarzynski

Actions

LS Updated by Lumir Sliva 2 months ago Actions #1

  • Severity changed from 1 - critical to 2 - major

LS Updated by Lumir Sliva 2 months ago Actions #2

Attaching the reproducer and the raw output, so all of this can be checked without taking my word for it:

  • README.md: how to run everything below, plugin-only and on vstart
  • evidence.txt: harness runs (v20.2.4 unpatched, fixed, v19.2.3, and the same plugin with only SIMD_ALIGN 32 vs 64), the profile matrix, parity shards pulled off BlueStore compared with the plugin output, and valgrind showing the parity and decode output buffers are never written
  • unittest-main.txt: on main 98fb1cf8c58 the new ErasureCodeClay.encode_decode_small_subchunks fails on every erasure pattern without the fix and passes with it; unittest_erasure_code_plugin_clay passes too
  • clay-subchunk-in-place-decode.patch: fix plus test, against main (applies to v20.2.4 as well)
  • clay_decode.cc: the standalone plugin harness
  • clay_repro.sh, getshard.sh, swap_plugin.sh: cluster repro, shard extraction with ceph-objectstore-tool, and swapping libec_clay.so in a running vstart
  • vstart-cluster-log-crc-lines.txt: the full-object read crc lines from the v20.2.4 vstart during degraded reads

PR with the fix to follow shortly.

LS Updated by Lumir Sliva 2 months ago Actions #3

  • Pull request ID set to 72056

RZ Updated by Radoslaw Zarzynski 2 months ago Actions #4

  • Status changed from In Progress to Fix Under Review

Fix approved, has been taken into QA.

RZ Updated by Radoslaw Zarzynski 2 months ago Actions #5

The (speculative) backport for Tentacle is here: https://github.com/ceph/ceph/pull/72182. The formal ticket for it will be created after merging the main PR.

MS Updated by Michal Strnad 2 months ago Actions #6

Hi.

Thank you very much for all your help.

We tested the patch on our testbed and deployed it to production over the past few days. We are now discussing how to detect potentially corrupted data and what tools or procedures we can provide to users so that they can verify the integrity of their data.

To begin with, I would like to provide a brief overview of our environment to establish the necessary context and describe the protocols involved.

We have a 23 PiB cluster that has been affected by this bug. Our users use both S3 and RBD. RBD devices are attached to their systems, typically remote servers, where users create a filesystem of their choice and use it as they see fit, for example, for databases, backups written directly to the filesystem, and other workloads.

First, we would like to ask you to verify our current understanding of the issue. Our hypothesis can be summarized in the following scenarios:

1. Data written either before or after the upgrade to 20.2.4 (Squid → Tentacle), where the corresponding PG has not undergone any recovery, backfill, or repair since the upgrade:
The data shards themselves should still be intact. For data written after the upgrade, however, the parity may have been generated incorrectly due to the CLAY bug.

2. Data written either before or after the upgrade to 20.2.4, where the corresponding PG subsequently underwent recovery, backfill, or repair while running the affected 20.2.4 code - for example, due to an OSD failure, disk replacement, or cluster rebalancing:
Such data may potentially have become corrupted during reconstruction, even if the original data shards had been written correctly.

In other words, our understanding is that the situation for data written before and after the upgrade to 20.2.4 is largely similar, with one important difference: objects written after the upgrade may additionally have incorrect parity generated by the affected CLAY implementation.

The key question we would therefore like to clarify is:

Can data written before the upgrade to 20.2.4 also be corrupted by this bug? If so, does this require a subsequent recovery/backfill/repair operation involving the affected object/PG, or could pre-upgrade data become corrupted even if no such operation occurred after the upgrade?

Confirming this distinction is very important for us, as it may allow us to narrow down the set of objects that need to be considered potentially affected.

Thank you very much
Michal Strnad

MS Updated by Michal Strnad 2 months ago Actions #7

I would also like to add a few important questions:

1. If any of the data shards is corrupted (i.e., it was subsequently reconstructed using incorrect parity), can we rely on RADOS to always detect this and refuse to return the object to the client (for example, with a `full-object read crc` error)?

Conversely, if RADOS successfully returns an object without any error, can we rely on the returned content being exactly the same as the content that was originally written?

2. Are there any integrity mechanisms at higher layers that can be used to verify object consistency or detect corruption? For example, can the S3 ETag or any other metadata/checksum maintained by RGW be reliably used for this purpose?

3. Based on our current understanding, a scrub/deep-scrub is unlikely to repair a PG affected by this particular issue. It also appears that there may be no existing mechanism capable of automatically recovering or repairing even a subset of the affected data once corruption has occurred.

Could you please explicitly confirm whether this assumption is correct? If there is any mechanism that could recover at least some of the affected objects, we would greatly appreciate details on how it could be used.

Thank you very much

LS Updated by Lumir Sliva 2 months ago · Edited 1Actions #8

Short version: yes, data written before the upgrade can be damaged, but only by a few specific operations, and a healthy read, a deep-scrub or a snapshot isn't one of them. The rule per object:

  • data shards written by a client are correct
  • parity written by a 20.x OSD before the fix is wrong
  • any shard rebuilt by decode on a 20.x OSD is wrong if it was rebuilt before the fix, and also after the fix if it was rebuilt from wrong parity
  • the object is recoverable from RADOS as long as it still has k correct shards

Line numbers below are from v20.2.3, the code is the same in 20.2.4.

Your two scenarios

Scenario 1: right, with one exception: a partial write while the PG is degraded. On a pool with allow_ec_overwrites, a partial overwrite reads the rest of the stripe, and if a data shard of that stripe is missing it's rebuilt by decode and written back to all shards as data. So the data shards change without any recovery of that object, and silently, because the partial write also drops data_digest. Objects written before the upgrade get hit the same way. That's my best guess for the broken RBD filesystems: OSDs restarting during the upgrade while VMs kept writing. Pools without overwrites only accept whole-object writes and appends at the end of the object (PrimaryLogPG.cc:6757-6766), so they have no read-modify-write and this case doesn't exist there.

Scenario 2: right, with two refinements:

  • Only a shard that's actually decoded goes bad. If the previous holder of that shard is still up and in the acting set (a normal rebalance with pg_temp), the shard is copied: get_all_avail_shards() offers it (ECCommonL.cc:220-240), minimum_to_decode() returns just that shard, and ErasureCode::_decode() copies it without decoding (ErasureCode.cc:383-391). Decode happens when the holder is down or gone: OSD failure, disk replacement, an OSD marked out while down, log-based recovery of objects written while an OSD was down, and pg repair. That's from the code; I haven't tested the rebalance-with-everything-up case separately.
  • For an object written before the upgrade and not modified since, one bad shard still leaves 15 good ones, so it can be repaired (see 3 below). The data is really lost only for objects written on 20.x that also had a data shard rebuilt, since their parity is wrong as well.

The rebuild risk doesn't end with the patch for objects written on 20.x. With the fixed plugin, rebuilding a data shard of such an object from its wrong parity still gives garbage: in the lab, a pool written by 20.2.4 and read degraded with the fixed plugin returned EIO on 8 objects. So keep every OSD up until those objects are rewritten.

The key question

Data written before the upgrade and not modified since is intact on disk, data and parity, unless one of its shards was rebuilt by decode on a 20.x OSD. Nothing else touches it: healthy reads only read the data shards, deep-scrub reads and hashes each shard, and a snapshot clone on EC is a local clone of each shard with no encode or decode.

What RADOS can't tell you is what clients did with garbage from degraded reads. RBD reads aren't checked at all (below), so a filesystem or database that read garbage and wrote it back stored it as a normal write, and RADOS now returns it correctly.

For RBD, rados stat on the rbd_data.* objects gives the client time of the last write, so an mtime before the first 20.2.4 OSD started means the object wasn't written on 20.x. For RGW don't rely on it: the head object's mtime is set explicitly (rgw_rados.cc:3324-3325) and can carry the source's time for multisite-synced or copied objects.

Your follow-up questions

1. Does RADOS always catch it?

No.

  • RBD: nothing checks. librbd reads with sparse-read, which on an EC pool becomes a plain read without any digest check (PrimaryLogPG.cc:5954-5968). Partial writes clear data_digest anyway (PrimaryLogPG.cc:6836-6847), and pools with allow_ec_overwrites keep no per-shard hash (ECBackendL.cc:1109). A data shard rebuilt wrong is returned as it is, without an error, even with all OSDs up and the fixed plugin.
  • RGW on a pool without overwrites: two checks. Each OSD verifies its shard against the stored hinfo when it reads the whole shard (ECBackendL.cc:1137-1150, "Bad hash for ..." in the cluster log), and the primary then rebuilds the object from the other shards. The primary verifies the reassembled object against data_digest when the read covers the whole RADOS object (PrimaryLogPG.cc:5881-5883 and 5405-5416), which gives you the "full-object read crc" EIO. RGW objects carry data_digest because RGW writes them with write_full plus appends (rgw_putobj_processor.cc:177-181, osd_skip_data_digest defaults to false). So a full read that returns without an error is correct. A read that doesn't cover the whole RADOS object, e.g. an S3 Range GET, skips both checks and can return garbage silently. A plain GET with the default rgw_get_obj_max_req_size (4 MiB) should read each 4 MiB RADOS object in one piece; that's from the code, I haven't tested every read shape.
  • In every pool: if a client read garbage and wrote it back, RADOS returns that garbage without an error, because to RADOS it's valid data.

2. Checks at higher layers

  • RGW: the ETag is the MD5 of the uploaded bytes, computed before compression and encryption (rgw_op.cc:4641-4645), so GET plus md5 against the ETag is an end-to-end check that doesn't depend on how RADOS reads. For multipart objects the ETag is the MD5 of the concatenated binary part MD5s plus a -N suffix. RGW supports GET ?partNumber=N, so fetch each part, md5 it and recompute. That doesn't cover Swift DLO/SLO manifests, which don't get a data MD5. Objects uploaded with x-amz-checksum-* also return the stored checksum on GET with x-amz-checksum-mode: ENABLED. Run all of this with all OSDs up and the fixed plugin everywhere, otherwise degraded reads add noise.
  • RBD: nothing in librbd or RADOS. Only in the guest: btrfs and ZFS scrub cover file data; ext4 metadata_csum and XFS v5 cover metadata only, so fsck finds metadata damage but not damaged file contents; database page checksums (PostgreSQL data checksums, InnoDB) and backup tools with a verify mode cover their own data. RBD snapshots taken before the upgrade keep the pre-upgrade content of objects modified since (the clone is a local copy of each shard), subject to the same caveat about shards rebuilt on 20.x.

3. Scrub and repair

Mostly right, and one exception gets you a subset back:

  • deep-scrub can't see wrong parity written by encode, because hinfo was computed over that same parity. Confirmed in the lab: 0 inconsistent on a pool written by 20.2.4.
  • On pools without overwrites (RGW), deep-scrub does see shards written by a buggy rebuild, as ec_hash_error (rados list-inconsistent-obj <pgid>). In the lab, one OSD down and backfilled on 20.2.4 gave 12 inconsistent PGs and 18 scrub errors.
  • pg repair with the fixed plugin on every OSD heals those for objects whose other shards are good, i.e. written before the upgrade and not modified since. In the lab it cleared all 9 PGs the buggy backfill had damaged, and reads were correct afterwards. Don't repair while any OSD still runs the old plugin, and keep osd_scrub_auto_repair off (the default) until then.
  • For objects written on 20.x, repair can't help: a data shard is rebuilt from the wrong parity again, and a parity shard is rebuilt correctly but then fails the stale hinfo, so the PG stays inconsistent. Those need a whole-object rewrite while their data shards are intact. For RGW, radosgw-admin object rewrite and bucket rewrite read and write the data again (RGWRados::rewrite_obj() calls copy_obj_data(), rgw_rados.cc:3887-3916), so they should re-encode with the fixed plugin and get the read checks from 1. I haven't tested them against this bug.
  • On RBD pools deep-scrub has nothing to compare, so a wrongly rebuilt shard there is invisible. For an object not modified since the upgrade the other 15 shards are still good, so it's recoverable in principle: remove the bad shard with ceph-objectstore-tool and let pg repair rebuild it with the fixed plugin (that's how I tested a parity shard in the lab, on a pool without overwrites). You'd need to know which shard: a PG and position whose OSD changed while the previous holder was down, which you can get from the osdmap history (ceph osd getmap <epoch> plus osdmaptool --test-map-pgs-dump) if the mons still have those epochs (osdmap_first_committed in ceph report). I haven't tried this on an overwrite pool; happy to run it in the lab before you rely on it.
  • An object written on 20.x that lost a data shard can't be rebuilt from its parity. The wrong parity can't be inverted: on 12+4, parity shards 13 and 15 are wrong everywhere and the odd sub-chunks of 12 and 14 are uninitialised memory. The only way left is the original bytes, e.g. if the old OSD's disk is still readable, ceph-objectstore-tool can export the shard from it.

If you can share which of the affected pools have allow_ec_overwrites and whether the mons still hold osdmaps from before the upgrade, I can go through the narrowing per pool with you.

AA Updated by Alex Ainscow 2 months ago · Edited Actions #9

Lumir,

Thankyou for your very detailed reply, there is not much I can add here.

  • The only addition I can suggest is setting min_size to k+m, this doesn't prevent recovery, but it does prevent client writes if an OSD degraded.
  • You correctly state the following: "On pools without overwrites (RGW), deep-scrub does see shards written by a buggy rebuild, as ec_hash_error (rados list-inconsistent-obj <pgid>). In the lab, one OSD down and backfilled on 20.2.4 gave 12 inconsistent PGs and 18 scrub errors."
    • I just wanted to clarify that when overwrites are on, no CRC is stored across an object. This is because you cannot update the CRC without reading the entire object, which would be catastrophic for performance.
  • For rbd, there are tools such as rbd migration and rbd deep-copy. I am not too familiar with these tools personally, but I think they might be able to be used to force the rbd object re-writes you describe.
  • There is a tool upstream/umbrella (ceph_ec_consistency_checker) you might be able to backport this and use it to check the consistency of objects. However, even if you manage to get this backported its going to take an extremely long time to check 23PiB of data. But I thought I would mention it for clarity.

If you do backport ceph_ec_consistency_checker: while it checks an object, the parity-read inject on the primary affects every client's reads of that object, not just the checker's. So only check objects that aren't in use (e.g. unmapped RBD images). It also requires bluestore_debug_inject_read_err=true on the OSDs.

LF Updated by Laura Flores 2 months ago Actions #10

  • Status changed from Fix Under Review to Pending Backport

UB Updated by Upkeep Bot 2 months ago Actions #11

  • Copied to Backport #81138: umbrella: erasure-code/clay: wrong parity and garbage reconstruction since tentacle (SIMD_ALIGN 32 -> 64) added

UB Updated by Upkeep Bot 2 months ago Actions #12

  • Copied to Backport #81139: tentacle: erasure-code/clay: wrong parity and garbage reconstruction since tentacle (SIMD_ALIGN 32 -> 64) added

UB Updated by Upkeep Bot 2 months ago Actions #13

  • Status changed from Pending Backport to Backporting
  • Merge Commit set to dffaf990666f640cbe85e876be68895d85fce027
  • Fixed In set to v21.3.0-3786-gdffaf99066
  • Upkeep Timestamp set to 2026-09-29T21:43:47+00:00

UB Updated by Upkeep Bot about 2 months ago Actions #14

  • Status changed from Backporting to Resolved
  • Upkeep Timestamp changed from 2026-09-29T21:43:47+00:00 to 2026-10-14T13:08:37+00:00
Actions

Also available in: PDF Atom