Skip to content

fs::create_directories causes crashes in multiple places when lacking write permission #24953

Closed

Description

@mruddy

Expected behavior

I expected for the program to keep executing, or to shutdown gracefully, after having displayed and/or logged messages/warnings telling me that write permissions are lacking on the involved filesystem resources. This can affect attempting to write to directories outside of the normal bitcoin data directory and/or blocks directory, as seen in my second example below. The nastier crashes are like the ones in the GUI settings that could happen concurrent to data modification. Those could lead to data corruption when files are not flushed, and/or data gets out of synch.

Actual behavior

The program logged a runaway exception and immediately aborted.

To reproduce

This can be reproduced in multiple ways since there are many references to fs::create_directories. Also, crashes can result from restrictive umask settings too since some calls attempt to create directories multiple levels deep.

Here are two easy ways:

  1. bitcoind "-blocksdir not writable"
    1. start with the command line: mkdir /tmp/blocks && chmod 0500 /tmp/blocks && ./src/bitcoind -blocksdir=/tmp/blocks
    2. the program will immediately crash with this logged in the console:
************************
EXCEPTION: NSt10filesystem7__cxx1116filesystem_errorE       
filesystem error: cannot create directories: Permission denied [/tmp/blocks/blocks]       
bitcoin in AppInit()
  1. bitcoin-qt "Start Bitcoin Core on system login
    1. start with the command line: mkdir -p /tmp/btc && mkdir -p /tmp/crash && chmod 0500 /tmp/crash && XDG_CONFIG_HOME=/tmp/crash ./src/qt/bitcoin-qt -debug -datadir=/tmp/btc -connect=0
    2. in the GUI go to the Settings menu and select Options...
    3. check Start Bitcoin Core on system login
      settings
    4. click OK. you will be presented with the exception as:
      exception
    5. the console will show:
************************
EXCEPTION: NSt10filesystem7__cxx1116filesystem_errorE       
filesystem error: cannot create directories: Permission denied [/tmp/crash/autostart]       
bitcoin in Runaway exception       

bitcoin-qt: ./checkqueue.h:204: CCheckQueue<T>::~CCheckQueue() [with T = CScriptCheck]: Assertion `m_worker_threads.empty()' failed.
Aborted (core dumped)

System information

This affects current master branch as of at least be7a5f2. Tested on Ubuntu 21.10.

Activity

  1. laanwj commented on Apr 23, 2022

    @laanwj
    Member

    I wouldn't consider these as bugs. The error, and even the cause of the error "permission denied" is logged or printed, right? Sure, messages could always be nicer, but there's an infinite amount of things that can be wrong with the file system, or underlying assumptions that could be broken, it's not possible to special-case all of them.

    Edit: though I have to admit this unrelated assertion error is a bit strange:

    bitcoin-qt: ./checkqueue.h:204: CCheckQueue<T>::~CCheckQueue() [with T = CScriptCheck]: Assertion `m_worker_threads.empty()' failed.
    Aborted (core dumped)
    
  2. mruddy commented on Apr 23, 2022

    @mruddy
    ContributorAuthor

    I think the 2nd example (the one in the GUI) is a good example that this is a bug because: 1) the crash can cause data loss, 2) it goes beyond the scope of thinking that everything in the data directory has to be writable by the node because it deals with a directory outside of the bitcoin node's data directory. For that one, if you don't set the env var XDG_CONFIG_HOME, like I did to make the test easily reproducible and lightweight, then the default will try to create $HOME/.config/autostart, if it does not exist. If this ends up not being considered a bug, then we should definitely document that having write permissions available on $HOME/.config is a prereq for bitcoin-qt to not crash suddenly.

  3. added a commit that references this issue on Apr 27, 2022
    0d9e61a
  4. locked and limited conversation to collaborators on Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions