Skip to contentSkip to conversation

audit: allow other filter list types for AUDIT_EXE

PATCH In review Ondrej Mosnacek 3 participants 5 messages Apr 25, 2018 – May 2, 2018 Audit

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 audit: allow other filter list types for AUDIT_EXE

This patch removes the restriction of the AUDIT_EXE field to only SYSCALL filter and teaches audit_filter to recognize this field.

This makes it possible to write rule lists such as:

auditctl -a exit,always [some general rule]
# Filter out events with executable name /bin/exe1 or /bin/exe2:
auditctl -a exclude,always -F exe=/bin/exe1
auditctl -a exclude,always -F exe=/bin/exe2

See: https://github.com/linux-audit/audit-kernel/issues/54

---
 kernel/auditfilter.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/auditfilter.c +5 -2
index a0c5a3ec6e60..8c9abbf20d42 100644
@@ -428,8 +428,6 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
 	case AUDIT_EXE:
 		if (f->op != Audit_not_equal && f->op != Audit_equal)
 			return -EINVAL;
-		if (entry->rule.listnr != AUDIT_FILTER_EXIT)
-			return -EINVAL;
 		break;
 	}
 	return 0;
@@ -1362,6 +1360,11 @@ int audit_filter(int msgtype, unsigned int listtype)
 							f->type, f->op, f->lsm_rule, NULL);
 				}
 				break;
+			case AUDIT_EXE:
+				result = audit_exe_compare(current, e->rule.exe);
+				if (f->op == Audit_not_equal)
+					result = !result;
+				break;
 			default:
 				goto unlock_and_return;
 			}
Signature · 1 line
2.14.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Ondrej Mosnacek

This patch removes the restriction of the AUDIT_EXE field to only SYSCALL filter and teaches audit_filter to recognize this field.

This makes it possible to write rule lists such as:

auditctl -a exit,always [some general rule]
# Filter out events with executable name /bin/exe1 or /bin/exe2:
auditctl -a exclude,always -F exe=/bin/exe1
auditctl -a exclude,always -F exe=/bin/exe2

See: https://github.com/linux-audit/audit-kernel/issues/54

---
 kernel/auditfilter.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/auditfilter.c +0 -0
index a0c5a3ec6e60..8c9abbf20d42 100644

kernel/auditfilter.c static int audit_field_valid(struct audit_entry *entry, struct audit_field *f) · line 432

Quoted 5 lines
kernel/auditfilter.c +0 -2
@@ -428,8 +428,6 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
 	case AUDIT_EXE:
 		if (f->op != Audit_not_equal && f->op != Audit_equal)
 			return -EINVAL;
-		if (entry->rule.listnr != AUDIT_FILTER_EXIT)
-			return -EINVAL;

This looks right since the FS filter will throw its own error in higher in that function. (The ENTRY and WATCH filters are gone.)

Quoted 5 lines
kernel/auditfilter.c +0 -0
 		break;
 	}
 	return 0;
@@ -1362,6 +1360,11 @@ int audit_filter(int msgtype, unsigned int listtype)
 							f->type, f->op, f->lsm_rule, NULL);

kernel/auditfilter.c int audit_filter(int msgtype, unsigned int listtype) · line 1370

Quoted 10 lines
kernel/auditfilter.c +5 -0
 				}
 				break;
+			case AUDIT_EXE:
+				result = audit_exe_compare(current, e->rule.exe);
+				if (f->op == Audit_not_equal)
+					result = !result;
+				break;
 			default:
 				goto unlock_and_return;
 			}

- RGB

--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635

maintainer
#2 lore raw
In reply to Ondrej Mosnacek
Quoted 10 lines · Ondrej Mosnacek

This patch removes the restriction of the AUDIT_EXE field to only SYSCALL filter and teaches audit_filter to recognize this field.

This makes it possible to write rule lists such as:

auditctl -a exit,always [some general rule]
# Filter out events with executable name /bin/exe1 or /bin/exe2:
auditctl -a exclude,always -F exe=/bin/exe1
auditctl -a exclude,always -F exe=/bin/exe2

Quoted 6 lines

See: https://github.com/linux-audit/audit-kernel/issues/54

---
 kernel/auditfilter.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Looks reasonable, do you have a working test for this?

Quoted 28 lines
kernel/auditfilter.c +5 -3
index a0c5a3ec6e60..8c9abbf20d42 100644
@@ -428,8 +428,6 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
        case AUDIT_EXE:
                if (f->op != Audit_not_equal && f->op != Audit_equal)
                        return -EINVAL;
-               if (entry->rule.listnr != AUDIT_FILTER_EXIT)
-                       return -EINVAL;
                break;
        }
        return 0;
@@ -1362,6 +1360,11 @@ int audit_filter(int msgtype, unsigned int listtype)
                                                        f->type, f->op, f->lsm_rule, NULL);
                                }
                                break;
