Skip to contentSkip to conversation

Add support for sessionid user filters, sessionid_set and loginuid_set

PATCH Superseded Richard Guy Briggs 2 participants 11 messages Aug 2, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add support for sessionid user filters, sessionid_set and loginuid_set

Add support for sessionid, sessionid_set (first two patches) and loginuid_set (and auid_set) (third patch) in user filters. The first two are directly related to issue "ghak4":
https://github.com/linux-audit/audit-kernel/issues/4
https://github.com/linux-audit/audit-kernel/wiki/RFE-Session-ID-User-Filter

The third is to support a kernel change from 3.10 and 3.19 to avoid using in-band values to indicate the loginuid is unset.

The last two patches are to add unset flags to sessionid and loginuid for ausearch and aureport. These two patches are extras and not required for basic support.

Richard Guy Briggs (5):
Add userspace support for session ID user filter.
Add sessionid_set option from kernel uapi macro AUDIT_SESSIONID_SET Add user filter option loginuid_set from uapi macro AUDIT_LOGINUID_SET Add sessionid_set option to ausearch and aureport
Add support for loginuid_set option for event filtering and searches.

 trunk/lib/fieldtab.h         |    4 ++
 trunk/src/aureport-options.c |    4 +-
 trunk/src/ausearch-common.h  |    1 +
 trunk/src/ausearch-match.c   |    3 +
 trunk/src/ausearch-options.c |   85 +++++++++++++++++++++++++++++++++++++++++-
 trunk/src/ausearch-options.h |    1 +
 trunk/src/ausearch-parse.c   |   30 +++++++-------
 7 files changed, 110 insertions(+), 18 deletions(-)
#1 lore raw

PATCH 1/5 Add userspace support for session ID user filter.

Add support for the session ID user filter by adding the field name "sessionid" using the kernel defined macro value AUDIT_SESSIONID.

https://github.com/linux-audit/audit-kernel/issues/4
RFE: add a session ID filter to the kernel's user filter

---
 trunk/lib/fieldtab.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
trunk/lib/fieldtab.h +1 -0
index bf48c95..88cf8ea 100644
@@ -31,6 +31,7 @@ _S(AUDIT_SGID,         "sgid"         )
 _S(AUDIT_FSGID,        "fsgid"        )
 _S(AUDIT_LOGINUID,     "auid"         )
 _S(AUDIT_LOGINUID,     "loginuid"     )
+_S(AUDIT_SESSIONID,    "sessionid"    )
 _S(AUDIT_PERS,         "pers"         )
 _S(AUDIT_ARCH,         "arch"         )
 _S(AUDIT_MSGTYPE,      "msgtype"      )
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/5 Add sessionid_set option from kernel uapi macro AUDIT_SESSIONID_SET

In reply to Richard Guy Briggs

Add sessionid_set field option from kernel uapi macro SESSIONID_SET to enable specifying that sessionID is set or not in user filters.

---
 trunk/lib/fieldtab.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
trunk/lib/fieldtab.h +1 -0
index 88cf8ea..b7b9f51 100644
@@ -32,6 +32,7 @@ _S(AUDIT_FSGID,        "fsgid"        )
 _S(AUDIT_LOGINUID,     "auid"         )
 _S(AUDIT_LOGINUID,     "loginuid"     )
 _S(AUDIT_SESSIONID,    "sessionid"    )
+_S(AUDIT_SESSIONID_SET,"sessionid_set")
 _S(AUDIT_PERS,         "pers"         )
 _S(AUDIT_ARCH,         "arch"         )
 _S(AUDIT_MSGTYPE,      "msgtype"      )
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/5 Add user filter option loginuid_set from uapi macro AUDIT_LOGINUID_SET

In reply to Richard Guy Briggs

See upstream kernel commits:

	780a7654cee8d61819512385e778e4827db4bfbc (3.10.rc1)
		(audit: Make testing for a valid loginuid explicit.)
	041d7b98ffe59c59fdd639931dea7d74f9aa9a59 (3.19.rc2)
		(audit: restore AUDIT_LOGINUID unset ABI)
---
 trunk/lib/fieldtab.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
