Uploaded image for project: 'Lustre'
  1. Lustre
  2. LU-20479

lnetctl: use-after-free in cYAML_build_error()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Medium Medium
    • Lustre 2.18.0
    • None
    • None
    • 3
    • 9223372036854775807

      cYAML_build_error() locates the command node with cYAML_get_object_item(), which searches the tree recursively.

      The commands are direct children of the error root, but the entities below them are not. A recursive search can therefore return an entity that happens to share a name with the command being looked up. cYAML_build_error() then finds a node that is not a sequence, takes its failure path, frees the error tree, prints "fatal: out of memory", and leaves the caller's pointer dangling - the failure path assigns NULL to the local variable r rather than to *root. The caller goes on to build further errors into, and finally print, freed memory.

      This is reachable on master through the liblnetconfig YAML handlers, which lnetctl uses whenever the Netlink API is bypassed: "lnetctl import --old-api" (relied on by sanity-lnet test_170), and the fallbacks taken when the Netlink socket cannot be allocated or its parser cannot be initialized.

      Reproducer, verified on master (a plain "lnetctl import" goes through Netlink and is not affected):

      lnetctl lnet configure
      lnetctl net add --net tcp --if <iface> --conns-per-peer 8
      lnetctl export --backup > /tmp/net.yaml
      lnetctl lnet unconfigure && lnetctl lnet configure
      sed -i 's/conns_per_peer: 8/conns_per_peer: 200/' /tmp/net.yaml
      lnetctl import --old-api < /tmp/net.yaml

      error:
      fatal: out of memory
      Segmentation fault (core dumped)

      The out-of-range conns_per_peer is rejected by handle_yaml_config_ni(), which builds a "ni" command holding an "add" entity. The "global" section that follows in the imported config is configured with the "add" command (ioctl_set_value/ADD_CMD). The recursive lookup finds the "add" entity of the earlier "ni" error, mistakes it for the "add" command, and takes the failure path.

      That pair is not the only way in: "net", "peer" and "set" are each used as both a command and an entity name. Nor is the bug specific to the out-of-range conns_per_peer check that landed with LU-20398 - the "bad interface list" error in handle_yaml_config_ni() builds the same "ni"/"add" shape and predates it.

      Fix: look the command up among the direct children of the error root with cYAML_get_object_child(), and clear the caller's pointer when the tree is freed.

            hornc Chris Horn
            hornc Chris Horn
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: