2023-03-18 21:30:07 +00:00
|
|
|
// Copyright 2023 Mikhail Klementev. All rights reserved.
|
2019-08-18 17:49:11 +00:00
|
|
|
// Use of this source code is governed by a AGPLv3 license
|
|
|
|
// (or later) that can be found in the LICENSE file.
|
|
|
|
|
2024-02-17 22:38:43 +00:00
|
|
|
package cmd
|
2019-08-18 17:49:11 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-02-20 12:38:36 +00:00
|
|
|
"os"
|
2019-08-18 17:49:11 +00:00
|
|
|
"time"
|
2023-03-18 21:30:07 +00:00
|
|
|
|
2023-05-13 09:17:57 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/fs"
|
|
|
|
|
2023-03-18 21:30:07 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2019-08-18 17:49:11 +00:00
|
|
|
)
|
|
|
|
|
2023-01-31 07:13:33 +00:00
|
|
|
type PackCmd struct {
|
|
|
|
Autogen bool `help:"kernel autogeneration"`
|
2023-01-31 09:05:43 +00:00
|
|
|
UseHost bool `help:"also use host kernels"`
|
2023-01-31 07:13:33 +00:00
|
|
|
NoDownload bool `help:"do not download qemu image while kernel generation"`
|
|
|
|
ExploitRuns int64 `default:"4" help:"amount of runs of each exploit"`
|
|
|
|
KernelRuns int64 `default:"1" help:"amount of runs of each kernel"`
|
2023-05-21 21:43:18 +00:00
|
|
|
Max int `help:"download random kernels from set defined by regex in release_mask, but no more than X for each of release_mask" default:"1"`
|
2023-01-31 09:05:43 +00:00
|
|
|
|
|
|
|
Threads int `help:"threads" default:"4"`
|
2023-01-31 07:13:33 +00:00
|
|
|
|
|
|
|
Tag string `help:"filter tag"`
|
|
|
|
|
2023-01-31 09:05:43 +00:00
|
|
|
Timeout time.Duration `help:"timeout after tool will not spawn new tests"`
|
|
|
|
QemuTimeout time.Duration `help:"timeout for qemu"`
|
|
|
|
DockerTimeout time.Duration `help:"timeout for docker"`
|
2023-01-31 07:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *PackCmd) Run(g *Globals) (err error) {
|
2019-08-18 17:49:11 +00:00
|
|
|
tag := fmt.Sprintf("pack_run_%d", time.Now().Unix())
|
2024-05-23 10:19:46 +00:00
|
|
|
log.Info().Msgf("Tag: %s", tag)
|
2019-08-18 17:49:11 +00:00
|
|
|
|
2024-02-20 12:38:36 +00:00
|
|
|
files, err := os.ReadDir(g.WorkDir)
|
2019-08-18 17:49:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range files {
|
2023-01-31 07:13:33 +00:00
|
|
|
workPath := g.WorkDir + "/" + f.Name()
|
2019-08-18 17:49:11 +00:00
|
|
|
|
2023-05-13 09:17:57 +00:00
|
|
|
if !fs.PathExists(workPath + "/.out-of-tree.toml") {
|
2019-08-18 17:49:11 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-01-31 07:13:33 +00:00
|
|
|
if cmd.Autogen {
|
2023-06-01 14:07:53 +00:00
|
|
|
autogen := KernelAutogenCmd{}
|
|
|
|
err = autogen.Run(
|
2023-01-31 09:05:43 +00:00
|
|
|
&KernelCmd{
|
|
|
|
NoDownload: cmd.NoDownload,
|
|
|
|
UseHost: cmd.UseHost,
|
2023-05-26 15:33:54 +00:00
|
|
|
Max: cmd.Max,
|
2023-01-31 09:05:43 +00:00
|
|
|
},
|
|
|
|
&Globals{
|
|
|
|
Config: g.Config,
|
|
|
|
WorkDir: workPath,
|
|
|
|
},
|
|
|
|
)
|
2019-08-18 17:49:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-23 10:19:46 +00:00
|
|
|
log.Info().Msg(f.Name())
|
2019-08-18 17:49:11 +00:00
|
|
|
|
2023-04-05 11:29:31 +00:00
|
|
|
pew := PewCmd{
|
2023-01-31 09:05:43 +00:00
|
|
|
Max: cmd.KernelRuns,
|
|
|
|
Runs: cmd.ExploitRuns,
|
|
|
|
Threads: cmd.Threads,
|
|
|
|
Tag: tag,
|
|
|
|
Timeout: cmd.Timeout,
|
|
|
|
QemuTimeout: cmd.QemuTimeout,
|
|
|
|
DockerTimeout: cmd.DockerTimeout,
|
|
|
|
Dist: pathDevNull,
|
2023-04-05 11:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pew.Run(&Globals{
|
2023-01-31 09:05:43 +00:00
|
|
|
Config: g.Config,
|
|
|
|
WorkDir: workPath,
|
|
|
|
})
|
2019-08-18 17:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|