new file mode 100644
@@ -0,0 +1,148 @@
+{
+ "lsm return value: positive not allowed, return -EPERM",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, -EPERM),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "inode_permission",
+ .expected_attach_type = BPF_LSM_MAC,
+ .result = ACCEPT,
+},
+{
+ "lsm return value: positive not allowed, return zero",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "inode_permission",
+ .expected_attach_type = BPF_LSM_MAC,
+ .result = ACCEPT,
+},
+{
+ "lsm return value: positive not allowed, return one",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 1),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "inode_permission",
+ .expected_attach_type = BPF_LSM_MAC,
+ .errstr = "Invalid R0, cannot return positive value",
+ .result = REJECT,
+},
+{
+ "lsm return value: zero/positive not allowed, return -EPERM",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, -EPERM),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "inode_init_security",
+ .expected_attach_type = BPF_LSM_MAC,
+ .result = ACCEPT,
+},
+{
+ "lsm return value: zero/positive not allowed, return zero",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "inode_init_security",
+ .expected_attach_type = BPF_LSM_MAC,
+ .errstr = "Invalid R0, cannot return zero value",
+ .result = REJECT,
+},
+{
+ "lsm return value: zero/positive not allowed, return one",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 1),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "inode_init_security",
+ .expected_attach_type = BPF_LSM_MAC,
+ .errstr = "Invalid R0, cannot return positive value",
+ .result = REJECT,
+},
+{
+ "lsm return value: positive allowed, return one",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 1),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "getprocattr",
+ .expected_attach_type = BPF_LSM_MAC,
+ .result = ACCEPT,
+},
+{
+ "lsm return value: positive allowed, return two",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 2),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "getprocattr",
+ .expected_attach_type = BPF_LSM_MAC,
+ .result = ACCEPT,
+},
+{
+ "lsm return value: only one allowed, return one",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 1),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "audit_rule_match",
+ .expected_attach_type = BPF_LSM_MAC,
+ .result = ACCEPT,
+},
+{
+ "lsm return value: only one allowed, return two",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 2),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "audit_rule_match",
+ .expected_attach_type = BPF_LSM_MAC,
+ .errstr = "Invalid R0, can return only one as positive value",
+ .result = REJECT,
+},
+{
+ "lsm return value: negative not allowed, return -EPERM",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, -EPERM),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "vm_enough_memory",
+ .expected_attach_type = BPF_LSM_MAC,
+ .errstr = "Invalid R0, cannot return negative value",
+ .result = REJECT,
+},
+{
+ "lsm return value: negative not allowed, return zero",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "vm_enough_memory",
+ .expected_attach_type = BPF_LSM_MAC,
+ .result = ACCEPT,
+},
+{
+ "lsm return value: negative not allowed, return one",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 1),
+ BPF_EXIT_INSN(),
+ },
+ .prog_type = BPF_PROG_TYPE_LSM,
+ .kfunc = "vm_enough_memory",
+ .expected_attach_type = BPF_LSM_MAC,
+ .result = ACCEPT,
+},