Project

General

Profile

Actions

Bug #80514

open
SS GB

tentacle: rgw/dedup: buffer overflow in shard_token_oid::set_shard() aborts all radosgw daemons

Bug #80514: tentacle: rgw/dedup: buffer overflow in shard_token_oid::set_shard() aborts all radosgw daemons

Added by Supriti Singh 3 months ago. Updated 3 months ago.

Status:
New
Priority:
Normal
Target version:
-
Due date:
% Done:

0%

Source:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
09/14/2026
Affected Versions:
ceph-qa-suite:
Pull request ID:
Tags (freeform):
Merge Commit:
Fixed In:
Released In:
Upkeep Timestamp:

Description

Affected versions: tentacle (v20.2.x); main is already fixed

  1. Description

`rgw::dedup::cluster::shard_token_oid::set_shard()` writes past the end of its
buffer. With `_FORTIFY_SOURCE` enabled (the default for release builds),
`__snprintf_chk()` detects the overflow and aborts the process, taking down
every radosgw in the cluster as soon as a dedup run is started.

src/rgw/rgw_dedup_cluster.h:

static const unsigned BUFF_SIZE = 15;
char buff[BUFF_SIZE];
void set_shard(uint16_t shard) {
int n = snprintf(this->buff + this->prefix_len, BUFF_SIZE, "%03x", shard);
this->total_len = this->prefix_len + n;
}

The destination is `buff + prefix_len`, but the size limit passed is the full
`BUFF_SIZE` rather than the space remaining.

Both prefixes are 12 characters:

WORKER_SHARD_PREFIX = "WRK.SHRD.TK." 
MD5_SHARD_PREFIX = "MD5.SHRD.TK."

so only 3 of the 15 bytes remain, while `"%03x"` needs 4 bytes including the
terminating NUL. The write overruns by one byte, and the declared limit of 15
is five times the real headroom.

  1. Backtrace
    • buffer overflow detected ***: terminated
    • Caught signal (Aborted) *
      in thread 7fa48abfb6c0 thread_name:dedup_bg
      ceph version 20.2.4 tentacle (stable - RelWithDebInfo)
      4: abort()
      8: __snprintf_chk()
      9: (rgw::dedup::cluster::create_shard_tokens(rgw::sal::RadosStore
      , unsigned int, char const*)+0xe6)
      10: (rgw::dedup::cluster::reset(rgw::sal::RadosStore*, rgw::dedup::dedup_epoch_t*, unsigned short, unsigned short)+0x2ec)
      11: (rgw::dedup::Background::setup(rgw::dedup::dedup_epoch_t*)+0x30f)
      12: (rgw::dedup::Background::run()+0x1a2)
  1. Reproducer

Run the `rgw/dedup` suite against tentacle. All three radosgw daemons abort
simultaneously partway through `test_dedup.py`. Observed in 4 of 4 dedup jobs.

The crash is not hit at gateway startup: `Background::run()` only reaches
`setup()` when `d_ctl.dedup_exec` is set, i.e. once a dedup run is requested.

  1. Fix

main already carries the correct code, at
src/rgw/driver/rados/rgw_dedup_cluster.h:

static const unsigned BUFF_SIZE = 16;
int n = snprintf(this->buff + this->prefix_len,
BUFF_SIZE - this->prefix_len, "%03x", shard);

Both changes are required: passing the remaining space, and growing the buffer
to 16 so a 12 character prefix plus three hex digits plus NUL fits.

These landed in main incidentally as part of 00b36052d0f ("rgw/dedup: Add
support for RGW versions. Dedup code will scan all instances of versioned
objects and include them in the dedup process": https://github.com/ceph/ceph/commit/00b36052d0f#diff-c6489b6acb8fcf6a25ba959c26fd00108ff671c0c313b4ecb504543577aaeb01), which is a feature commit and
was never proposed for backport. That appears to be why tentacle still carries
the bug.

GB Updated by Gabriel BenHanokh 3 months ago Actions #1

  • Assignee set to Gabriel BenHanokh
  • Pull request ID set to 70023

SS Updated by Supriti Singh 3 months ago Actions #2

Thanks for the PR link.

To give more context, I saw this error in a teuthology run internally and found a similar failure in an upstream teuthology run:
https://pulpito.ceph.com/jenkins-build-2026-09-13_06:06:48-rgw-tentacle-distro-default-trial/554150/

The crash happens only if Ceph is built with -D_FORTIFY_SOURCE=3. With -D_FORTIFY_SOURCE=2 or a Debug build there is no crash. The bad write happens in all builds; only level 3 detects it and stops the process.

If the goal were just to fix this crash, the fix is two lines, and those two lines are already part of the larger PR you have created. But I am not sure whether, after fixing this crash, another error would pop out.

Meanwhile, would you say it is better to recommend that users not use radosgw-admin dedup estimate at all in tentacle? As far as I can tell it is the only dedup command tentacle exposes (dedup restart returns "Only dedup estimate is supported!"), so if the estimate is not usable then dedup is effectively unavailable in this release. I would like to document that for our users.

SS Updated by Supriti Singh 3 months ago Actions #3

Update: this is not limited to dedup estimate. dedup stats aborts as well, through a different caller.

The same upstream job (554150 in jenkins-build-2026-09-13_06:06:48-rgw-tentacle-distro-default-trial, rgw/dedup) contains four aborts from two distinct paths.

dedup estimate — aborts the radosgw daemon on its dedup background thread:

*** buffer overflow detected ***: terminated
 in thread 7f4abd1e56c0 thread_name:dedup_bg
 8: __snprintf_chk()
 9: (rgw::dedup::cluster::create_shard_tokens(...)+0xe6)
10: (rgw::dedup::cluster::reset(...)+0x2ec)
11: (rgw::dedup::Background::setup(...)+0x30f)
12: (rgw::dedup::Background::run()+0x1a2)

dedup stats — aborts the radosgw-admin process itself:

*** buffer overflow detected ***: terminated
 in thread 7fea73c00c40 thread_name:radosgw-admin
 8: __snprintf_chk()
10: (rgw::dedup::cluster::collect_all_shard_stats(rgw::sal::RadosStore*, ceph::Formatter*, DoutPrefixProvider const*)+0x2ba)
11: main()

Both are the same overflow in shard_token_oid::set_shard(), reached from different callers. There are seven call sites of set_shard() in rgw_dedup_cluster.cc:

create_shard_tokens
verify_all_shard_tokens
update_shard_token_heartbeat
mark_shard_token_completed
get_next_shard_token
all_shard_tokens_completed   (x2)

so any code path that names a shard token is affected, not just scan startup.

Of the six documented admin commands, dedup restart is refused on tentacle (Only dedup estimate is supported!). estimate and stats are confirmed to abort. abort, pause and resume are unverified in either direction: they are not exercised by the dedup test suite (which calls restart x2, estimate, abort and stats), and I have no clean way to drive them individually since a crash ends the test.

For anyone trying to reproduce: this requires a build with -D_FORTIFY_SOURCE=3. At level 2 gcc computes __builtin_object_size(buff + prefix_len) at compile time, cannot resolve the runtime offset, and emits no check. Level 3 uses __builtin_dynamic_object_size and catches it at run time. A Debug build does not link __snprintf_chk at all, so the one-byte overrun lands in trailing struct padding and goes unnoticed.

Actions

Also available in: PDF Atom