Skip to content

kernel_version can cause a data race when called from multiple threads #2028

Closed
@LegionMammal978

Description

@LegionMammal978

In src/features.rs, kernel_version() is defined as:

    fn kernel_version() -> Result<usize> {
        static mut KERNEL_VERS: usize = 0;

        unsafe {
            if KERNEL_VERS == 0 {
                KERNEL_VERS = parse_kernel_version()?;
            }

            Ok(KERNEL_VERS)
        }
    }

If two threads call this function simultaneously when KERNEL_VERS is still 0, then it will result in a data race. A trivial fix is to replace it with an AtomicUsize accessed with Relaxed, since the worst case is that a thread performs a redundant uname() call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions