Skip to content

Commit

Permalink
Merge pull request #271 from slimm609/read_kernel_boot
Browse files Browse the repository at this point in the history
read kernel config from /boot
  • Loading branch information
slimm609 authored Dec 19, 2024
2 parents ff76bcf + 5f73d2e commit 4a73404
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 4a73404

Please sign in to comment.