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

rustreapi: lsp_pool is set from an unterminated Rust String

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • None
    • None
    • None
    • 3
    • 9223372036854775807

      rustreapi passes an unterminated Rust string to liblustreapi as the pool name.

      OpenOptions::get_stripe_param() (rustreapi/rustreapi/src/lib.rs:229) fills
      llapi_stripe_param.lsp_pool from the bytes of a Rust String:

      let pool = if let Some(pool) = self.pool.as_ref()

      { pool.as_bytes().as_ptr() as *mut c_char }

      else

      { ptr::null_mut::<c_char>() }

      ;
      ...
      addr_of_mut!((*param).lsp_pool).write(pool);

      `pool` is Option<String> (line 97). A Rust String stores exactly its bytes with
      no trailing NUL, but liblustreapi treats lsp_pool as a C string:

      • liblustreapi.c:478 const char *pool_name = param->lsp_pool;
        then lov_pool_is_ignored(pool_name)
      • llapi_stripe_param_verify(), which strlen()s it against LOV_MAXPOOLNAME
      • liblustreapi.c:881 snprintf(lmu->lum_pool_name, sizeof(...), "%s",
        param->lsp_pool)

      Each of those reads past the end of the String's heap allocation until it
      happens to find a zero byte. Depending on what follows in memory the effects
      are: garbage appended to the pool name so a valid pool fails with EINVAL or
      ENOENT, a length that trips the LOV_MAXPOOLNAME check, or a heap over-read
      fault when no zero byte precedes the end of the mapping.

      Reproducer:

      OpenOptions::new().pool(Some("mypool".to_string())).open(path)

      Note this is not a dangling pointer: self.pool is owned by the OpenOptions,
      which outlives the llapi_* call, so the memory is valid. Only the terminator
      is missing. That shapes the fix – a CString built inside get_stripe_param()
      would be dropped at return and would dangle, because open() calls
      assume_init() and then passes &param to llapi_file_open_param() after
      get_stripe_param() has returned. The terminator has to be owned by something
      that outlives the call; storing pool as a CString rather than a String is the
      straightforward option, since self already has the right lifetime.

      The same class of bug in OpenOptions::volatile(), which passed
      dir.as_os_str().as_encoded_bytes().as_ptr() as the directory argument, is
      fixed in https://review.whamcloud.com/c/fs/lustre-release/+/58514 (LU-18842).

            wc-triage WC Triage
            rread Robert Read
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: