GHSA-v666-6w97-pcwm: Ckb Miner Fails To Get Block Vulnerability

HIGH
CWE-367
Published
Advisory Summary

GHSA-v666-6w97-pcwm is a HIGH miner fails to get block vulnerability (CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition) affecting Ckb libraries in the crates.io ecosystem. The issue involves miner fails to get block template when a cell used as a cell dep has been destroyed.. Remediation is available by upgrading affected packages to version 0.40.0.

GHSA-v666-6w97-pcwm at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-v666-6w97-pcwm
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition
Affected Product Ckb
Package Ecosystem crates.io
Published Date
Last Updated

How to Fix GHSA-v666-6w97-pcwm

To remediate this vulnerability, upgrade all affected Ckb dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

ckb fixed: 0.40.0
Upgrade ckb to 0.40.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for ckb

How to Check if You Are Affected

To determine whether your application is affected by GHSA-v666-6w97-pcwm, inspect your project dependencies for Ckb:

inspect dependencies for ckb

Analyze the terminal output to locate any version of Ckb in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.40.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition, where the product checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check. In Ckb, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact The RPC `get_block_template` fails when a cell has been used as a cell dep and an input in the different transactions. Say cell C is used as a dep group in the transaction A, and is destroyed in the transaction B. The node adds transaction A first, then B into the transaction pool. They are both valid. But when generating the block template, if the fee rate of B is higher, it comes before A, which will invalidate A. Currently the RPC `get_block_template` will fail instead of dropping A. ### Patch First, the `get_block_template` should not fail but dropping the conflict transactions. Then we can propose solution to this issue. Here is an example. When a transaction is added to the pool, the pool must consider it depending on all the transactions which dep cell (direct or indirect via dep group) has been destroyed in this transaction. Because future transactions using the destroyed cells as dep will be rejected, the spending transaction only need to wait for all the existing dep transactions on chain. ### Workaround 1. Submit transaction B when A is already on chain. 2. Let B depend on A explicitly, there are several solutions: * a. Add any output cell on A as a dep cell or input in B. * b. Merge A and B. CKB allows using the same cell as both dep and input in the same transaction. 3. Ensure the fee rate of B is less than A so A always has higher priority.

GHSA-v666-6w97-pcwm Affected Ckb Versions

1 component(s)
Fixed Versions:
0.40.0
Product / Package Ecosystem Affected Versions Fixed Version
ckb
crates.io
< 0.40.0
0.40.0

References

Frequently Asked Questions

What is GHSA-v666-6w97-pcwm?
GHSA-v666-6w97-pcwm is a security vulnerability in Ckb involving Miner fails to get block template when a cell used as a cell dep has been destroyed. under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition.
Which Ckb versions are affected?
Affected versions include releases prior to 0.40.0 across affected packages: ckb.
What version fixes GHSA-v666-6w97-pcwm?
Upgrading to 0.40.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is ckb affected?
Yes, ckb is affected in releases prior to 0.40.0. Upgrade your dependency to 0.40.0 or later.
What CWE is associated with GHSA-v666-6w97-pcwm?
GHSA-v666-6w97-pcwm is classified under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition (The product checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check.).
How can I check crates.io dependencies for GHSA-v666-6w97-pcwm?
Run the dependency tree command: 'inspect dependencies for ckb'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-v666-6w97-pcwm",
  "modified" : "2021-08-02T21:55:20Z",
  "published" : "2021-08-25T21:01:21Z",
  "aliases" : [ ],
  "summary" : "Miner fails to get block template when a cell used as a cell dep has been destroyed.",
  "details" : "### Impact\n\nThe RPC `get_block_template` fails when a cell has been used as a cell dep and an input in the different transactions.\n\nSay cell C is used as a dep group in the transaction A, and is destroyed in the transaction B.\n\nThe node adds transaction A first, then B into the transaction pool. They are both valid. But when generating the block template, if the fee rate of B is higher, it comes before A, which will invalidate A. Currently the RPC `get_block_template` will fail instead of dropping A.\n\n### Patch\n\nFirst, the `get_block_template` should not fail but dropping the conflict transactions.\n\nThen we can propose solution to this issue. Here is an example. When a transaction is added to the pool, the pool must consider it depending on all the transactions which dep cell (direct or indirect via dep group) has been destroyed in this transaction. Because future transactions using the destroyed cells as dep will be rejected, the spending transaction only need to wait for all the existing dep transactions on chain.\n\n### Workaround\n\n1. Submit transaction B when A is already on chain.\n2. Let B depend on A explicitly, there are several solutions:\n    * a. Add any output cell on A as a dep cell or input in B.\n    * b. Merge A and B. CKB allows using the same cell as both dep and input in the same transaction.\n3. Ensure the fee rate of B is less than A so A always has higher priority.\n",
  "severity" : [ ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "ckb"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.40.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/nervosnetwork/ckb/security/advisories/GHSA-v666-6w97-pcwm"
  }, {
    "type" : "WEB",
    "url" : "https://rustsec.org/advisories/RUSTSEC-2021-0107.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-367" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-08-02T21:55:20Z",
    "nvd_published_at" : null
  }
}