| 1 |
|
| 2 |
|
| 3 |
package seccomp |
| 4 |
|
| 5 |
import ( |
| 6 |
"bytes" |
| 7 |
"errors" |
| 8 |
"fmt" |
| 9 |
"io" |
| •10 |
"math/bits" |
| 11 |
"os" |
| •12 |
"os/exec" |
| 13 |
"runtime" |
| 14 |
"strings" |
| 15 |
"syscall" |
| 16 |
"testing" |
| 17 |
"time" |
| 18 |
"unsafe" |
| 19 |
) |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
func execInSubprocess(t *testing.T, f func(t *testing.T)) { |
| 25 |
const subprocessEnvKey = `GO_SUBPROCESS_KEY` |
| 26 |
if testIDString, ok := os.LookupEnv(subprocessEnvKey); ok && testIDString == "1" { |
| 27 |
t.Run(`subprocess`, f) |
| 28 |
return |
| 29 |
} |
| 30 |
|
| 31 |
cmd := exec.Command(os.Args[0]) |
| 32 |
cmd.Args = []string{os.Args[0], "-test.run=" + t.Name() + "$", "-test.v=true"} |
| 33 |
for _, arg := range os.Args { |
| 34 |
if strings.HasPrefix(arg, `-test.testlogfile=`) { |
| 35 |
cmd.Args = append(cmd.Args, arg) |
| 36 |
} |
| 37 |
} |
| 38 |
cmd.Env = append(os.Environ(), |
| 39 |
subprocessEnvKey+"=1", |
| 40 |
) |
| 41 |
cmd.Stdin = os.Stdin |
| 42 |
|
| 43 |
out, err := cmd.CombinedOutput() |
| 44 |
t.Logf("%s", out) |
| 45 |
if err != nil { |
| 46 |
t.Fatal(err) |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
func TestExpectedSeccompVersion(t *testing.T) { |
| 51 |
execInSubprocess(t, subprocessExpectedSeccompVersion) |
| 52 |
} |
| 53 |
|
| 54 |
func subprocessExpectedSeccompVersion(t *testing.T) { |
| 55 |
|
| 56 |
const name = "_EXPECTED_LIBSECCOMP_VERSION" |
| 57 |
|
| 58 |
expVer := os.Getenv(name) |
| 59 |
if expVer == "" { |
| 60 |
t.Skip(name, "not set") |
| 61 |
} |
| 62 |
expVer = strings.TrimPrefix(expVer, "v") |
| 63 |
|
| 64 |
curVer := fmt.Sprintf("%d.%d.%d", verMajor, verMinor, verMicro) |
| 65 |
t.Logf("testing against libseccomp %s", curVer) |
| 66 |
if curVer != expVer { |
| 67 |
t.Fatalf("libseccomp version mismatch: must be %s, got %s", expVer, curVer) |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
func APILevelIsSupported() bool { |
| 74 |
return verMajor > 2 || |
| 75 |
(verMajor == 2 && verMinor >= 4) |
| 76 |
} |
| 77 |
|
| 78 |
func TestGetAPILevel(t *testing.T) { |
| 79 |
execInSubprocess(t, subprocessGetAPILevel) |
| 80 |
} |
| 81 |
|
| 82 |
func subprocessGetAPILevel(t *testing.T) { |
| 83 |
api, err := GetAPI() |
| 84 |
if !APILevelIsSupported() { |
| 85 |
if api != 0 { |
| 86 |
t.Errorf("API level returned despite lack of support: %v", api) |
| 87 |
} else if err == nil { |
| 88 |
t.Errorf("No error returned despite lack of API level support") |
| 89 |
} |
| 90 |
|
| 91 |
t.Skipf("Skipping test: %s", err) |
| 92 |
} else if err != nil { |
| 93 |
t.Errorf("Error getting API level: %s", err) |
| 94 |
} |
| 95 |
t.Logf("Got API level of %v\n", api) |
| 96 |
} |
| 97 |
|
| 98 |
func TestSetAPILevel(t *testing.T) { |
| 99 |
execInSubprocess(t, subprocessSetAPILevel) |
| 100 |
} |
| 101 |
|
| 102 |
func subprocessSetAPILevel(t *testing.T) { |
| 103 |
const expectedAPI = uint(1) |
| 104 |
|
| 105 |
err := SetAPI(expectedAPI) |
| 106 |
if !APILevelIsSupported() { |
| 107 |
if err == nil { |
| 108 |
t.Errorf("No error returned despite lack of API level support") |
| 109 |
} |
| 110 |
|
| 111 |
t.Skipf("Skipping test: %s", err) |
| 112 |
} else if err != nil { |
| 113 |
t.Errorf("Error setting API level: %s", err) |
| 114 |
} |
| 115 |
|
| 116 |
api, err := GetAPI() |
| 117 |
if err != nil { |
| 118 |
t.Errorf("Error getting API level: %s", err) |
| 119 |
} else if api != expectedAPI { |
| 120 |
t.Errorf("Got API level %v: expected %v", api, expectedAPI) |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
func TestActionSetReturnCode(t *testing.T) { |
| 125 |
if ActInvalid.SetReturnCode(0x0010) != ActInvalid { |
| 126 |
t.Errorf("Able to set a return code on invalid action!") |
| 127 |
} |
| 128 |
|
| 129 |
codeSet := ActErrno.SetReturnCode(0x0001) |
| 130 |
if codeSet == ActErrno || codeSet.GetReturnCode() != 0x0001 { |
| 131 |
t.Errorf("Could not set return code on ActErrno") |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
func TestSyscallGetName(t *testing.T) { |
| 136 |
call1 := ScmpSyscall(0x1) |
| 137 |
callFail := ScmpSyscall(0x999) |
| 138 |
|
| 139 |
name, err := call1.GetName() |
| 140 |
if err != nil { |
| 141 |
t.Errorf("Error getting syscall name for number 0x1") |
| 142 |
} else if len(name) == 0 { |
| 143 |
t.Errorf("Empty name returned for syscall 0x1") |
| 144 |
} |
| 145 |
t.Logf("Got name of syscall 0x1 on native arch as %s\n", name) |
| 146 |
|
| 147 |
_, err = callFail.GetName() |
| 148 |
if err == nil { |
| 149 |
t.Errorf("Getting nonexistent syscall should error!") |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
func TestSyscallGetNameByArch(t *testing.T) { |
| 154 |
call1 := ScmpSyscall(0x1) |
| 155 |
callInvalid := ScmpSyscall(0x999) |
| 156 |
archGood := ArchAMD64 |
| 157 |
archBad := ArchInvalid |
| 158 |
|
| 159 |
name, err := call1.GetNameByArch(archGood) |
| 160 |
if err != nil { |
| 161 |
t.Errorf("Error getting syscall name for number 0x1 and arch AMD64") |
| 162 |
} else if name != "write" { |
| 163 |
t.Errorf("Got incorrect name for syscall 0x1 - expected write, got %s", name) |
| 164 |
} |
| 165 |
|
| 166 |
_, err = call1.GetNameByArch(archBad) |
| 167 |
if err == nil { |
| 168 |
t.Errorf("Bad architecture GetNameByArch() should error!") |
| 169 |
} |
| 170 |
|
| 171 |
_, err = callInvalid.GetNameByArch(archGood) |
| 172 |
if err == nil { |
| 173 |
t.Errorf("Bad syscall GetNameByArch() should error!") |
| 174 |
} |
| 175 |
|
| 176 |
_, err = callInvalid.GetNameByArch(archBad) |
| 177 |
if err == nil { |
| 178 |
t.Errorf("Bad syscall and bad arch GetNameByArch() should error!") |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
func TestGetSyscallFromName(t *testing.T) { |
| 183 |
name1 := "write" |
| 184 |
nameInval := "NOTASYSCALL" |
| 185 |
|
| 186 |
syscall, err := GetSyscallFromName(name1) |
| 187 |
if err != nil { |
| 188 |
t.Errorf("Error getting syscall number of write: %s", err) |
| 189 |
} |
| 190 |
t.Logf("Got syscall number of write on native arch as %d\n", syscall) |
| 191 |
|
| 192 |
_, err = GetSyscallFromName(nameInval) |
| 193 |
if err == nil { |
| 194 |
t.Errorf("Getting an invalid syscall should error!") |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
func TestGetSyscallFromNameByArch(t *testing.T) { |
| 199 |
name1 := "write" |
| 200 |
nameInval := "NOTASYSCALL" |
| 201 |
arch1 := ArchAMD64 |
| 202 |
archInval := ArchInvalid |
| 203 |
|
| 204 |
syscall, err := GetSyscallFromNameByArch(name1, arch1) |
| 205 |
if err != nil { |
| 206 |
t.Errorf("Error getting syscall number of write on AMD64: %s", err) |
| 207 |
} |
| 208 |
t.Logf("Got syscall number of write on AMD64 as %d\n", syscall) |
| 209 |
|
| 210 |
_, err = GetSyscallFromNameByArch(nameInval, arch1) |
| 211 |
if err == nil { |
| 212 |
t.Errorf("Getting invalid syscall with valid arch should error") |
| 213 |
} |
| 214 |
|
| 215 |
_, err = GetSyscallFromNameByArch(name1, archInval) |
| 216 |
if err == nil { |
| 217 |
t.Errorf("Getting valid syscall for invalid arch should error") |
| 218 |
} |
| 219 |
|
| 220 |
_, err = GetSyscallFromNameByArch(nameInval, archInval) |
| 221 |
if err == nil { |
| 222 |
t.Errorf("Getting invalid syscall for invalid arch should error") |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
func TestMakeCondition(t *testing.T) { |
| 227 |
condition, err := MakeCondition(3, CompareNotEqual, 0x10) |
| 228 |
if err != nil { |
| 229 |
t.Errorf("Error making condition struct: %s", err) |
| 230 |
} else if condition.Argument != 3 || condition.Operand1 != 0x10 || |
| 231 |
condition.Operand2 != 0 || condition.Op != CompareNotEqual { |
| 232 |
t.Errorf("Condition struct was filled incorrectly") |
| 233 |
} |
| 234 |
|
| 235 |
condition, err = MakeCondition(3, CompareMaskedEqual, 0x10, 0x20) |
| 236 |
if err != nil { |
| 237 |
t.Errorf("Error making condition struct: %s", err) |
| 238 |
} else if condition.Argument != 3 || condition.Operand1 != 0x10 || |
| 239 |
condition.Operand2 != 0x20 || condition.Op != CompareMaskedEqual { |
| 240 |
t.Errorf("Condition struct was filled incorrectly") |
| 241 |
} |
| 242 |
|
| 243 |
_, err = MakeCondition(7, CompareNotEqual, 0x10) |
| 244 |
if err == nil { |
| 245 |
t.Errorf("Condition struct with bad syscall argument number should error") |
| 246 |
} |
| 247 |
|
| 248 |
_, err = MakeCondition(3, CompareInvalid, 0x10) |
| 249 |
if err == nil { |
| 250 |
t.Errorf("Condition struct with bad comparison operator should error") |
| 251 |
} |
| 252 |
|
| 253 |
_, err = MakeCondition(3, CompareMaskedEqual, 0x10, 0x20, 0x30) |
| 254 |
if err == nil { |
| 255 |
t.Errorf("MakeCondition with more than 2 arguments should fail") |
| 256 |
} |
| 257 |
|
| 258 |
_, err = MakeCondition(3, CompareMaskedEqual) |
| 259 |
if err == nil { |
| 260 |
t.Errorf("MakeCondition with no arguments should fail") |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
func TestGetNativeArch(t *testing.T) { |
| 267 |
arch, err := GetNativeArch() |
| 268 |
if err != nil { |
| 269 |
t.Errorf("GetNativeArch should not error!") |
| 270 |
} |
| 271 |
t.Logf("Got native arch of system as %s\n", arch.String()) |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
func TestFilterCreateRelease(t *testing.T) { |
| 277 |
_, err := NewFilter(ActInvalid) |
| 278 |
if err == nil { |
| 279 |
t.Errorf("Can create filter with invalid action") |
| 280 |
} |
| 281 |
|
| 282 |
filter, err := NewFilter(ActKillThread) |
| 283 |
if err != nil { |
| 284 |
t.Errorf("Error creating filter: %s", err) |
| 285 |
} |
| 286 |
|
| 287 |
if !filter.IsValid() { |
| 288 |
t.Errorf("Filter created by NewFilter was not valid") |
| 289 |
} |
| 290 |
|
| 291 |
filter.Release() |
| 292 |
|
| 293 |
if filter.IsValid() { |
| 294 |
t.Errorf("Filter is valid after being released") |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
func TestFilterReset(t *testing.T) { |
| 299 |
filter, err := NewFilter(ActKillThread) |
| 300 |
if err != nil { |
| 301 |
t.Errorf("Error creating filter: %s", err) |
| 302 |
} |
| 303 |
defer filter.Release() |
| 304 |
|
| 305 |
|
| 306 |
action, err := filter.GetDefaultAction() |
| 307 |
if err != nil { |
| 308 |
t.Errorf("Error getting default action of filter") |
| 309 |
} else if action != ActKillThread { |
| 310 |
t.Errorf("Default action of filter was set incorrectly!") |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
err = filter.Reset(ActAllow) |
| 315 |
if err != nil { |
| 316 |
t.Errorf("Error resetting filter!") |
| 317 |
} |
| 318 |
|
| 319 |
valid := filter.IsValid() |
| 320 |
if !valid { |
| 321 |
t.Errorf("Filter is no longer valid after reset!") |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
action, err = filter.GetDefaultAction() |
| 326 |
if err != nil { |
| 327 |
t.Errorf("Error getting default action of filter") |
| 328 |
} else if action != ActAllow { |
| 329 |
t.Errorf("Default action of filter was set incorrectly!") |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
func TestFilterArchFunctions(t *testing.T) { |
| 334 |
filter, err := NewFilter(ActKillThread) |
| 335 |
if err != nil { |
| 336 |
t.Errorf("Error creating filter: %s", err) |
| 337 |
} |
| 338 |
defer filter.Release() |
| 339 |
|
| 340 |
arch, err := GetNativeArch() |
| 341 |
if err != nil { |
| 342 |
t.Errorf("Error getting native architecture: %s", err) |
| 343 |
} |
| 344 |
|
| 345 |
present, err := filter.IsArchPresent(arch) |
| 346 |
if err != nil { |
| 347 |
t.Errorf("Error retrieving arch from filter: %s", err) |
| 348 |
} else if !present { |
| 349 |
t.Errorf("Filter does not contain native architecture by default") |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
err = filter.AddArch(arch) |
| 354 |
if err != nil { |
| 355 |
t.Errorf("Adding arch to filter already containing it should succeed") |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
prospectiveArch := ArchX86 |
| 360 |
if arch == ArchX86 { |
| 361 |
prospectiveArch = ArchAMD64 |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
present, err = filter.IsArchPresent(prospectiveArch) |
| 366 |
if err != nil { |
| 367 |
t.Errorf("Error retrieving arch from filter: %s", err) |
| 368 |
} else if present { |
| 369 |
t.Errorf("Arch not added to filter is present") |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
err = filter.RemoveArch(prospectiveArch) |
| 374 |
if err != nil { |
| 375 |
t.Errorf("Error removing nonexistent arch: %s", err) |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
err = filter.AddArch(prospectiveArch) |
| 380 |
if err != nil { |
| 381 |
t.Errorf("Could not add arch %s to filter: %s", |
| 382 |
prospectiveArch.String(), err) |
| 383 |
} |
| 384 |
|
| 385 |
present, err = filter.IsArchPresent(prospectiveArch) |
| 386 |
if err != nil { |
| 387 |
t.Errorf("Error retrieving arch from filter: %s", err) |
| 388 |
} else if !present { |
| 389 |
t.Errorf("Filter does not contain architecture %s after it was added", |
| 390 |
prospectiveArch.String()) |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
err = filter.RemoveArch(prospectiveArch) |
| 395 |
if err != nil { |
| 396 |
t.Errorf("Could not remove arch %s from filter: %s", |
| 397 |
prospectiveArch.String(), err) |
| 398 |
} |
| 399 |
|
| 400 |
present, err = filter.IsArchPresent(prospectiveArch) |
| 401 |
if err != nil { |
| 402 |
t.Errorf("Error retrieving arch from filter: %s", err) |
| 403 |
} else if present { |
| 404 |
t.Errorf("Filter contains architecture %s after it was removed", |
| 405 |
prospectiveArch.String()) |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
func TestFilterAttributeGettersAndSetters(t *testing.T) { |
| 410 |
filter, err := NewFilter(ActKillThread) |
| 411 |
if err != nil { |
| 412 |
t.Errorf("Error creating filter: %s", err) |
| 413 |
} |
| 414 |
defer filter.Release() |
| 415 |
|
| 416 |
act, err := filter.GetDefaultAction() |
| 417 |
if err != nil { |
| 418 |
t.Errorf("Error getting default action: %s", err) |
| 419 |
} else if act != ActKillThread { |
| 420 |
t.Errorf("Default action was set incorrectly") |
| 421 |
} |
| 422 |
|
| 423 |
err = filter.SetBadArchAction(ActAllow) |
| 424 |
if err != nil { |
| 425 |
t.Errorf("Error setting bad arch action: %s", err) |
| 426 |
} |
| 427 |
|
| 428 |
act, err = filter.GetBadArchAction() |
| 429 |
if err != nil { |
| 430 |
t.Errorf("Error getting bad arch action") |
| 431 |
} else if act != ActAllow { |
| 432 |
t.Errorf("Bad arch action was not set correctly!") |
| 433 |
} |
| 434 |
|
| 435 |
err = filter.SetBadArchAction(ActInvalid) |
| 436 |
if err == nil { |
| 437 |
t.Errorf("Setting bad arch action to an invalid action should error") |
| 438 |
} |
| 439 |
|
| 440 |
err = filter.SetNoNewPrivsBit(false) |
| 441 |
if err != nil { |
| 442 |
t.Errorf("Error setting no new privileges bit") |
| 443 |
} |
| 444 |
|
| 445 |
privs, err := filter.GetNoNewPrivsBit() |
| 446 |
if err != nil { |
| 447 |
t.Errorf("Error getting no new privileges bit!") |
| 448 |
} else if privs != false { |
| 449 |
t.Errorf("No new privileges bit was not set correctly") |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
if err := checkAPI(t.Name(), 3, 2, 4, 0); err != nil { |
| 454 |
t.Logf("Skipping the rest of the test: %v", err) |
| 455 |
return |
| 456 |
} |
| 457 |
|
| 458 |
err = filter.SetLogBit(true) |
| 459 |
if err != nil { |
| 460 |
t.Errorf("Error setting log bit: %v", err) |
| 461 |
} |
| 462 |
|
| 463 |
log, err := filter.GetLogBit() |
| 464 |
if err != nil { |
| 465 |
t.Errorf("Error getting log bit: %v", err) |
| 466 |
} else if log != true { |
| 467 |
t.Error("Log bit was not set correctly") |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
if err := checkAPI(t.Name(), 4, 2, 5, 0); err != nil { |
| 472 |
t.Logf("Skipping the rest of the test: %v", err) |
| 473 |
return |
| 474 |
} |
| 475 |
|
| 476 |
err = filter.SetSSB(true) |
| 477 |
if err != nil { |
| 478 |
t.Errorf("Error setting SSB bit: %v", err) |
| 479 |
} |
| 480 |
|
| 481 |
ssb, err := filter.GetSSB() |
| 482 |
if err != nil { |
| 483 |
t.Errorf("Error getting SSB bit: %v", err) |
| 484 |
} else if ssb != true { |
| 485 |
t.Error("SSB bit was not set correctly") |
| 486 |
} |
| 487 |
|
| 488 |
err = filter.SetOptimize(2) |
| 489 |
if err != nil { |
| 490 |
t.Errorf("Error setting optimize level: %v", err) |
| 491 |
} |
| 492 |
|
| 493 |
level, err := filter.GetOptimize() |
| 494 |
if err != nil { |
| 495 |
t.Errorf("Error getting optimize level: %v", err) |
| 496 |
} else if level != 2 { |
| 497 |
t.Error("Optimize level was not set correctly") |
| 498 |
} |
| 499 |
|
| 500 |
err = filter.SetRawRC(true) |
| 501 |
if err != nil { |
| 502 |
t.Errorf("Error setting RawRC flag: %v", err) |
| 503 |
} |
| 504 |
|
| 505 |
rawrc, err := filter.GetRawRC() |
| 506 |
if err != nil { |
| 507 |
t.Errorf("Error getting RawRC flag: %v", err) |
| 508 |
} else if rawrc != true { |
| 509 |
t.Error("RawRC flag was not set correctly") |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
if err := checkAPI(t.Name(), 7, 2, 6, 0); err != nil { |
| 514 |
t.Logf("Skipping the rest of the test: %v", err) |
| 515 |
return |
| 516 |
} |
| 517 |
|
| 518 |
err = filter.SetWaitKill(true) |
| 519 |
if err != nil { |
| 520 |
t.Errorf("Error setting WaitKill flag: %v", err) |
| 521 |
} |
| 522 |
|
| 523 |
wk, err := filter.GetWaitKill() |
| 524 |
if err != nil { |
| 525 |
t.Errorf("Error getting WaitKill flag: %v", err) |
| 526 |
} else if wk != true { |
| 527 |
t.Error("WaitKill flag was not set correctly") |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
func TestMergeFilters(t *testing.T) { |
| 532 |
filter1, err := NewFilter(ActAllow) |
| 533 |
if err != nil { |
| 534 |
t.Errorf("Error creating filter: %s", err) |
| 535 |
} |
| 536 |
|
| 537 |
filter2, err := NewFilter(ActAllow) |
| 538 |
if err != nil { |
| 539 |
t.Errorf("Error creating filter: %s", err) |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
nativeArch, err := GetNativeArch() |
| 545 |
if err != nil { |
| 546 |
t.Errorf("Error getting native arch: %s", err) |
| 547 |
} |
| 548 |
|
| 549 |
prospectiveArch := ArchAMD64 |
| 550 |
if nativeArch == ArchAMD64 { |
| 551 |
prospectiveArch = ArchX86 |
| 552 |
} |
| 553 |
|
| 554 |
err = filter2.AddArch(prospectiveArch) |
| 555 |
if err != nil { |
| 556 |
t.Errorf("Error adding architecture to filter: %s", err) |
| 557 |
} |
| 558 |
|
| 559 |
err = filter2.RemoveArch(nativeArch) |
| 560 |
if err != nil { |
| 561 |
t.Errorf("Error removing architecture from filter: %s", err) |
| 562 |
} |
| 563 |
|
| 564 |
err = filter1.Merge(filter2) |
| 565 |
if err != nil { |
| 566 |
t.Errorf("Error merging filters: %s", err) |
| 567 |
} |
| 568 |
|
| 569 |
if filter2.IsValid() { |
| 570 |
t.Errorf("Source filter should not be valid after merging") |
| 571 |
} |
| 572 |
|
| 573 |
filter3, err := NewFilter(ActKillThread) |
| 574 |
if err != nil { |
| 575 |
t.Errorf("Error creating filter: %s", err) |
| 576 |
} |
| 577 |
defer filter3.Release() |
| 578 |
|
| 579 |
err = filter1.Merge(filter3) |
| 580 |
if err == nil { |
| 581 |
t.Errorf("Attributes should have to match to merge filters") |
| 582 |
} |
| 583 |
} |
| 584 |
|
| 585 |
func TestAddRuleErrors(t *testing.T) { |
| 586 |
execInSubprocess(t, subprocessAddRuleErrors) |
| 587 |
} |
| 588 |
|
| 589 |
func subprocessAddRuleErrors(t *testing.T) { |
| 590 |
filter, err := NewFilter(ActAllow) |
| 591 |
if err != nil { |
| 592 |
t.Errorf("Error creating filter: %s", err) |
| 593 |
} |
| 594 |
defer filter.Release() |
| 595 |
|
| 596 |
err = filter.AddRule(ScmpSyscall(0x1), ActAllow) |
| 597 |
if err == nil { |
| 598 |
t.Error("expected error, got nil") |
| 599 |
} else if err != errDefAction { |
| 600 |
t.Errorf("expected error %v, got %v", errDefAction, err) |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
func TestRuleAddAndLoad(t *testing.T) { |
| •605 |
if runtime.GOARCH == "ppc64le" { |
| 606 |
t.Skip("https://github.com/seccomp/libseccomp-golang/issues/61") |
| 607 |
} |
| 608 |
execInSubprocess(t, subprocessRuleAddAndLoad) |
| 609 |
} |
| 610 |
|
| 611 |
func subprocessRuleAddAndLoad(t *testing.T) { |
| 612 |
doSubprocessRuleAddAndLoad(t, false) |
| 613 |
} |
| 614 |
|
| 615 |
func TestRuleAddPrecomputeAndLoad(t *testing.T) { |
| 616 |
execInSubprocess(t, subprocessRuleAddPrecomputeAndLoad) |
| 617 |
} |
| 618 |
|
| 619 |
func subprocessRuleAddPrecomputeAndLoad(t *testing.T) { |
| 620 |
doSubprocessRuleAddAndLoad(t, true) |
| 621 |
} |
| 622 |
|
| 623 |
func doSubprocessRuleAddAndLoad(t *testing.T, precompute bool) { |
| 624 |
|
| 625 |
filter1, err := NewFilter(ActAllow) |
| 626 |
if err != nil { |
| 627 |
t.Errorf("Error creating filter: %s", err) |
| 628 |
} |
| 629 |
defer filter1.Release() |
| 630 |
|
| 631 |
const expErr = syscall.ENOSPC |
| 632 |
call, err := GetSyscallFromName("listen") |
| 633 |
if err != nil { |
| 634 |
t.Errorf("Error getting syscall number of listen: %s", err) |
| 635 |
} |
| 636 |
err = filter1.AddRule(call, ActErrno.SetReturnCode(int16(expErr))) |
| 637 |
if err != nil { |
| 638 |
t.Errorf("Error adding rule to restrict syscall: %s", err) |
| 639 |
} |
| 640 |
|
| 641 |
call2, err := GetSyscallFromName("setreuid") |
| 642 |
if err != nil { |
| 643 |
t.Errorf("Error getting syscall number of setreuid: %s", err) |
| 644 |
} |
| 645 |
|
| 646 |
call3, err := GetSyscallFromName("setreuid32") |
| 647 |
if err != nil { |
| 648 |
t.Errorf("Error getting syscall number of setreuid32: %s", err) |
| 649 |
} |
| 650 |
|
| 651 |
uid := syscall.Getuid() |
| 652 |
euid := syscall.Geteuid() |
| 653 |
|
| 654 |
cond, err := MakeCondition(1, CompareEqual, uint64(euid)) |
| 655 |
if err != nil { |
| 656 |
t.Errorf("Error making rule to restrict syscall: %s", err) |
| 657 |
} |
| 658 |
|
| 659 |
cond2, err := MakeCondition(0, CompareEqual, uint64(uid)) |
| 660 |
if err != nil { |
| 661 |
t.Errorf("Error making rule to restrict syscall: %s", err) |
| 662 |
} |
| 663 |
|
| 664 |
conditions := []ScmpCondition{cond, cond2} |
| 665 |
|
| 666 |
err = filter1.AddRuleConditional(call2, ActErrno.SetReturnCode(0x2), conditions) |
| 667 |
if err != nil { |
| 668 |
t.Errorf("Error adding conditional rule: %s", err) |
| 669 |
} |
| 670 |
|
| 671 |
err = filter1.AddRuleConditional(call3, ActErrno.SetReturnCode(0x3), conditions) |
| 672 |
if err != nil { |
| 673 |
t.Errorf("Error adding second conditional rule: %s", err) |
| 674 |
} |
| 675 |
|
| 676 |
if precompute { |
| 677 |
expErr := error(nil) |
| 678 |
|
| 679 |
if checkAPI(t.Name(), 7, 2, 6, 0) != nil { |
| 680 |
expErr = syscall.EOPNOTSUPP |
| 681 |
} |
| 682 |
|
| 683 |
err = filter1.Precompute() |
| 684 |
if !errors.Is(err, expErr) { |
| 685 |
t.Errorf("Precompute: want %v, got %v", expErr, err) |
| 686 |
} |
| 687 |
} |
| 688 |
|
| 689 |
err = filter1.Load() |
| 690 |
if err != nil { |
| 691 |
t.Errorf("Error loading filter: %s", err) |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
if err := syscall.Listen(0, 0); err != expErr { |
| 696 |
t.Errorf("Syscall listen: want %v, got %v", expErr, err) |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
err = syscall.Setreuid(uid, euid) |
| 701 |
if err == nil { |
| 702 |
t.Errorf("Syscall should have returned error code!") |
| 703 |
} else if err != syscall.Errno(2) && err != syscall.Errno(3) { |
| 704 |
t.Errorf("Syscall returned incorrect error code - likely not blocked by Seccomp!") |
| 705 |
} |
| 706 |
} |
| 707 |
|
| 708 |
func TestLogAct(t *testing.T) { |
| 709 |
execInSubprocess(t, subprocessLogAct) |
| 710 |
} |
| 711 |
|
| 712 |
func subprocessLogAct(t *testing.T) { |
| 713 |
|
| 714 |
if err := checkAPI(t.Name(), 3, 2, 4, 0); err != nil { |
| 715 |
t.Skip(err) |
| 716 |
} |
| 717 |
|
| 718 |
expectedPid := syscall.Getpid() |
| 719 |
|
| 720 |
filter, err := NewFilter(ActAllow) |
| 721 |
if err != nil { |
| 722 |
t.Errorf("Error creating filter: %s", err) |
| 723 |
} |
| 724 |
defer filter.Release() |
| 725 |
|
| 726 |
call, err := GetSyscallFromName("getpid") |
| 727 |
if err != nil { |
| 728 |
t.Errorf("Error getting syscall number of getpid: %s", err) |
| 729 |
} |
| 730 |
|
| 731 |
err = filter.AddRule(call, ActLog) |
| 732 |
if err != nil { |
| 733 |
t.Errorf("Error adding rule to log syscall: %s", err) |
| 734 |
} |
| 735 |
|
| 736 |
err = filter.Load() |
| 737 |
if err != nil { |
| 738 |
t.Errorf("Error loading filter: %s", err) |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
pid := syscall.Getpid() |
| 743 |
if pid != expectedPid { |
| 744 |
t.Errorf("Syscall should have returned expected pid (%d != %d)", pid, expectedPid) |
| 745 |
} |
| 746 |
} |
| 747 |
|
| 748 |
func TestCreateActKillThreadFilter(t *testing.T) { |
| 749 |
execInSubprocess(t, subprocessCreateActKillThreadFilter) |
| 750 |
} |
| 751 |
|
| 752 |
func subprocessCreateActKillThreadFilter(t *testing.T) { |
| 753 |
filter, err := NewFilter(ActKillThread) |
| 754 |
if err != nil { |
| 755 |
t.Errorf("Error creating filter: %s", err) |
| 756 |
} |
| 757 |
|
| 758 |
if !filter.IsValid() { |
| 759 |
t.Errorf("Filter created by NewFilter was not valid") |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
func TestCreateActKillProcessFilter(t *testing.T) { |
| 764 |
execInSubprocess(t, subprocessCreateActKillProcessFilter) |
| 765 |
} |
| 766 |
|
| 767 |
func subprocessCreateActKillProcessFilter(t *testing.T) { |
| 768 |
|
| 769 |
if err := checkAPI(t.Name(), 3, 2, 4, 0); err != nil { |
| 770 |
t.Skip(err) |
| 771 |
} |
| 772 |
|
| 773 |
filter, err := NewFilter(ActKillThread) |
| 774 |
if err != nil { |
| 775 |
t.Errorf("Error creating filter: %s", err) |
| 776 |
} |
| 777 |
|
| 778 |
if !filter.IsValid() { |
| 779 |
t.Errorf("Filter created by NewFilter was not valid") |
| 780 |
} |
| 781 |
} |
| 782 |
|
| 783 |
func TestExportBPF(t *testing.T) { |
| 784 |
execInSubprocess(t, subprocessExportBPF) |
| 785 |
} |
| 786 |
|
| 787 |
func subprocessExportBPF(t *testing.T) { |
| 788 |
filter, err := NewFilter(ActAllow) |
| 789 |
if err != nil { |
| 790 |
t.Fatalf("Error creating filter: %s", err) |
| 791 |
} |
| 792 |
defer filter.Release() |
| 793 |
|
| 794 |
call, err := GetSyscallFromName("getpid") |
| 795 |
if err != nil { |
| 796 |
t.Fatalf("Error getting syscall number of getpid: %s", err) |
| 797 |
} |
| 798 |
|
| 799 |
err = filter.AddRule(call, ActErrno.SetReturnCode(42)) |
| 800 |
if err != nil { |
| 801 |
t.Fatalf("Error adding rule: %s", err) |
| 802 |
} |
| 803 |
|
| 804 |
file, err := os.Create(t.TempDir() + "/bpf") |
| 805 |
if err != nil { |
| 806 |
t.Fatal(err) |
| 807 |
} |
| 808 |
defer file.Close() |
| 809 |
|
| 810 |
err = filter.ExportBPF(file) |
| 811 |
if err != nil { |
| 812 |
t.Fatalf("ExportBPF: %v", err) |
| 813 |
} |
| 814 |
|
| 815 |
if _, err := file.Seek(0, io.SeekStart); err != nil { |
| 816 |
t.Fatal(err) |
| 817 |
} |
| 818 |
contents, err := io.ReadAll(file) |
| 819 |
if err != nil { |
| 820 |
t.Fatal(err) |
| 821 |
} |
| 822 |
t.Logf("ExportBPF: size %d", len(contents)) |
| 823 |
|
| 824 |
expErr := error(nil) |
| 825 |
|
| 826 |
if checkAPI(t.Name(), 0, 2, 6, 0) != nil { |
| 827 |
expErr = syscall.EOPNOTSUPP |
| 828 |
} |
| 829 |
contentsMem, err := filter.ExportBPFMem() |
| 830 |
if err != expErr { |
| 831 |
t.Errorf("ExportBPFMem: want %v, got %v", expErr, err) |
| 832 |
} |
| 833 |
if err == nil { |
| 834 |
t.Logf("ExportBPFMem: size %d", len(contents)) |
| 835 |
if !bytes.Equal(contents, contentsMem) { |
| 836 |
t.Errorf("Got different data from ExportBPF and ExportBPFMem (%v != %v)", contents, contentsMem) |
| 837 |
} |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
type notifTest struct { |
| 847 |
syscall ScmpSyscall |
| 848 |
args [6]uintptr |
| 849 |
arch ScmpArch |
| 850 |
respErr int32 |
| 851 |
respVal uint64 |
| 852 |
respFlags uint32 |
| 853 |
expectedErr error |
| 854 |
expectedVal uint64 |
| 855 |
} |
| 856 |
|
| 857 |
|
| 858 |
func notifHandler(ch chan error, fd ScmpFd, tests []notifTest) { |
| 859 |
for _, test := range tests { |
| 860 |
req, err := NotifReceive(fd) |
| 861 |
if err != nil { |
| 862 |
ch <- fmt.Errorf("Error in NotifReceive(): %s", err) |
| 863 |
return |
| 864 |
} |
| 865 |
|
| 866 |
if req.Data.Syscall != test.syscall { |
| 867 |
want, _ := test.syscall.GetName() |
| 868 |
got, _ := req.Data.Syscall.GetName() |
| 869 |
ch <- fmt.Errorf("Error in notification request syscall: got %s, want %s", got, want) |
| 870 |
return |
| 871 |
} |
| 872 |
|
| 873 |
if req.Data.Arch != test.arch { |
| 874 |
ch <- fmt.Errorf("Error in notification request arch: got %s, want %s", req.Data.Arch, test.arch) |
| 875 |
return |
| 876 |
} |
| 877 |
|
| 878 |
for i, arg := range test.args { |
| 879 |
if arg != uintptr(req.Data.Args[i]) { |
| 880 |
ch <- fmt.Errorf("Error in syscall arg[%d]: got 0x%x, want 0x%x", i, req.Data.Args[i], arg) |
| 881 |
return |
| 882 |
} |
| 883 |
} |
| 884 |
|
| 885 |
|
| 886 |
if err := NotifIDValid(fd, req.ID); err != nil { |
| 887 |
ch <- fmt.Errorf("TOCTOU check failed: req.ID is no longer valid: %s", err) |
| 888 |
return |
| 889 |
} |
| 890 |
|
| 891 |
resp := &ScmpNotifResp{ |
| 892 |
ID: req.ID, |
| 893 |
Error: test.respErr, |
| 894 |
Val: test.respVal, |
| 895 |
Flags: test.respFlags, |
| 896 |
} |
| 897 |
|
| 898 |
if err = NotifRespond(fd, resp); err != nil { |
| 899 |
ch <- fmt.Errorf("Error in notification response: %s", err) |
| 900 |
return |
| 901 |
} |
| 902 |
|
| 903 |
ch <- nil |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
func TestNotif(t *testing.T) { |
| •908 |
if bits.UintSize == 32 { |
| 909 |
t.Skip("not working on 32bit system") |
| 910 |
} |
| 911 |
execInSubprocess(t, subprocessNotif) |
| 912 |
} |
| 913 |
|
| 914 |
func subprocessNotif(t *testing.T) { |
| 915 |
if err := notifSupported(); err != nil { |
| 916 |
t.Skip(err) |
| 917 |
} |
| 918 |
|
| 919 |
arch, err := GetNativeArch() |
| 920 |
if err != nil { |
| 921 |
t.Errorf("Error in GetNativeArch(): %s", err) |
| 922 |
return |
| 923 |
} |
| 924 |
|
| 925 |
cwd, err := os.Getwd() |
| 926 |
if err != nil { |
| 927 |
t.Errorf("Error in Getwd(): %s", err) |
| 928 |
return |
| 929 |
} |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
filter, err := NewFilter(ActAllow) |
| 936 |
if err != nil { |
| 937 |
t.Errorf("Error creating filter: %s", err) |
| 938 |
} |
| 939 |
defer filter.Release() |
| 940 |
|
| 941 |
call, err := GetSyscallFromName("chdir") |
| 942 |
if err != nil { |
| 943 |
t.Errorf("Error getting syscall number: %s", err) |
| 944 |
} |
| 945 |
|
| 946 |
err = filter.AddRule(call, ActNotify) |
| 947 |
if err != nil { |
| 948 |
t.Errorf("Error adding rule to log syscall: %s", err) |
| 949 |
} |
| 950 |
|
| 951 |
nonExistentPath, err := syscall.BytePtrFromString("/non-existent-path") |
| 952 |
if err != nil { |
| 953 |
t.Errorf("Error converting string: %s", err) |
| 954 |
} |
| 955 |
currentWorkingDirectory, err := syscall.BytePtrFromString(cwd) |
| 956 |
if err != nil { |
| 957 |
t.Errorf("Error converting string: %s", err) |
| 958 |
} |
| 959 |
|
| 960 |
tests := []notifTest{ |
| 961 |
{ |
| 962 |
syscall: call, |
| 963 |
args: [6]uintptr{uintptr(unsafe.Pointer(nonExistentPath)), 0, 0, 0, 0, 0}, |
| 964 |
arch: arch, |
| 965 |
respErr: 0, |
| 966 |
respVal: 0, |
| 967 |
respFlags: NotifRespFlagContinue, |
| 968 |
expectedErr: syscall.ENOENT, |
| 969 |
expectedVal: ^uint64(0), |
| 970 |
}, |
| 971 |
{ |
| 972 |
syscall: call, |
| 973 |
args: [6]uintptr{uintptr(unsafe.Pointer(currentWorkingDirectory)), 0, 0, 0, 0, 0}, |
| 974 |
arch: arch, |
| 975 |
respErr: 0, |
| 976 |
respVal: 0, |
| 977 |
respFlags: NotifRespFlagContinue, |
| 978 |
expectedErr: syscall.Errno(0), |
| 979 |
expectedVal: 0, |
| 980 |
}, |
| 981 |
{ |
| 982 |
syscall: call, |
| 983 |
args: [6]uintptr{uintptr(unsafe.Pointer(nonExistentPath)), 0, 0, 0, 0, 0}, |
| 984 |
arch: arch, |
| 985 |
respErr: int32(syscall.ENOMEDIUM), |
| 986 |
respVal: ^uint64(0), |
| 987 |
respFlags: 0, |
| 988 |
expectedErr: syscall.ENOMEDIUM, |
| 989 |
expectedVal: ^uint64(0), |
| 990 |
}, |
| 991 |
{ |
| 992 |
syscall: call, |
| 993 |
args: [6]uintptr{uintptr(unsafe.Pointer(currentWorkingDirectory)), 0, 0, 0, 0, 0}, |
| 994 |
arch: arch, |
| 995 |
respErr: int32(syscall.EPIPE), |
| 996 |
respVal: ^uint64(0), |
| 997 |
respFlags: 0, |
| 998 |
expectedErr: syscall.EPIPE, |
| 999 |
expectedVal: ^uint64(0), |
| 1000 |
}, |
| 1001 |
} |
| 1002 |
|
| 1003 |
seccompFdChan := make(chan ScmpFd) |
| 1004 |
errorChan := make(chan error, 2) |
| 1005 |
infoChan := make(chan string) |
| 1006 |
done := make(chan struct{}) |
| 1007 |
|
| 1008 |
go func() { |
| 1009 |
err = filter.Load() |
| 1010 |
if err != nil { |
| 1011 |
t.Errorf("Error loading filter: %s", err) |
| 1012 |
} |
| 1013 |
|
| 1014 |
fd, err := filter.GetNotifFd() |
| 1015 |
if err != nil { |
| 1016 |
t.Errorf("Error getting filter notification fd: %s", err) |
| 1017 |
} |
| 1018 |
|
| 1019 |
if fd < 3 { |
| 1020 |
t.Errorf("Error in notification fd: want >=3, got %v", fd) |
| 1021 |
} |
| 1022 |
seccompFdChan <- fd |
| 1023 |
|
| 1024 |
for i, test := range tests { |
| 1025 |
infoChan <- fmt.Sprintf("Starting test %d", i) |
| 1026 |
r1, r2, err := syscall.Syscall6(syscall.SYS_CHDIR, |
| 1027 |
test.args[0], test.args[1], test.args[2], test.args[3], test.args[4], test.args[5]) |
| 1028 |
if err != test.expectedErr || uint64(r1) != test.expectedVal { |
| 1029 |
errorChan <- fmt.Errorf("test #%d: error in syscall: want \"%s\", got \"%s\" (want %v, got r1=%v, r2=%v)", |
| 1030 |
i, test.expectedErr, err, test.expectedVal, r1, r2) |
| 1031 |
} |
| 1032 |
infoChan <- fmt.Sprintf("Test %d completed", i) |
| 1033 |
} |
| 1034 |
done <- struct{}{} |
| 1035 |
}() |
| 1036 |
|
| 1037 |
seccompFd := <-seccompFdChan |
| 1038 |
go notifHandler(errorChan, seccompFd, tests) |
| 1039 |
|
| 1040 |
L: |
| 1041 |
for { |
| 1042 |
select { |
| 1043 |
case <-done: |
| 1044 |
t.Logf("Tests completed") |
| 1045 |
break L |
| 1046 |
case msg := <-infoChan: |
| 1047 |
t.Logf("%s", msg) |
| 1048 |
case err = <-errorChan: |
| 1049 |
if err != nil { |
| 1050 |
t.Errorf("Received error: %s", err.Error()) |
| 1051 |
break L |
| 1052 |
} |
| 1053 |
case <-time.After(5 * time.Second): |
| 1054 |
t.Errorf("Timeout during tests") |
| 1055 |
break L |
| 1056 |
} |
| 1057 |
} |
| 1058 |
} |
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
func TestNotifUnsupported(t *testing.T) { |
| 1064 |
execInSubprocess(t, subprocessNotifUnsupported) |
| 1065 |
} |
| 1066 |
|
| 1067 |
func subprocessNotifUnsupported(t *testing.T) { |
| 1068 |
if err := notifSupported(); err == nil { |
| 1069 |
t.Skip("seccomp notification is supported") |
| 1070 |
} |
| 1071 |
|
| 1072 |
filter, err := NewFilter(ActAllow) |
| 1073 |
if err != nil { |
| 1074 |
t.Errorf("Error creating filter: %s", err) |
| 1075 |
} |
| 1076 |
defer filter.Release() |
| 1077 |
|
| 1078 |
_, err = filter.GetNotifFd() |
| 1079 |
if err == nil { |
| 1080 |
t.Error("GetNotifFd: got nil, want error") |
| 1081 |
} |
| 1082 |
} |
| 1083 |
|
| 1084 |
func TestTransaction(t *testing.T) { |
| 1085 |
execInSubprocess(t, testTransaction) |
| 1086 |
} |
| 1087 |
|
| 1088 |
func testTransaction(t *testing.T) { |
| 1089 |
if err := checkAPI("seccomp transaction support", 0, 2, 6, 0); err != nil { |
| 1090 |
t.Skip(err) |
| 1091 |
} |
| 1092 |
|
| 1093 |
filter, err := NewFilter(ActAllow) |
| 1094 |
if err != nil { |
| 1095 |
t.Fatalf("Error creating filter: %s", err) |
| 1096 |
} |
| 1097 |
defer filter.Release() |
| 1098 |
|
| 1099 |
if err := filter.TransactionStart(); err != nil { |
| 1100 |
t.Fatalf("Error starting transaction: %v", err) |
| 1101 |
} |
| 1102 |
if err := filter.AddRuleExact(ScmpSyscall(0x1), ActKill); err != nil { |
| 1103 |
t.Fatalf("Error adding rule: %v", err) |
| 1104 |
} |
| 1105 |
if err := filter.TransactionCommit(); err != nil { |
| 1106 |
t.Fatalf("Error committing transaction: %v", err) |
| 1107 |
} |
| 1108 |
|
| 1109 |
if err := filter.TransactionStart(); err != nil { |
| 1110 |
t.Fatalf("Error starting transaction: %v", err) |
| 1111 |
} |
| 1112 |
if err := filter.AddRuleExact(ScmpSyscall(0x1), ActKill); err != nil { |
| 1113 |
t.Fatalf("Error adding rule: %v", err) |
| 1114 |
} |
| 1115 |
filter.TransactionReject() |
| 1116 |
} |
| 1117 |
|
| 1118 |
func TestTransactionUnsupported(t *testing.T) { |
| 1119 |
execInSubprocess(t, testTransactionUnsupported) |
| 1120 |
} |
| 1121 |
|
| 1122 |
func testTransactionUnsupported(t *testing.T) { |
| 1123 |
if checkAPI("seccomp transaction support", 0, 2, 6, 0) == nil { |
| 1124 |
t.Skip("seccomp transaction is supported") |
| 1125 |
} |
| 1126 |
|
| 1127 |
filter, err := NewFilter(ActAllow) |
| 1128 |
if err != nil { |
| 1129 |
t.Fatalf("Error creating filter: %s", err) |
| 1130 |
} |
| 1131 |
defer filter.Release() |
| 1132 |
|
| 1133 |
if filter.TransactionStart() == nil { |
| 1134 |
t.Error("TransactionStart: want error, got nil") |
| 1135 |
} |
| 1136 |
if filter.TransactionCommit() == nil { |
| 1137 |
t.Fatalf("TransactionCommit: want error, got nil") |
| 1138 |
} |
| 1139 |
filter.TransactionReject() |
| 1140 |
} |