Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid db page layout #15498

Open
serathius opened this issue Mar 17, 2023 · 9 comments
Open

Invalid db page layout #15498

serathius opened this issue Mar 17, 2023 · 9 comments
Labels
priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. stage/tracked type/bug

Comments

@serathius
Copy link
Member

serathius commented Mar 17, 2023

What happened?

Etcd started crashlooping with

From etcd logs:

panic: runtime error: slice bounds out of range [:8] with capacity 5

goroutine 111 [running]:
go.etcd.io/etcd/mvcc.bytesToRev(0x7f760418e0b0, 0x5, 0x5, 0x0, 0x17f7780)
        /go/src/go.etcd.io/etcd/mvcc/revision.go:58 +0x85
go.etcd.io/etcd/mvcc.restoreIntoIndex.func1(0xc000070000, 0xc000074720, 0x11edc08, 0xc00017d620, 0xc00024a060)
        /go/src/go.etcd.io/etcd/mvcc/kvstore.go:515 +0x287
created by go.etcd.io/etcd/mvcc.restoreIntoIndex
        /go/src/go.etcd.io/etcd/mvcc/kvstore.go:490 +0xaf

When analysing the db file I found invalid etcd db file layout.
Under bucket branch page, in keys bucket there was a branch page linking to another bucket branch page.
This resulted in bbolt returning key alarm when reading whole keys bucket. This is correct layout for bbolt, but not for etcd.

From etcd point of view this is invalid as it assumes that all keys in keys bucket are revision numbers.
Panic from above comes from bytesToRev function that parses revision. It failed as main rev has 8 bytes, while key "alarm" has only 5 bytes.

This means that at some point bbolt either:

  • overridden page that was in use with buckets page
  • incorrectly pointed branch page into buckets page

We can't exclude hardware issue that resulted in memory corruption.

Providing the dump.txt for further investigation

What did you expect to happen?

Want to report the issue to start the discussion of etcd handling potential memory corruptions.

Assuming that this was indeed a memory corruption, I expect that should avoid writing corrupted page to disk.
Running mmapped memory comes with risk with memory stamping, etcd should have mechanism that prevent corruption from being persisted.

Was discussing with @ptabor idea of protected mode for bbolt where it would verifying every write to ensure corruptions are not persisted.

How can we reproduce it (as minimally and precisely as possible)?

Don't think so.

Anything else we need to know?

No response

Etcd version (please run commands below)

v3.4.21

Etcd configuration (command line flags or environment variables)

Nothing unusual

Etcd debug information (please run commands below, feel free to obfuscate the IP address or FQDN in the output)

N/A

Relevant log output

No response

@serathius
Copy link
Member Author

cc @ahrtr @ptabor

@serathius serathius added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Mar 17, 2023
@ahrtr
Copy link
Member

ahrtr commented Mar 18, 2023

Please attached db file if possible.

@serathius
Copy link
Member Author

No db file, only the mentioned dump with data redacted.

@ahrtr
Copy link
Member

ahrtr commented Mar 20, 2023

This issue seems similar to etcd-io/bbolt#402

@ahrtr
Copy link
Member

ahrtr commented Apr 29, 2023

Under bucket branch page, in keys bucket there was a branch page linking to another bucket branch page.

It doesn't help to provide such vague info, please provide at least all related page IDs next time.

It's also most likely incorrect info, I do not see any dedicated alarm pages at all, since the pageID is 0, which means there is no any alarm or it's inline page.

@ahrtr
Copy link
Member

ahrtr commented Apr 30, 2023

One branch item somehow pointed to an old root page. The other abnormal point is that two meta pages pointed to the same root page (690).

image

@cenkalti
Copy link
Member

@ahrtr Just wondering, how did you draw that diagram? Is there any bbolt specific tool for that or did you use a general tool?

@ahrtr
Copy link
Member

ahrtr commented May 20, 2023

@ahrtr Just wondering, how did you draw that diagram? Is there any bbolt specific tool for that or did you use a general tool?

https://www.umlet.com/

@stale
Copy link

stale bot commented Sep 17, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 17, 2023
@ahrtr ahrtr added stage/tracked and removed stale labels Sep 18, 2023
missinglink pushed a commit to missinglink/bbolt that referenced this issue Dec 5, 2023
A no-op write transaction has two consequences:
    1. The txid increases by 1;
    2. Two meta pages point to the same root page.

Please also read etcd-io/etcd#15498 (comment).

Signed-off-by: Benjamin Wang <wachao@vmware.com>
passiondev2024 added a commit to passiondev2024/bbolt that referenced this issue Mar 20, 2024
A no-op write transaction has two consequences:
    1. The txid increases by 1;
    2. Two meta pages point to the same root page.

Please also read etcd-io/etcd#15498 (comment).

Signed-off-by: Benjamin Wang <wachao@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. stage/tracked type/bug
Development

No branches or pull requests

3 participants