Skip to content

bug: kernel version comparison in setup.sh is lexicographic, not numeric #50

@jpleva91

Description

@jpleva91

Bug: String comparison for kernel version

File: scripts/setup.sh

The OpenShell prerequisite check compares the Linux kernel version as a string:

if [[ "$(uname -r | cut -d. -f1-2)" < "5.13" ]]; then
    warn "Kernel $(uname -r) — Landlock needs >= 5.13"
fi

Bash's [[ < ]] operator performs lexicographic (alphabetical) comparison, not numeric comparison. This means:

Kernel cut output String comparison result Correct?
5.4 5.4 "5.4" < "5.13" → false (4 > 1) ❌ should warn, doesn't
5.9 5.9 "5.9" < "5.13" → false (9 > 1) ❌ should warn, doesn't
5.13 5.13 "5.13" < "5.13" → false
6.0 6.0 "6.0" < "5.13" → false

Kernels 5.4–5.12 (which don't support Landlock) will not trigger the warning, potentially leading to a broken OpenShell install.

Fix

kernel_maj=$(uname -r | cut -d. -f1)
kernel_min=$(uname -r | cut -d. -f2)
if (( kernel_maj < 5 || (kernel_maj == 5 && kernel_min < 13) )); then
    warn "Kernel $(uname -r) — Landlock needs >= 5.13"
fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium prioritybugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions