Skip to content

Commit

Permalink
read kernel config from /boot
Browse files Browse the repository at this point in the history
read the kernel config from /boot if it exists and /proc/config.gz is not found
  • Loading branch information
slimm609 committed Dec 18, 2024
1 parent ff76bcf commit 5f73d2e
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions cmd/kernel.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package cmd

import (
"github.com/slimm609/checksec/pkg/utils"
"fmt"
"os"
"strings"

"github.com/slimm609/checksec/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -14,8 +17,27 @@ var kernelCmd = &cobra.Command{
var configFile string
if len(args) > 0 {
configFile = args[0]
} else {
} else if _, err := os.Stat("/proc/config.gz"); err == nil {
configFile = "/proc/config.gz"
} else {
osReleaseFile := "/proc/sys/kernel/osrelease"
_, err := os.Stat(osReleaseFile)
if err != nil {
fmt.Println("Error: could not find kernel config")
os.Exit(1)
}
osReleaseVersion, err := os.ReadFile(osReleaseFile)
if err != nil {
fmt.Println("Error: could not find kernel config")
os.Exit(1)
}
content := strings.ReplaceAll(string(osReleaseVersion), "\n", "")
configFile = fmt.Sprintf("%s-%s", "/boot/config", content)
_, err = os.Stat(configFile)
if err != nil {
fmt.Println("Error: could not find kernel config")
os.Exit(1)
}
}

utils.CheckFileExists(configFile)
Expand Down

0 comments on commit 5f73d2e

Please sign in to comment.