Skip to contentSkip to conversation

selinux: add netlink nlmsg_type audit message

PATCH Applied Thiébaud Weksteen 2 participants 4 messages Dec 5, 2024 – Dec 16, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selinux: add netlink nlmsg_type audit message

Add a new audit message type to capture nlmsg-related information. This is similar to LSM_AUDIT_DATA_IOCTL_OP which was added for the other SELinux extended permission (ioctl).

Adding a new type is preferred to adding to the existing lsm_network_audit structure which contains irrelevant information for the netlink sockets (i.e., dport, sport).

---
v2: Change printed field name from nlmsg_type to nlnk-msgtype

 include/linux/lsm_audit.h | 2 ++
 security/lsm_audit.c      | 3 +++
 security/selinux/hooks.c  | 4 ++--
 3 files changed, 7 insertions(+), 2 deletions(-)
include/linux/lsm_audit.h +2 -0
index 97a8b21eb033..69d2b7bc00ed 100644
@@ -77,6 +77,7 @@ struct common_audit_data {
 #define LSM_AUDIT_DATA_LOCKDOWN 15
 #define LSM_AUDIT_DATA_NOTIFICATION 16
 #define LSM_AUDIT_DATA_ANONINODE	17
+#define LSM_AUDIT_DATA_NLMSGTYPE	18
 	union 	{
 		struct path path;
 		struct dentry *dentry;
@@ -98,6 +99,7 @@ struct common_audit_data {
 		struct lsm_ibendport_audit *ibendport;
 		int reason;
 		const char *anonclass;
+		u16 nlmsg_type;
 	} u;
 	/* this union contains LSM specific data */
 	union {
security/lsm_audit.c +3 -0
index 9a8352972086..70444230e56f 100644
@@ -425,6 +425,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 	case LSM_AUDIT_DATA_ANONINODE:
 		audit_log_format(ab, " anonclass=%s", a->u.anonclass);
 		break;
+	case LSM_AUDIT_DATA_NLMSGTYPE:
+		audit_log_format(ab, " nlnk-msgtype=%hu", a->u.nlmsg_type);
+		break;
 	} /* switch (a->type) */
 }
 
security/selinux/hooks.c +2 -2
index f5a08f94e094..20ccd6ed5a75 100644
@@ -5939,14 +5939,14 @@ static int nlmsg_sock_has_extended_perms(struct sock *sk, u32 perms, u16 nlmsg_t
 {
 	struct sk_security_struct *sksec = sk->sk_security;
 	struct common_audit_data ad;
-	struct lsm_network_audit net;
 	u8 driver;
 	u8 xperm;
 
 	if (sock_skip_has_perm(sksec->sid))
 		return 0;
 
-	ad_net_init_from_sk(&ad, &net, sk);
+	ad.type = LSM_AUDIT_DATA_NLMSGTYPE;
+	ad.u.nlmsg_type = nlmsg_type;
 
 	driver = nlmsg_type >> 8;
 	xperm = nlmsg_type & 0xff;
Signature · 1 line
2.47.0.338.g60cca15819-goog
maintainer
#1 lore raw
Quoted 17 lines · Thiébaud Weksteen

Add a new audit message type to capture nlmsg-related information. This is similar to LSM_AUDIT_DATA_IOCTL_OP which was added for the other SELinux extended permission (ioctl).

Adding a new type is preferred to adding to the existing lsm_network_audit structure which contains irrelevant information for the netlink sockets (i.e., dport, sport).

---
v2: Change printed field name from nlmsg_type to nlnk-msgtype

 include/linux/lsm_audit.h | 2 ++
 security/lsm_audit.c      | 3 +++
 security/selinux/hooks.c  | 4 ++--
 3 files changed, 7 insertions(+), 2 deletions(-)

...

security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 430

Quoted 11 lines
security/lsm_audit.c +3 -0
index 9a8352972086..70444230e56f 100644
@@ -425,6 +425,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        case LSM_AUDIT_DATA_ANONINODE:
                audit_log_format(ab, " anonclass=%s", a->u.anonclass);
                break;
+       case LSM_AUDIT_DATA_NLMSGTYPE:
+               audit_log_format(ab, " nlnk-msgtype=%hu", a->u.nlmsg_type);
+               break;

See my follow-up reply to your v1 patch. Assuming no objections, I can change this to "nl-msgtype" when I merge the patch; is that okay with you?

Quoted 2 lines
security/lsm_audit.c +0 -0
        } /* switch (a->type) */
 }
Signature · 1 line
paul-moore.com
#2 lore raw
Quoted 22 lines · Paul Moore
Quoted 17 lines · Thiébaud Weksteen

Add a new audit message type to capture nlmsg-related information. This is similar to LSM_AUDIT_DATA_IOCTL_OP which was added for the other SELinux extended permission (ioctl).

Adding a new type is preferred to adding to the existing lsm_network_audit structure which contains irrelevant information for the netlink sockets (i.e., dport, sport).

---
v2: Change printed field name from nlmsg_type to nlnk-msgtype

 include/linux/lsm_audit.h | 2 ++
 security/lsm_audit.c      | 3 +++
 security/selinux/hooks.c  | 4 ++--
 3 files changed, 7 insertions(+), 2 deletions(-)

...

Quoted 15 lines

security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 430

Quoted 11 lines
security/lsm_audit.c +3 -0
index 9a8352972086..70444230e56f 100644
@@ -425,6 +425,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        case LSM_AUDIT_DATA_ANONINODE:
                audit_log_format(ab, " anonclass=%s", a->u.anonclass);
                break;
+       case LSM_AUDIT_DATA_NLMSGTYPE:
+               audit_log_format(ab, " nlnk-msgtype=%hu", a->u.nlmsg_type);
+               break;

See my follow-up reply to your v1 patch. Assuming no objections, I can change this to "nl-msgtype" when I merge the patch; is that okay with you?

Yes, please do. Thanks Paul.

maintainer Applied
#3 lore raw
Quoted 2 lines · Thiébaud Weksteen
Quoted 1 line · Paul Moore

On Wed, Dec 4, 2024 at 8:21 PM Thiébaud Weksteen <[email protected]> wrote:

...

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
security/lsm_audit.c +0 -0
index 9a8352972086..70444230e56f 100644
@@ -425,6 +425,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        case LSM_AUDIT_DATA_ANONINODE:
                audit_log_format(ab, " anonclass=%s", a->u.anonclass);
Quoted 8 lines

security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 430

Quoted 4 lines
security/lsm_audit.c +3 -0
                break;
+       case LSM_AUDIT_DATA_NLMSGTYPE:
+               audit_log_format(ab, " nlnk-msgtype=%hu", a->u.nlmsg_type);
+               break;

See my follow-up reply to your v1 patch. Assuming no objections, I can change this to "nl-msgtype" when I merge the patch; is that okay with you?

Quoted 1 line

Yes, please do. Thanks Paul.

Merged into selinux/dev, thanks!

Signature · 1 line
paul-moore.com