trunk/lib/fieldtab.h +2 -0
index b7b9f51..eeb951e 100644
@@ -31,6 +31,8 @@ _S(AUDIT_SGID,         "sgid"         )
 _S(AUDIT_FSGID,        "fsgid"        )
 _S(AUDIT_LOGINUID,     "auid"         )
 _S(AUDIT_LOGINUID,     "loginuid"     )
+_S(AUDIT_LOGINUID_SET, "auid_set"     )
+_S(AUDIT_LOGINUID_SET, "loginuid_set" )
 _S(AUDIT_SESSIONID,    "sessionid"    )
 _S(AUDIT_SESSIONID_SET,"sessionid_set")
 _S(AUDIT_PERS,         "pers"         )
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/5 Add sessionid_set option to ausearch and aureport

In reply to Richard Guy Briggs
---
 trunk/src/aureport-options.c |    3 ++-
 trunk/src/ausearch-match.c   |    3 +++
 trunk/src/ausearch-options.c |   42 +++++++++++++++++++++++++++++++++++++++++-
 trunk/src/ausearch-options.h |    1 +
 trunk/src/ausearch-parse.c   |   14 +++++++-------
 5 files changed, 54 insertions(+), 9 deletions(-)
trunk/src/aureport-options.c +2 -1
index 9a0fc18..b15cbb5 100644
@@ -59,7 +59,7 @@ const char *event_uuid = NULL;
 const char *event_vmname = NULL;
 long long event_exit = 0;
 int event_exit_is_set = 0;
-int event_ppid = -1, event_session_id = -2;
+int event_ppid = -1, event_session_id = -2, event_session_id_set = -1;
 int event_debug = 0, event_machine = -1;
 
 /* These are used by aureport */
@@ -565,6 +565,7 @@ int check_params(int count, char *vars[])
 			else {
 				set_detail(D_DETAILED);
 				event_session_id = 1;
+				event_session_id_set = 1;
 				event_loginuid = 1;
 				event_tauid = dummy;
 				event_terminal = dummy;
trunk/src/ausearch-match.c +3 -0
index ec8a582..bff7e24 100644
@@ -112,6 +112,9 @@ int match(llist *l)
 				if ((event_session_id != -2) &&
 					(event_session_id != l->s.session_id))
 					return 0;
+				if ((event_session_id_set != -1) &&
+					(event_session_id_set != (l->s.session_id != -1)))
+					return 0;
 				if (event_exit_is_set) {
 					if (l->s.exit_is_set == 0)
 						return 0;
trunk/src/ausearch-options.c +41 -1

72 lines not on this page · raw message

trunk/src/ausearch-options.h +1 -0
index 1372762..947f5d6 100644
@@ -40,6 +40,7 @@ extern int line_buffered;
 extern int event_debug;
 extern pid_t event_ppid;
 extern uint32_t event_session_id;
+extern uint32_t event_session_id_set;
 extern ilist *event_type;
 
 /* Data type to govern output format */
trunk/src/ausearch-parse.c +7 -7
index 3047925..c45d54e 100644
@@ -357,7 +357,7 @@ static int parse_task_info(lnode *n, search_items *s)
 		}
 	}
 	// ses
