@@ -1530,20 +1530,60 @@ static void audit_receive(struct sk_buff *skb)
1530
1530
audit_ctl_unlock ();
1531
1531
}
1532
1532
1533
+ /* Log information about who is connecting to the audit multicast socket */
1534
+ static void audit_log_multicast (int group , const char * op , int err )
1535
+ {
1536
+ const struct cred * cred ;
1537
+ struct tty_struct * tty ;
1538
+ char comm [sizeof (current -> comm )];
1539
+ struct audit_buffer * ab ;
1540
+
1541
+ if (!audit_enabled )
1542
+ return ;
1543
+
1544
+ ab = audit_log_start (audit_context (), GFP_KERNEL , AUDIT_EVENT_LISTENER );
1545
+ if (!ab )
1546
+ return ;
1547
+
1548
+ cred = current_cred ();
1549
+ tty = audit_get_tty ();
1550
+ audit_log_format (ab , "pid=%u uid=%u auid=%u tty=%s ses=%u" ,
1551
+ task_pid_nr (current ),
1552
+ from_kuid (& init_user_ns , cred -> uid ),
1553
+ from_kuid (& init_user_ns , audit_get_loginuid (current )),
1554
+ tty ? tty_name (tty ) : "(none)" ,
1555
+ audit_get_sessionid (current ));
1556
+ audit_put_tty (tty );
1557
+ audit_log_task_context (ab ); /* subj= */
1558
+ audit_log_format (ab , " comm=" );
1559
+ audit_log_untrustedstring (ab , get_task_comm (comm , current ));
1560
+ audit_log_d_path_exe (ab , current -> mm ); /* exe= */
1561
+ audit_log_format (ab , " nl-mcgrp=%d op=%s res=%d" , group , op , !err );
1562
+ audit_log_end (ab );
1563
+ }
1564
+
1533
1565
/* Run custom bind function on netlink socket group connect or bind requests. */
1534
- static int audit_bind (struct net * net , int group )
1566
+ static int audit_multicast_bind (struct net * net , int group )
1535
1567
{
1568
+ int err = 0 ;
1569
+
1536
1570
if (!capable (CAP_AUDIT_READ ))
1537
- return - EPERM ;
1571
+ err = - EPERM ;
1572
+ audit_log_multicast (group , "connect" , err );
1573
+ return err ;
1574
+ }
1538
1575
1539
- return 0 ;
1576
+ static void audit_multicast_unbind (struct net * net , int group )
1577
+ {
1578
+ audit_log_multicast (group , "disconnect" , 0 );
1540
1579
}
1541
1580
1542
1581
static int __net_init audit_net_init (struct net * net )
1543
1582
{
1544
1583
struct netlink_kernel_cfg cfg = {
1545
1584
.input = audit_receive ,
1546
- .bind = audit_bind ,
1585
+ .bind = audit_multicast_bind ,
1586
+ .unbind = audit_multicast_unbind ,
1547
1587
.flags = NL_CFG_F_NONROOT_RECV ,
1548
1588
.groups = AUDIT_NLGRP_MAX ,
1549
1589
};
0 commit comments