Description
It is possible to consistently cause a bitcoind process to be OOM killed on Linux (and probably termed on other operating systems) by making excessively large batched JSON RPC requests. There is currently no configurable way to limit batch sizes, so this can be done to any bitcoind instance providing the JSON RPC interfaces.
Expected Behavior
The server responds with a “batch too large” error or equivalent whenever a configured batch size limit is reached.
Actual Behavior
Bitcoind attempts to satisfy the request until it exhausts all available memory and is then OOM killed by the Linux kernel.
Reproduction
This issue can be easily reproduced under the following conditions:
- Create a fresh Bitcoin Docker image using Ubuntu Linux.
- Run the image with
-p 8332:8332 -p 8333:8333 -m=100m
to restrict the available memory to 100MB and expose RPC and chatter protocols. - Run
bitcoind
with the following flags:-testnet -rpcuser=<user> -rpcpassword=<pass> -rpcbind=0.0.0.0 -rpcallowip=0.0.0.0/0
- Wait for the first ~25,000 testnet blocks to sync.
- Execute JSON RPC batch request to
getblockhash
for the first 20,000 block hashes - Execute JSON RPC batch request
getblock(<hash>, 2)
for the first 20,000 block hashes, requesting all 20,000 blocks and included transactions in one batch response. - Bitcoin process will eventually exhaust memory and be terminated.
The bitcoind process will be OOM killed by the Linux kernel:
The socket on the RPC request will EOF:
Looking in the system logs you will see something like:
0Out of memory: kill process 1984 (bitcoind) score 910 or sacrifice child
1<snip>
2bitcoin-httpwor invoked oom-killer: gfp_mask=0x14201ca(GFP_HIGHUSER_MOVABLE|__GFP_COLD), nodemask=(null), order=0, oom_score_adj=0
Machine Type
This works on all AWS instance types running Gentoo or Ubuntu Linux, and should be reproducible on any Linux instance type that has the OOM killer enabled.
References
- Respite from the OOM killer - Good overview of the Linux OOM killer and the security issues it can cause.
- Slides: Avoid OOM On Embedded Linux - Overview of Linux kernel overcommit and issues it can cause in embedded systems.