diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-11-22 18:12:06 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-11-22 18:12:06 +0900 |
| commit | f7c725ea5722959145db51847214897bad8e8b01 (patch) | |
| tree | c08cbe634d2e8ee025309bb6b1ae082265b8e03c | |
| parent | ee51069e4756492f445069e39cc13715c6b19f0d (diff) | |
container/seccomp: use sha384 for validation
This also replaces hex encoding with base64 for more manageable string
representations, and removes targets with build-only support.
Signed-off-by: Ophestra <cat@gensokyo.uk>
| -rw-r--r-- | container/seccomp/libseccomp_test.go | 21 | ||||
| -rw-r--r-- | container/seccomp/presets_386_test.go | 27 | ||||
| -rw-r--r-- | container/seccomp/presets_amd64_test.go | 28 | ||||
| -rw-r--r-- | container/seccomp/presets_arm64_test.go | 28 | ||||
| -rw-r--r-- | container/seccomp/presets_riscv64_test.go | 27 | ||||
| -rw-r--r-- | container/seccomp/presets_test.go | 24 |
6 files changed, 57 insertions, 98 deletions
diff --git a/container/seccomp/libseccomp_test.go b/container/seccomp/libseccomp_test.go index f46c36db..3e7de27c 100644 --- a/container/seccomp/libseccomp_test.go +++ b/container/seccomp/libseccomp_test.go @@ -2,6 +2,7 @@ package seccomp_test import ( "crypto/sha512" + "encoding/base64" "errors" "syscall" "testing" @@ -98,11 +99,21 @@ func TestExport(t *testing.T) { t.Parallel() want := bpfExpected[bpfPreset{tc.flags, tc.presets}] - if data, err := Export(Preset(tc.presets, tc.flags), tc.flags); (err != nil) != tc.wantErr { - t.Errorf("Export: error = %v, wantErr %v", err, tc.wantErr) + if data, err := Export( + Preset(tc.presets, tc.flags), + tc.flags, + ); (err != nil) != tc.wantErr { + t.Errorf( + "Export: error = %v, wantErr %v", + err, tc.wantErr, + ) return - } else if got := sha512.Sum512(data); got != want { - t.Fatalf("Export: hash = %x, want %x", got, want) + } else if got := sha512.Sum384(data); got != want { + t.Fatalf( + "Export: hash = %s, want %s", + base64.StdEncoding.EncodeToString(got[:]), + base64.StdEncoding.EncodeToString(want[:]), + ) return } }) @@ -121,7 +132,7 @@ func BenchmarkExport(b *testing.B) { if err != nil { b.Fatalf("Export: error = %v", err) } - if got := sha512.Sum512(data); got != want { + if got := sha512.Sum384(data); got != want { b.Fatalf("Export: hash = %x, want %x", got, want) return } diff --git a/container/seccomp/presets_386_test.go b/container/seccomp/presets_386_test.go deleted file mode 100644 index 890d4550..00000000 --- a/container/seccomp/presets_386_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package seccomp_test - -import ( - . "hakurei.app/container/seccomp" - . "hakurei.app/container/std" -) - -var bpfExpected = bpfLookup{ - {AllowMultiarch | AllowCAN | - AllowBluetooth, PresetExt | - PresetDenyNS | PresetDenyTTY | PresetDenyDevel | - PresetLinux32}: toHash( - "e67735d24caba42b6801e829ea4393727a36c5e37b8a51e5648e7886047e8454484ff06872aaef810799c29cbd0c1b361f423ad0ef518e33f68436372cc90eb1"), - - {0, 0}: toHash( - "5dbcc08a4a1ccd8c12dd0cf6d9817ea6d4f40246e1db7a60e71a50111c4897d69f6fb6d710382d70c18910c2e4fa2d2aeb2daed835dd2fabe3f71def628ade59"), - {0, PresetExt}: toHash( - "d6c0f130dbb5c793d1c10f730455701875778138bd2d03ca009d674842fd97a10815a8c539b76b7801a73de19463938701216b756c053ec91cfe304cba04a0ed"), - {0, PresetStrict}: toHash( - "af7d7b66f2e83f9a850472170c1b83d1371426faa9d0dee4e85b179d3ec75ca92828cb8529eb3012b559497494b2eab4d4b140605e3a26c70dfdbe5efe33c105"), - {0, PresetDenyNS | PresetDenyTTY | PresetDenyDevel}: toHash( - "adfb4397e6eeae8c477d315d58204aae854d60071687b8df4c758e297780e02deee1af48328cef80e16e4d6ab1a66ef13e42247c3475cf447923f15cbc17a6a6"), - {0, PresetExt | PresetDenyDevel}: toHash( - "5d641321460cf54a7036a40a08e845082e1f6d65b9dee75db85ef179f2732f321b16aee2258b74273b04e0d24562e8b1e727930a7e787f41eb5c8aaa0bc22793"), - {0, PresetExt | PresetDenyNS | PresetDenyDevel}: toHash( - "b1f802d39de5897b1e4cb0e82a199f53df0a803ea88e2fd19491fb8c90387c9e2eaa7e323f565fecaa0202a579eb050531f22e6748e04cfd935b8faac35983ec"), -} diff --git a/container/seccomp/presets_amd64_test.go b/container/seccomp/presets_amd64_test.go index c021772c..ba525e7f 100644 --- a/container/seccomp/presets_amd64_test.go +++ b/container/seccomp/presets_amd64_test.go @@ -9,19 +9,19 @@ var bpfExpected = bpfLookup{ {AllowMultiarch | AllowCAN | AllowBluetooth, PresetExt | PresetDenyNS | PresetDenyTTY | PresetDenyDevel | - PresetLinux32}: toHash( - "e99dd345e195413473d3cbee07b4ed57b908bfa89ea2072fe93482847f50b5b758da17e74ca2bbc00813de49a2b9bf834c024ed48850be69b68a9a4c5f53a9db"), + PresetLinux32}: mustParse( + "OEo0cEGplptK4cjDEehCaXJRRde5bNSy+f85FZ7ix8JBlWg/Vz/tW/krcUTIvkgS"), - {0, 0}: toHash( - "95ec69d017733e072160e0da80fdebecdf27ae8166f5e2a731270c98ea2d2946cb5231029063668af215879155da21aca79b070e04c0ee9acdf58f55cfa815a5"), - {0, PresetExt}: toHash( - "dc7f2e1c5e829b79ebb7efc759150f54a83a75c8df6fee4dce5dadc4736c585d4deebfeb3c7969af3a077e90b77bb4741db05d90997c8659b95891206ac9952d"), - {0, PresetStrict}: toHash( - "e880298df2bd6751d0040fc21bc0ed4c00f95dc0d7ba506c244d8b8cf6866dba8ef4a33296f287b66cccc1d78e97026597f84cc7dec1573e148960fbd35cd735"), - {0, PresetDenyNS | PresetDenyTTY | PresetDenyDevel}: toHash( - "39871b93ffafc8b979fcedc0b0c37b9e03922f5b02748dc5c3c17c92527f6e022ede1f48bff59246ea452c0d1de54827808b1a6f84f32bbde1aa02ae30eedcfa"), - {0, PresetExt | PresetDenyDevel}: toHash( - "c698b081ff957afe17a6d94374537d37f2a63f6f9dd75da7546542407a9e32476ebda3312ba7785d7f618542bcfaf27ca27dcc2dddba852069d28bcfe8cad39a"), - {0, PresetExt | PresetDenyNS | PresetDenyDevel}: toHash( - "0b76007476c1c9e25dbf674c29fdf609a1656a70063e49327654e1b5360ad3da06e1a3e32bf80e961c5516ad83d4b9e7e9bde876a93797e27627d2555c25858b"), + {0, 0}: mustParse( + "sAvw2CtI7W4wSYJO6W3Ze/cR7n8SPosH2V5M7KaUAwx/I/Xt6kQfZ47mdhfpsU7X"), + {0, PresetExt}: mustParse( + "MX+zm1iU5vjinYMESQP/nSwPZAKkg8Be1NB/78ymBWIJQL7YLHXok0wZGYCN0PGV"), + {0, PresetStrict}: mustParse( + "isd2gO0e6x0op65JOPQef7PBkQkZsk+yVDMXc6RZicws6kJly86k6D7Oc0et2UAQ"), + {0, PresetDenyNS | PresetDenyTTY | PresetDenyDevel}: mustParse( + "rE7j00R4QKuYvFFJIlC0j7t/vepQD+pTFCwWjSpuPLytscUBBYCfhEdeAZuhtMNY"), + {0, PresetExt | PresetDenyDevel}: mustParse( + "G0YXlspH4dCZ7g6xt0xUSDEtovwQniGJAogR1mfPS3/Ku0bVon4Oh5plFbMMDPXh"), + {0, PresetExt | PresetDenyNS | PresetDenyDevel}: mustParse( + "Y/IbE5y2PSjiP2GS7JDnNIr+sRDdAEaRhyxkrfd5SLZCaJW3j8pu/eqtNIC9ZGAi"), } diff --git a/container/seccomp/presets_arm64_test.go b/container/seccomp/presets_arm64_test.go index a445d3b7..468591ec 100644 --- a/container/seccomp/presets_arm64_test.go +++ b/container/seccomp/presets_arm64_test.go @@ -9,19 +9,19 @@ var bpfExpected = bpfLookup{ {AllowMultiarch | AllowCAN | AllowBluetooth, PresetExt | PresetDenyNS | PresetDenyTTY | PresetDenyDevel | - PresetLinux32}: toHash( - "1431c013f2ddac3adae577821cb5d351b1514e7c754d62346ddffd31f46ea02fb368e46e3f8104f81019617e721fe687ddd83f1e79580622ccc991da12622170"), + PresetLinux32}: mustParse( + "twXUaARtogDCbL1KBbedm/kHg6sJXznJL0sUqRikKLm2GUtQzSfRhjGdJT0A7qvf"), - {0, 0}: toHash( - "450c21210dbf124dfa7ae56d0130f9c2e24b26f5bce8795ee75766c75850438ff9e7d91c5e73d63bbe51a5d4b06c2a0791c4de2903b2b9805f16265318183235"), - {0, PresetExt}: toHash( - "d971d0f2d30f54ac920fc6d84df2be279e9fd28cf2d48be775d7fdbd790b750e1369401cd3bb8bcf9ba3adb91874fe9792d9e3f62209b8ee59c9fdd2ddd10c7b"), - {0, PresetStrict}: toHash( - "79318538a3dc851314b6bd96f10d5861acb2aa7e13cb8de0619d0f6a76709d67f01ef3fd67e195862b02f9711e5b769bc4d1eb4fc0dfc41a723c89c968a93297"), - {0, PresetDenyNS | PresetDenyTTY | PresetDenyDevel}: toHash( - "228286c2f5df8e44463be0a57b91977b7f38b63b09e5d98dfabe5c61545b8f9ac3e5ea3d86df55d7edf2ce61875f0a5a85c0ab82800bef178c42533e8bdc9a6c"), - {0, PresetExt | PresetDenyDevel}: toHash( - "433ce9b911282d6dcc8029319fb79b816b60d5a795ec8fc94344dd027614d68f023166a91bb881faaeeedd26e3d89474e141e5a69a97e93b8984ca8f14999980"), - {0, PresetExt | PresetDenyNS | PresetDenyDevel}: toHash( - "cf1f4dc87436ba8ec95d268b663a6397bb0b4a5ac64d8557e6cc529d8b0f6f65dad3a92b62ed29d85eee9c6dde1267757a4d0f86032e8a45ca1bceadfa34cf5e"), + {0, 0}: mustParse( + "E5bX9LpbIOyhramrRow7KUdI88mfJyl5l6fel/ExG225OCKbmHAEUkCjl4Fq5Pb8"), + {0, PresetExt}: mustParse( + "tCfjE21krvCxqqcCZBbu7TxeN0B2HMij5bFP/izDwh8eUHDm0OYFmUjvsBGRxmhS"), + {0, PresetStrict}: mustParse( + "WMS9H9ShztPm7B/O0n+zHQ8QOjHcmVtnRx9PiGzcsrDEtNcrdjMVqfqS1GR+dMmL"), + {0, PresetDenyNS | PresetDenyTTY | PresetDenyDevel}: mustParse( + "9qFCO42xnesgW9sgPfDSrViBL8z9AQoQNKiqdmkWE2W/9xL/eHzjkLxfhevrE8Ip"), + {0, PresetExt | PresetDenyDevel}: mustParse( + "SxAtjuCiDU9kB8Ju2qIcZZHy5VFBd71aqd5migWqh4y+o0UxqY3Zb04pdTvbOQ71"), + {0, PresetExt | PresetDenyNS | PresetDenyDevel}: mustParse( + "RkzpxZqXcMudAKfn/IcGLG6U8G6jcsC6Jn6UxUbnDj0CRcexKy7ZeZyGQcSsvULU"), } diff --git a/container/seccomp/presets_riscv64_test.go b/container/seccomp/presets_riscv64_test.go deleted file mode 100644 index f59469b0..00000000 --- a/container/seccomp/presets_riscv64_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package seccomp_test - -import ( - . "hakurei.app/container/seccomp" - . "hakurei.app/container/std" -) - -var bpfExpected = bpfLookup{ - {AllowMultiarch | AllowCAN | - AllowBluetooth, PresetExt | - PresetDenyNS | PresetDenyTTY | PresetDenyDevel | - PresetLinux32}: toHash( - "a1c4ffa35f4bfbf38061184760b9a09edfcb4964c3b534395e47327b83f3fb61f2f9573ddfcc4772424cc2f5dd12fd32471e6531dbe10e85eda3797dd4fa179f"), - - {0, 0}: toHash( - "f3910fd727d087def593e3876c2c6ab9ace71d82ec8cbc992a26223e7bba85e1d7a0b56c5fc6303703f24595825dad8561637edaedd5384b34a6cd080946633c"), - {0, PresetExt}: toHash( - "741438c5e3f11c36c92ae8c5934f13440675c6e719541c2dbffeda79a10081bcfd9ad8314a60c1d1f53db86c8080c13fffa3bbcf7fe753935679b4b902737286"), - {0, PresetStrict}: toHash( - "79e9e464d02405c6d74fd2c771bd72a1311e488221c73a9c32db9270219837c54fccec2f36fe2474895547e60c311514567e2e6cf4e7a7fcf909c1ecd1e254a7"), - {0, PresetDenyNS | PresetDenyTTY | PresetDenyDevel}: toHash( - "3c443715a6c1e557a284862ea8efb70a5d4ecbe67d1226627323e861cd3646fb3e7768ec5b94b93760b7f652cf6916f66e317a4fbf8716d10c3673aa4fc3ae58"), - {0, PresetExt | PresetDenyDevel}: toHash( - "4448a74e8cc75a4ab63799c4f2cc2a5af63e5f4e8e9b8ac15a1873d647dfa67a4c67b39ed466d8dd32abc64136d401879fc6185c9ab00feeaf59ccf4305f8201"), - {0, PresetExt | PresetDenyNS | PresetDenyDevel}: toHash( - "c7c86e793cb7192f5f6c735f372cda27eb43ae1045e587f8eadb64c849520a3280b6570a3d7b601d32cddb38021585a2234db38e506cebfd10aa3d6c75440f17"), -} diff --git a/container/seccomp/presets_test.go b/container/seccomp/presets_test.go index b86d49ba..d24ca97f 100644 --- a/container/seccomp/presets_test.go +++ b/container/seccomp/presets_test.go @@ -2,29 +2,31 @@ package seccomp_test import ( "crypto/sha512" - "encoding/hex" + "encoding/base64" + "fmt" "hakurei.app/container/seccomp" "hakurei.app/container/std" ) type ( + // bpfPreset represents a preset to validate. bpfPreset = struct { seccomp.ExportFlag std.FilterPreset } - bpfLookup map[bpfPreset][sha512.Size]byte + + // bpfLookup are bpf presets and their corresponding filter checksum. + bpfLookup = map[bpfPreset][sha512.Size384]byte ) -func toHash(s string) [sha512.Size]byte { - if len(s) != sha512.Size*2 { - panic("bad sha512 string length") - } - if v, err := hex.DecodeString(s); err != nil { - panic(err.Error()) - } else if len(v) != sha512.Size { - panic("unreachable") +// mustParse parses [base64.StdEncoding] representations of a sha512 checksum. +func mustParse(s string) [sha512.Size384]byte { + if v, err := base64.StdEncoding.DecodeString(s); err != nil { + panic(err) + } else if len(v) != sha512.Size384 { + panic(fmt.Sprintf("bad checksum of %d bytes", len(v))) } else { - return ([sha512.Size]byte)(v) + return ([sha512.Size384]byte)(v) } } |
