Skip to content

Commit 0c842c6

Browse files
adriansrandrewkroh
authored andcommitted
Fixes to rule conversion into display format (#41)
* Fix parsing of syscall rule with non-specified arch The new `rule.ToCommandLine` failed when parsing a syscall rule without an explicit platform. * Fix test panic when GetStatus returns an error TestAuditClientSetBacklogWaitTime would panic when fetch of auditd status fails, for example when run without CAP_AUDIT_READ. * Fix test build in 32-bit platform The test was using some constants too big for a 32-bit signed integer. * Fixes to rule parsing in 32-bit arch Arch resolution logic was not working properly for 32bit architectures. Updated the unit tests for 32bit platforms too. * Tests fixes and exclusions for 32bit platforms - Fix build error in test - Exclude golden tests for now (rules not compatible with 32bit) * Travis: testing round on a 32bit binary
1 parent c9d20c6 commit 0c842c6

File tree

7 files changed

+70
-20
lines changed

7 files changed

+70
-20
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ script:
1515
find . -name '*.go' | grep -v vendor | xargs gofmt -s -l | read &&
1616
echo "Code differs from gofmt's style. Run 'gofmt -s -w .'" 1>&2 && exit 1 || true
1717
- go test -v $(go list ./... | grep -v /vendor/)
18+
- GOARCH=386 go test -v $(go list ./... | grep -v /vendor/)
1819
- mkdir -p build/bin
1920
- go build -o build/bin/audit ./cmd/audit/
2021
- go build -o build/bin/auparse ./cmd/auparse/

audit_test.go

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"fmt"
2727
"io"
2828
"os"
29+
"runtime"
2930
"syscall"
3031
"testing"
3132
"time"
@@ -637,6 +638,9 @@ func TestAuditClientSetBacklogWaitTime(t *testing.T) {
637638
}
638639

639640
status, err := getStatus(t)
641+
if err != nil || status == nil {
642+
t.Skipf("audit status not available: %v", err)
643+
}
640644
if status.FeatureBitmap&AuditFeatureBitmapBacklogWaitTime == 0 {
641645
t.Skip("backlog wait time feature not supported in current kernel")
642646
}
@@ -735,21 +739,63 @@ func TestAuditClientGetStatusAsync(t *testing.T) {
735739
}
736740

737741
func TestRuleParsing(t *testing.T) {
738-
for idx, line := range []string{
739-
"-a always,exit -F arch=b64 -S execve,execveat -F key=exec",
740-
"-a never,exit -F arch=b64 -S connect,accept,bind -F key=external-access",
741-
"-w /etc/group -p wa",
742-
"-w /etc/passwd -p rx",
743-
"-w /etc/gshadow -p rwxa",
744-
"-w /tmp/test -p rwa",
745-
"-a always,exit -F arch=b64 -S open,truncate,ftruncate,creat,openat,open_by_handle_at -F exit=-EACCES -F key=access",
746-
"-a never,exit -F arch=b64 -S open,truncate,ftruncate,creat,openat,open_by_handle_at -F exit=-EPERM -F key=access",
747-
"-a always,exit -F arch=b32 -S open -F key=admin -F uid=root -F gid=root -F exit=33 -F path=/tmp -F perm=rwxa",
748-
"-a always,exit -F arch=b64 -S open -F key=key -F uid=1111 -F gid=333 -F exit=-151111 -F filetype=fifo",
749-
"-a never,exclude -F msgtype=GRP_CHAUTHTOK",
750-
"-a always,user -F uid=root",
751-
"-a always,task -F uid=root",
752-
} {
742+
var rules []string
743+
switch runtime.GOARCH {
744+
case "386":
745+
rules = []string{
746+
"-a always,exit -F arch=b32 -S execve,execveat -F key=exec",
747+
"-a never,exit -F arch=b32 -S bind,connect,accept4 -F key=external-access",
748+
"-w /etc/group -p wa",
749+
"-w /etc/passwd -p rx",
750+
"-w /etc/gshadow -p rwxa",
751+
"-w /tmp/test -p rwa",
752+
"-a always,exit -F arch=b32 -S open,creat,truncate,ftruncate,openat,open_by_handle_at -F exit=-EACCES -F key=access",
753+
"-a never,exit -F arch=b32 -S open,creat,truncate,ftruncate,openat,open_by_handle_at -F exit=-EPERM -F key=access",
754+
"-a always,exit -F arch=b32 -S open -F key=admin -F uid=root -F gid=root -F exit=33 -F path=/tmp -F perm=rwxa",
755+
"-a always,exit -F arch=b32 -S open -F key=key -F uid=1111 -F gid=333 -F exit=-151111 -F filetype=fifo",
756+
"-a never,exclude -F msgtype=GRP_CHAUTHTOK",
757+
"-a always,user -F uid=root",
758+
"-a always,task -F uid=root",
759+
"-a always,exit -S mount -F pid=1234",
760+
}
761+
case "amd64":
762+
rules = []string{
763+
"-a always,exit -F arch=b64 -S execve,execveat -F key=exec",
764+
"-a never,exit -F arch=b64 -S connect,accept,bind -F key=external-access",
765+
"-w /etc/group -p wa",
766+
"-w /etc/passwd -p rx",
767+
"-w /etc/gshadow -p rwxa",
768+
"-w /tmp/test -p rwa",
769+
"-a always,exit -F arch=b64 -S open,truncate,ftruncate,creat,openat,open_by_handle_at -F exit=-EACCES -F key=access",
770+
"-a never,exit -F arch=b64 -S open,truncate,ftruncate,creat,openat,open_by_handle_at -F exit=-EPERM -F key=access",
771+
"-a always,exit -F arch=b32 -S open -F key=admin -F uid=root -F gid=root -F exit=33 -F path=/tmp -F perm=rwxa",
772+
"-a always,exit -F arch=b64 -S open -F key=key -F uid=1111 -F gid=333 -F exit=-151111 -F filetype=fifo",
773+
"-a never,exclude -F msgtype=GRP_CHAUTHTOK",
774+
"-a always,user -F uid=root",
775+
"-a always,task -F uid=root",
776+
"-a always,exit -S mount -F pid=1234",
777+
}
778+
default:
779+
// Can't have multiple syscall testing as ordering of individual syscalls
780+
// will vary between platforms (sorted by syscall id)
781+
rules = []string{
782+
"-a always,exit -S execve -F key=exec",
783+
"-w /etc/group -p wa",
784+
"-w /etc/passwd -p rx",
785+
"-w /etc/gshadow -p rwxa",
786+
"-w /tmp/test -p rwa",
787+
"-a always,exit -S all -F exit=-EACCES -F key=access",
788+
"-a never,exit -S all -F exit=-EPERM -F key=access",
789+
"-a always,exit -S open -F key=admin -F uid=root -F gid=root -F exit=33 -F path=/tmp -F perm=rwxa",
790+
"-a always,exit -S open -F key=key -F uid=1111 -F gid=333 -F exit=-151111 -F filetype=fifo",
791+
"-a never,exclude -F msgtype=GRP_CHAUTHTOK",
792+
"-a always,user -F uid=root",
793+
"-a always,task -F uid=root",
794+
"-a always,exit -S mount -F pid=1234",
795+
}
796+
}
797+
t.Logf("checking %d rules", len(rules))
798+
for idx, line := range rules {
753799
msg := fmt.Sprintf("parsing line #%d: `%s`", idx, line)
754800
r, err := flags.Parse(line)
755801
if err != nil {

reassembler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestReassembler(t *testing.T) {
9696
}
9797

9898
type eventMeta struct {
99-
seq int
99+
seq uint
100100
count int
101101
}
102102

rule/gen_testdata_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
// +build linux
18+
// +build linux,amd64
1919

2020
package rule_test
2121

rule/rule.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,17 @@ func ToCommandLine(wf WireFormat, resolveIds bool) (rule string, err error) {
197197
}
198198
if r.arch == "b32" {
199199
switch arch {
200+
case "i386", "arm", "ppc":
200201
case "aarch64":
201202
arch = "arm"
202203
case "x86_64":
203204
arch = "i386"
204205
case "ppc64", "ppc64le":
205206
arch = "ppc"
206207
default:
207-
return "", errors.New("invalid arch for b32")
208+
return "", fmt.Errorf("invalid arch for b32: '%s'", arch)
208209
}
209-
} else if r.arch != "b64" {
210+
} else if len(r.arch) > 0 && r.arch != "b64" {
210211
arch = r.arch
211212
}
212213
syscallTable, ok := auparse.AuditSyscalls[arch]

rule/rule_integ_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
// +build linux,amd64
19+
1820
package rule_test
1921

2022
import (

rule/rule_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func TestAddFilter(t *testing.T) {
362362
}
363363
assert.EqualValues(t, arg3Field, rule.fields[0])
364364
assert.EqualValues(t, equalOperator, rule.fieldFlags[0])
365-
assert.EqualValues(t, math.MaxUint32, rule.values[0])
365+
assert.EqualValues(t, uint32(math.MaxUint32), rule.values[0])
366366
})
367367

368368
t.Run("arg_min_int32", func(t *testing.T) {

0 commit comments

Comments
 (0)