-	if (event_session_id != -2 ) {
+	if (event_session_id != -2 || event_session_id_set != -1) {
 		str = strstr(term, "ses=");
 		if (str) {
 			ptr = str + 4;
@@ -845,7 +845,7 @@ static int parse_user(const lnode *n, search_items *s)
 		s->tauid = lookup_uid("auid", s->loginuid);
 	}
 	// ses
-	if (event_session_id != -2 ) {
+	if (event_session_id != -2 || event_session_id_set != -1) {
 		str = strstr(term, "ses=");
 		if (str) {
 			ptr = str + 4;
@@ -1317,7 +1317,7 @@ static int parse_login(const lnode *n, search_items *s)
 			s->success = S_SUCCESS; 
 	}
 	// ses
-	if (event_session_id != -2 ) {
+	if (event_session_id != -2 || event_session_id_set != -1) {
 		if (term == NULL)
 			term = n->message;
 		str = strstr(term, "new ses=");
@@ -1631,7 +1631,7 @@ static int parse_integrity(const lnode *n, search_items *s)
 	}
 
 	// ses
-	if (event_session_id != -2 ) {
+	if (event_session_id != -2 || event_session_id_set != -1) {
 		str = strstr(term, "ses=");
 		if (str) {
 			ptr = str + 4;
@@ -1944,7 +1944,7 @@ static int parse_kernel_anom(const lnode *n, search_items *s)
 		}
 	}
 
-	if (event_session_id != -2) {
+	if (event_session_id != -2 || event_session_id_set != -1) {
 		str = strstr(term, "ses=");
 		if (str) {
 			ptr = str + 4;
@@ -2100,7 +2100,7 @@ static int parse_simple_message(const lnode *n, search_items *s)
 	}
 
 	// ses
-	if (event_session_id != -2 ) {
+	if (event_session_id != -2 || event_session_id_set != -1) {
 		str = strstr(term, "ses=");
 		if (str) {
 			ptr = str + 4;
@@ -2277,7 +2277,7 @@ static int parse_tty(const lnode *n, search_items *s)
 	}
 
 	// ses
-	if (event_session_id != -2 ) {
+	if (event_session_id != -2 || event_session_id_set != -1) {
 		str = strstr(term, "ses=");
 		if (str) {
 			ptr = str + 4;
Signature · 1 line
1.7.1
#5 lore raw

PATCH 5/5 Add support for loginuid_set option for event filtering and searches.

In reply to Richard Guy Briggs
---
 trunk/src/aureport-options.c |    1 +
 trunk/src/ausearch-common.h  |    1 +
 trunk/src/ausearch-options.c |   43 +++++++++++++++++++++++++++++++++++++++++-
 trunk/src/ausearch-parse.c   |   16 +++++++-------
 4 files changed, 52 insertions(+), 9 deletions(-)
trunk/src/aureport-options.c +1 -0
index b15cbb5..a0c78ea 100644
@@ -44,6 +44,7 @@ int no_config = 0;
 /* These are for compatibility with parser */
 unsigned int event_id = -1;
 uid_t event_uid = -1, event_loginuid = -2, event_euid = -1;
+int event_loginuid_set = -1;
 const char *event_tuid = NULL, *event_teuid = NULL, *event_tauid = NULL;
 gid_t event_gid = -1, event_egid = -1;
 slist *event_node_list = NULL;
trunk/src/ausearch-common.h +1 -0
index d60ea5f..cdb51e9 100644
@@ -48,6 +48,7 @@ extern gid_t event_gid, event_egid;
 extern pid_t event_pid;
 extern int event_exact_match;
 extern uid_t event_uid, event_euid, event_loginuid;
+extern int event_loginuid_set;
 extern const char *event_tuid, *event_teuid, *event_tauid;
 slist *event_node_list;
 extern const char *event_comm;
trunk/src/ausearch-options.c +42 -1

73 lines not on this page · raw message

trunk/src/ausearch-parse.c +8 -8
index c45d54e..a489d25 100644
@@ -251,7 +251,7 @@ static int parse_task_info(lnode *n, search_items *s)
 		*term = ' ';
 	}
 	// optionally get loginuid
-	if (event_loginuid != -2 || event_tauid) {
+	if (event_loginuid != -2 || event_tauid || event_loginuid_set != -1) {
 		str = strstr(term, "auid=");
 		if (str == NULL) {
 			str = strstr(term, "loginuid=");
@@ -823,7 +823,7 @@ static int parse_user(const lnode *n, search_items *s)
 		s->tuid = lookup_uid("uid", s->uid);
 	}
 	// optionally get loginuid
-	if (event_loginuid != -2 || event_tauid) {
+	if (event_loginuid != -2 || event_tauid || event_loginuid_set != -1) {
 		*term = ' ';
 		str = strstr(term, "auid=");
 		if (str == NULL) { // Try the older one
@@ -1271,7 +1271,7 @@ static int parse_login(const lnode *n, search_items *s)
 		}
 	}
 	// optionally get loginuid
-	if (event_loginuid != -2 || event_tauid) {
+	if (event_loginuid != -2 || event_tauid || event_loginuid_set != -1) {
 		str = strstr(term, "new auid=");
 		if (str == NULL) {
 			// 3.14 kernel changed it to the next line
@@ -1354,7 +1354,7 @@ static int parse_daemon1(const lnode *n, search_items *s)
 	term = mptr;
 
 	// optionally get auid
-	if (event_loginuid != -2 || event_tauid) {
+	if (event_loginuid != -2 || event_tauid || event_loginuid_set != -1) {
 		str = strstr(mptr, "auid=");
 		if (str == NULL)
 			return 1;
@@ -1613,7 +1613,7 @@ static int parse_integrity(const lnode *n, search_items *s)
 	}
 
 	// optionally get loginuid
-	if (event_loginuid != -2 || event_tauid) {
+	if (event_loginuid != -2 || event_tauid || event_loginuid_set != -1) {
 		str = strstr(n->message, "auid=");
 		if (str) {
 			ptr = str + 5;
@@ -1890,7 +1890,7 @@ static int parse_kernel_anom(const lnode *n, search_items *s)
 	char *str, *ptr, *term = n->message;
 
 	// optionally get loginuid
-	if (event_loginuid != -2 || event_tauid) {
+	if (event_loginuid != -2 || event_tauid || event_loginuid_set != -1) {
 		str = strstr(term, "auid=");
 		if (str == NULL)
 			return 1;
@@ -2078,7 +2078,7 @@ static int parse_simple_message(const lnode *n, search_items *s)
 	char *str, *ptr, *term = n->message;
 
 	// optionally get loginuid - old kernels skip auid for CONFIG_CHANGE
-	if (event_loginuid != -2 || event_tauid) {
+	if (event_loginuid != -2 || event_tauid || event_loginuid_set != -1) {
 		str = strstr(term, "auid=");
 		if (str == NULL && n->type != AUDIT_CONFIG_CHANGE)
 			return 1;
@@ -2257,7 +2257,7 @@ static int parse_tty(const lnode *n, search_items *s)
 	}
 
 	// optionally get loginuid
-	if (event_loginuid != -2 || event_tauid) {
+	if (event_loginuid != -2 || event_tauid || event_loginuid_set != -1) {
 		str = strstr(term, "auid=");
 		if (str == NULL)
 			return 5;
Signature · 1 line
1.7.1
#6 lore raw
In reply to Richard Guy Briggs
Quoted 9 lines · EDT Richard Guy Briggs

Add support for sessionid, sessionid_set (first two patches) and loginuid_set (and auid_set) (third patch) in user filters. The first two are directly related to issue "ghak4":
https://github.com/linux-audit/audit-kernel/issues/4
https://github.com/linux-audit/audit-kernel/wiki/RFE-Session-ID-User
-Filter

The third is to support a kernel change from 3.10 and 3.19 to avoid using in-band values to indicate the loginuid is unset.

Have the above three patches been tested on old kernels?

Quoted 3 lines

The last two patches are to add unset flags to sessionid and loginuid for ausearch and aureport. These two patches are extras and not required for basic support.

I don't understand what the point of these last two items are. If the session is not set, we have ses=4294967295 in the audit trail. That can already be specified in ausearch as --session -1. I also am not sure that session information makes any sense for aureport because we have aulast which reports on session activity for users.

-Steve

#7 lore raw
Quoted 8 lines · Steve Grubb
Quoted 7 lines · EDT Richard Guy Briggs

Add support for sessionid, sessionid_set (first two patches) and loginuid_set (and auid_set) (third patch) in user filters. The first two are directly related to issue "ghak4":
https://github.com/linux-audit/audit-kernel/issues/4
https://github.com/linux-audit/audit-kernel/wiki/RFE-Session-ID-User
-Filter

Quoted 4 lines
Quoted 2 lines

The third is to support a kernel change from 3.10 and 3.19 to avoid using in-band values to indicate the loginuid is unset.

Have the above three patches been tested on old kernels?

Not yet. How do you usually add new features to userspace to guard against missing features from old kernels? Time to add a bit to the kenrel audit status feature field?

Quoted 9 lines
Quoted 3 lines

The last two patches are to add unset flags to sessionid and loginuid for ausearch and aureport. These two patches are extras and not required for basic support.

I don't understand what the point of these last two items are. If the session is not set, we have ses=4294967295 in the audit trail. That can already be specified in ausearch as --session -1. I also am not sure that session information makes any sense for aureport because we have aulast which reports on session activity for users.

I was starting to doubt the utility of these last two patches which is why I tagged them optional. Please use any bits or ideas that might be useful, otherwise drop them.

Quoted 1 line

-Steve

- RGB

--
Richard Guy Briggs <[email protected]>
Kernel Security Engineering, Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635

#8 lore raw
Quoted 9 lines · EDT Richard Guy Briggs
Quoted 8 lines · Steve Grubb
Quoted 7 lines · EDT Richard Guy Briggs

Add support for sessionid, sessionid_set (first two patches) and loginuid_set (and auid_set) (third patch) in user filters. The first

two are directly related to issue "ghak4":

        https://github.com/linux-audit/audit-kernel/issues/4
        https://github.com/linux-audit/audit-kernel/wiki/RFE-Session-ID-> > >         User-Filter
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

The third is to support a kernel change from 3.10 and 3.19 to avoid using in-band values to indicate the loginuid is unset.

Have the above three patches been tested on old kernels?

Not yet. How do you usually add new features to userspace to guard against missing features from old kernels? Time to add a bit to the kenrel audit status feature field?

Yes. Otherwise you get EINVAL which doesn't let you explain what exactly is wrong with the rule.

Thanks,
-Steve

Quoted 23 lines
Quoted 9 lines
Quoted 3 lines

The last two patches are to add unset flags to sessionid and loginuid for ausearch and aureport. These two patches are extras and not required for basic support.

I don't understand what the point of these last two items are. If the session is not set, we have ses=4294967295 in the audit trail. That can already be specified in ausearch as --session -1. I also am not sure that session information makes any sense for aureport because we have aulast which reports on session activity for users.

I was starting to doubt the utility of these last two patches which is why I tagged them optional. Please use any bits or ideas that might be useful, otherwise drop them.

Quoted 1 line

-Steve

- RGB

--
Richard Guy Briggs <[email protected]>
Kernel Security Engineering, Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635

#9 lore raw
Quoted 14 lines · EDT Steve Grubb
Quoted 13 lines · EDT Richard Guy Briggs
Quoted 12 lines · Steve Grubb
Quoted 10 lines · EDT Richard Guy Briggs

Add support for sessionid, sessionid_set (first two patches) and loginuid_set (and auid_set) (third patch) in user filters. The first

two are directly related to issue "ghak4":
https://github.com/linux-audit/audit-kernel/issues/4
https://github.com/linux-audit/audit-kernel/wiki/RFE-Session-ID-> >

Quoted 1 line

User-Filter

The third is to support a kernel change from 3.10 and 3.19 to avoid using in-band values to indicate the loginuid is unset.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Have the above three patches been tested on old kernels?

Not yet. How do you usually add new features to userspace to guard against missing features from old kernels? Time to add a bit to the kenrel audit status feature field?

Yes. Otherwise you get EINVAL which doesn't let you explain what exactly is wrong with the rule.

Before you get too far...I just looked at the support being added in the first three patches. There is no code changing auditctl. Is there something missing?

-Steve

#10 lore raw
Quoted 21 lines · Steve Grubb
Quoted 20 lines · EDT Steve Grubb
Quoted 18 lines · EDT Richard Guy Briggs
Quoted 7 lines · Steve Grubb
Quoted 6 lines · EDT Richard Guy Briggs

Add support for sessionid, sessionid_set (first two patches) and loginuid_set (and auid_set) (third patch) in user filters. The first

two are directly related to issue "ghak4":
https://github.com/linux-audit/audit-kernel/issues/4
https://github.com/linux-audit/audit-kernel/wiki/RFE-Session-ID-> >

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

User-Filter

The third is to support a kernel change from 3.10 and 3.19 to avoid using in-band values to indicate the loginuid is unset.

Have the above three patches been tested on old kernels?

Not yet. How do you usually add new features to userspace to guard against missing features from old kernels? Time to add a bit to the kenrel audit status feature field?

Quoted 5 lines
Quoted 2 lines

Yes. Otherwise you get EINVAL which doesn't let you explain what exactly is wrong with the rule.

Before you get too far...I just looked at the support being added in the first three patches. There is no code changing auditctl. Is there something missing?

I am pretty sure I looked through auditctl and in the three cases things were simple enough that the fallthrough case was sufficient. Now that I think about it, to avoid the ambiguity of -EINVAL, restricting the first to a positive value and the 2nd and 3rd to true or false would remove that ambiguity.

Quoted 1 line

-Steve

- RGB

--
Richard Guy Briggs <[email protected]>
Kernel Security Engineering, Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635