GHSA-3PP4-64MP-9CG9

Vulnerability from github – Published: 2022-06-17 00:27 – Updated: 2022-06-17 00:27
VLAI?
Summary
Memory Safety Issue when using `patch` or `merge` on `state` and assign the result back to `state`
Details

Affected versions of this crate maintains references to memory that might have been freed already. If affects the following two tremor-script language constructs:

  • A Merge where we assign the result back to the target expression and the expression to be merged needs to reference the event:
let state = merge state of event end;
  • A Patch where we assign the result back to the target expression and the patch operations used need to reference the event:
let state = patch state of insert event.key => event.value end;

For constructs like this (it doesnt matter what is references in the expression to be merged or the patch operations) an optimization was applied to manipulate the target value in-place, instead of cloning it.

Our Value struct which underpins all event data in tremor-script, is representing as borrowed strings beef::Cow<'lifetime, str> that reference the actual Vec<u8> the event is based upon. We keep the raw byte-array next to the event structure inside our Event struct as a self-referential struct, so we make sure that the structured Value and its references are valid across its whole lifetime.

The optimization was considered safe as long as it was only possible to merge or patche event data or static data. When state was introduced to tremor-script a new possibility existed, to keep Value data around for longer than the lifetime of an event. If event data is merged or patched into state without cloning state first, it can still reference keys or values from the previous event, which will now be invalid. This allows access to those already freed regions of memory and to get their content out over the wire.

Workaround

If an upgrade is not possible, a possible workaround is to avoid the optimization by introducing a temporary variable and not immediately reassigning to state:

let tmp = merge state of event end;
let state = tmp

Fix

The flaw was corrected in tremor-script version 0.11.6 via commit 1a2efcd by removing the optimization and always clone the target expression of a Merge or [Patch](https://www.tremor.rs/docs/tremor-script/index#patch.

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "crates.io",
        "name": "tremor-script"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0.7.2"
            },
            {
              "fixed": "0.11.6"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [],
  "database_specific": {
    "cwe_ids": [],
    "github_reviewed": true,
    "github_reviewed_at": "2022-06-17T00:27:30Z",
    "nvd_published_at": null,
    "severity": "HIGH"
  },
  "details": "Affected versions of this crate maintains references to memory that might have been freed already.\nIf affects the following two `tremor-script` language constructs:\n\n* A [Merge](https://www.tremor.rs/docs/tremor-script/index#merge) where we assign the result back to the target expression\n  and the expression to be merged needs to reference the `event`:\n\n```\nlet state = merge state of event end;\n```\n\n* A [Patch](https://www.tremor.rs/docs/tremor-script/index#patch) where we assign the result back to the target expression\n  and the patch operations used need to reference the `event`:\n\n```\nlet state = patch state of insert event.key =\u003e event.value end;\n```\n\nFor constructs like this (it doesnt matter what is references in the expression to be merged or the patch operations) an optimization\nwas applied to manipulate the target value in-place, instead of cloning it.\n\nOur `Value` struct which underpins all event data in `tremor-script`, is representing as borrowed strings `beef::Cow\u003c\u0027lifetime, str\u003e` \nthat reference the actual `Vec\u003cu8\u003e` the event is based upon. We keep the raw byte-array next to the event structure inside our `Event` struct as a self-referential struct,\nso we make sure that the structured `Value` and its references are valid across its whole lifetime.\n\nThe optimization was considered safe as long as it was only possible to merge or patche `event` data or static data.\nWhen `state` was introduced to `tremor-script` a new possibility existed, to keep `Value` data around for longer than the lifetime of an event.\nIf `event` data is merged or patched into `state` without cloning `state` first, it can still reference keys or values from\nthe previous event, which will now be invalid. This allows access to those already freed regions of memory and to get their content out over the wire.\n\n\n## Workaround\n\nIf an upgrade is not possible, a possible workaround is to avoid the optimization\nby introducing a temporary variable and not immediately reassigning to `state`:\n\n```\nlet tmp = merge state of event end;\nlet state = tmp\n```\n\n## Fix\n\nThe flaw was corrected in `tremor-script` version 0.11.6 via commit [1a2efcd](https://github.com/tremor-rs/tremor-runtime/commit/1a2efcdbe68e5e7fd0a05836ac32d2cde78a0b2e) by removing the optimization\nand always clone the target expression of a [Merge](https://www.tremor.rs/docs/tremor-script/index#merge) or [Patch](https://www.tremor.rs/docs/tremor-script/index#patch.\n\n",
  "id": "GHSA-3pp4-64mp-9cg9",
  "modified": "2022-06-17T00:27:30Z",
  "published": "2022-06-17T00:27:30Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/tremor-rs/tremor-runtime/pull/1217"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/tremor-rs/tremor-runtime"
    },
    {
      "type": "WEB",
      "url": "https://rustsec.org/advisories/RUSTSEC-2021-0111.html"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [],
  "summary": "Memory Safety Issue when using `patch` or `merge` on `state` and assign the result back to `state`"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Sightings

Author Source Type Date

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.


Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…