+                       case AUDIT_EXE:
+                               result = audit_exe_compare(current, e->rule.exe);
+                               if (f->op == Audit_not_equal)
+                                       result = !result;
+                               break;
                        default:
                                goto unlock_and_return;
                        }
--

2.14.3

Signature · 2 lines
paul moore
www.paul-moore.com
#3 lore raw

2018-05-01 22:06 GMT+02:00 Paul Moore <[email protected]>:

Quoted 11 lines · Ondrej Mosnacek
Quoted 10 lines

This patch removes the restriction of the AUDIT_EXE field to only SYSCALL filter and teaches audit_filter to recognize this field.

This makes it possible to write rule lists such as:

auditctl -a exit,always [some general rule]
# Filter out events with executable name /bin/exe1 or /bin/exe2:
auditctl -a exclude,always -F exe=/bin/exe1
auditctl -a exclude,always -F exe=/bin/exe2

Quoted 8 lines
Quoted 6 lines

See: https://github.com/linux-audit/audit-kernel/issues/54

---
 kernel/auditfilter.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Looks reasonable, do you have a working test for this?

Sure, I listed all the related patches (test suite and userspace) in the GHAK issue. Anyway, the testsuite patch can be found here:

https://github.com/linux-audit/audit-testsuite/pull/68

Quoted 35 lines
Quoted 27 lines
kernel/auditfilter.c +5 -3
index a0c5a3ec6e60..8c9abbf20d42 100644
@@ -428,8 +428,6 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
        case AUDIT_EXE:
                if (f->op != Audit_not_equal && f->op != Audit_equal)
                        return -EINVAL;
-               if (entry->rule.listnr != AUDIT_FILTER_EXIT)
-                       return -EINVAL;
                break;
        }
        return 0;
@@ -1362,6 +1360,11 @@ int audit_filter(int msgtype, unsigned int listtype)
                                                        f->type, f->op, f->lsm_rule, NULL);
                                }
                                break;
+                       case AUDIT_EXE:
+                               result = audit_exe_compare(current, e->rule.exe);
+                               if (f->op == Audit_not_equal)
+                                       result = !result;
+                               break;
                        default:
                                goto unlock_and_return;
                        }
--
Quoted 2 lines

2.14.3

--
paul moore
www.paul-moore.com

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Associate Software Engineer, Security Technologies
Red Hat, Inc.
maintainer
#4 lore raw
Quoted 19 lines · Ondrej Mosnacek

2018-05-01 22:06 GMT+02:00 Paul Moore <[email protected]>:

Quoted 18 lines · Ondrej Mosnacek
Quoted 16 lines

This patch removes the restriction of the AUDIT_EXE field to only SYSCALL filter and teaches audit_filter to recognize this field.

This makes it possible to write rule lists such as:

auditctl -a exit,always [some general rule]
# Filter out events with executable name /bin/exe1 or /bin/exe2:
auditctl -a exclude,always -F exe=/bin/exe1
auditctl -a exclude,always -F exe=/bin/exe2

See: https://github.com/linux-audit/audit-kernel/issues/54

---
 kernel/auditfilter.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 6 lines
Quoted 1 line

Looks reasonable, do you have a working test for this?

Sure, I listed all the related patches (test suite and userspace) in the GHAK issue. Anyway, the testsuite patch can be found here:

https://github.com/linux-audit/audit-testsuite/pull/68

Great, thanks. As soon as we get a verdict on the userspace portion from Steve I think we can merge this.

Quoted 41 lines
Quoted 26 lines
Quoted 26 lines
kernel/auditfilter.c +5 -3
index a0c5a3ec6e60..8c9abbf20d42 100644
@@ -428,8 +428,6 @@ static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
        case AUDIT_EXE:
                if (f->op != Audit_not_equal && f->op != Audit_equal)
                        return -EINVAL;
-               if (entry->rule.listnr != AUDIT_FILTER_EXIT)
-                       return -EINVAL;
                break;
        }
        return 0;
@@ -1362,6 +1360,11 @@ int audit_filter(int msgtype, unsigned int listtype)
                                                        f->type, f->op, f->lsm_rule, NULL);
                                }
                                break;
+                       case AUDIT_EXE:
+                               result = audit_exe_compare(current, e->rule.exe);
+                               if (f->op == Audit_not_equal)
+                                       result = !result;
+                               break;
                        default:
                                goto unlock_and_return;
                        }
--
Quoted 8 lines
Quoted 2 lines

2.14.3

--
paul moore
www.paul-moore.com

--
Ondrej Mosnacek <omosnace at redhat dot com> Associate Software Engineer, Security Technologies Red Hat, Inc.

Signature · 2 lines
paul moore
www.paul-moore.com