Skip to content

blockstorage: XOR blocksdir *.dat files - #28052

Merged
achow101 merged 3 commits into
bitcoin:masterfrom
maflcko:2306-fs_stuff-
Aug 5, 2024
Merged

achow101 merged 3 commits into
bitcoin:masterfrom
maflcko:2306-fs_stuff-

Conversation

@maflcko

@maflcko maflcko commented Jul 8, 2023 •

Copy link
Copy Markdown
Member

Currently the *.dat files in the blocksdir store the data received from remote peers as-is. This may be problematic when a program other than Bitcoin Core tries to interpret them by accident. For example, an anti-virus program or other program may scan them and move them into quarantine, or delete them, or corrupt them. This may cause Bitcoin Core to fail a reorg, or fail to reply to block requests (via P2P, RPC, REST, ...).

Fix this, similar to #6650, by rolling a random XOR pattern over the dat files when writing or reading them.

Obviously this can only protect against programs that accidentally and unintentionally are trying to mess with the dat files. Any program that intentionally wants to mess with the dat files can still trivially do so.

The XOR pattern is only applied when the blocksdir is freshly created, and there is an option to disable it (on creation), so that people can disable it, if needed.

@DrahtBot

DrahtBot commented Jul 8, 2023 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK TheCharlatan, hodlinator, achow101
Concept ACK jamesob, sipa, dergoegge, darosior, kristapsk
Stale ACK pablomartin4btc, willcl-ark

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28687 (C++20 std::views::reverse by stickies-v)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko maflcko changed the title XOR blocksdir *.dat files blockstorage: XOR blocksdir *.dat files Jul 8, 2023
@jamesob

jamesob commented Jul 8, 2023

Copy link
Copy Markdown
Contributor

Concept ACK. Certainly worth doing.

@sipa
sipa marked this pull request as ready for review July 8, 2023 17:27
@sipa

sipa commented Jul 8, 2023 •

Copy link
Copy Markdown
Member

Oops, I clicked wrong.

I just meant to Concept ACK.

@maflcko
maflcko marked this pull request as draft July 9, 2023 05:50
@luke-jr

luke-jr commented Jul 9, 2023

Copy link
Copy Markdown
Contributor

AFAIK there is software which reads these files intentionally. IMO they can be expected to adapt, but having the option to disable it seems like a good idea in case they aren't ready right away.

@sedited

sedited commented Jul 10, 2023

Copy link
Copy Markdown
Contributor

Strong Concept ACK.

@maflcko

maflcko commented Jul 10, 2023

Copy link
Copy Markdown
Member Author

Thanks for the feedback so far. I've kept the option to disable, but made it a simple bool instead of allowing the user to pick the XOR-key.

If someone is interested, a new commit can be added to upgrade the linearize scripts to read the XOR-key.

@dergoegge

Copy link
Copy Markdown
Member

Concept ACK

@maflcko

maflcko commented Aug 1, 2023

Copy link
Copy Markdown
Member Author

Rebased on the latest ##28060

fanquake added a commit to bitcoin-core/gui that referenced this pull request Aug 1, 2023
fa633aa streams: Teach AutoFile how to XOR (MarcoFalke)
000019e Add AutoFile::detail_fread member function (MarcoFalke)
fa7724b refactor: Modernize AutoFile (MarcoFalke)
fa8d227 doc: Remove comments that just repeat what the code does (MarcoFalke)
fafe2ca refactor: Remove redundant file check from AutoFile shift operators (MarcoFalke)
9999a49 Extract util::Xor, Add key_offset option, Add bench (MarcoFalke)

Pull request description:

  This allows `AutoFile` to roll an XOR pattern while reading or writing to the underlying file.

  This is needed for bitcoin/bitcoin#28052, but can also be used in any other place.

  Also, there are tests, so I've split this up from the larger pull to make review easier, hopefully.

ACKs for top commit:
  Crypt-iQ:
    crACK fa633aa
  willcl-ark:
    Lightly tested ACK fa633aa
  jamesob:
    reACK fa633aa ([`jamesob/ackr/28060.4.MarcoFalke.util_add_xorfile`](https://github.com/jamesob/bitcoin/tree/ackr/28060.4.MarcoFalke.util_add_xorfile))

Tree-SHA512: 6d66cad0a089a096d3f95e4f2b28bce80b349d4b76f53d09dc9a0bea4fc1b7c0652724469c37971ba27728c7d46398a4c1d289c252af4c0f83bb2fcbc6f8e90b
@DrahtBot DrahtBot removed the CI failed label Aug 1, 2023
@maflcko maflcko mentioned this pull request Jul 30, 2024
@achow101

achow101 commented Aug 5, 2024

Copy link
Copy Markdown
Member

ACK fa895c7

@maflcko

maflcko commented Aug 7, 2024

Copy link
Copy Markdown
Member Author

Follow-up ideas for this pull requests are:

@hodlinator

Copy link
Copy Markdown
Contributor

Is there some label or something that can assist people in discovering this kind of follow-up work on closed/merged PRs?

@maflcko

maflcko commented Aug 7, 2024

Copy link
Copy Markdown
Member Author

Is there some label or something that can assist people in discovering this kind of follow-up work on closed/merged PRs?

I've moved it to an issue, see #30599

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.