Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FP UseAfterFree Warning #69

Open
stoneman258 opened this issue Sep 24, 2024 · 1 comment
Open

FP UseAfterFree Warning #69

stoneman258 opened this issue Sep 24, 2024 · 1 comment

Comments

@stoneman258
Copy link

Description

I encountered a false positive while using Lockbud to analyze the ntpd package. Lockbud flagged a use-after-free in the tokio crate. However, upon closer inspection, it seems this might be an incorrect detection.

Code snippets

https://github.com/tokio-rs/tokio/blob/48c55768fd6ae47d1c015b154a0ebd2579688359/tokio/src/util/slab.rs#L311-L323

            debug_assert!(
                self.cached[idx].slots.is_null() || self.cached[idx].slots == vec.as_ptr(),    //line311
                "cached = {:?}; actual = {:?}",
                self.cached[idx].slots,
                vec.as_ptr(),
            );


            // Clear cache
            self.cached[idx].slots = ptr::null();
            self.cached[idx].init = 0;

            drop(vec);    //line323
        }

Result

      {
        "UseAfterFree": {
          "bug_kind": "UseAfterFree",
          "possibility": "Possibly",
          "diagnosis": "Raw ptr is used at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.29.0/src/util/slab.rs:315:17: 315:29 (#1653) after dropped at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.29.0/src/util/slab.rs:322:13: 322:22 (#0)",
          "explanation": "Raw ptr is used or escapes the current function after the pointed value is dropped"
        }
      },

Lockbud report a wrong UseAfterFree warning. The vec is never used after drop in line 323.

Reproduction

git clone https://github.com/pendulum-project/ntpd-rs.git
git checkout v0.3.6
cargo lockbud -k all -l tokio 
@BurtonQin
Copy link
Owner

BurtonQin commented Sep 26, 2024

Nice catch! This is due to the imprecise pointer analysis. I am working to migrate to a new more precise point er analysis based on RUPTA. Current work around is to blacklist Tokio and only detect the project repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants