History

audit: report audit wait metric in audit status reply

In environments where the preservation of audit events and predictable usage of system memory are prioritized, admins may use a combination of --backlog_wait_time and -b options at the risk of degraded performance resulting from backlog waiting. In some cases, this risk may be preferred to lost events or unbounded memory usage. Ideally, this risk can be mitigated by making adjustments when backlog waiting is detected. However, detection can be difficult using the currently available metrics. For example, an admin attempting to debug degraded performance may falsely believe a full backlog indicates backlog waiting. It may turn out the backlog frequently fills up but drains quickly. To make it easier to reliably track degraded performance to backlog waiting, this patch makes the following changes: Add a new field backlog_wait_time_total to the audit status reply. Initialize this field to zero. Add to this field the total time spent by the current task on scheduled timeouts while the backlog limit is exceeded. Reset field to zero upon request via AUDIT_SET. Tested on Ubuntu 18.04 using complementary changes to the audit-userspace and audit-testsuite: - https://github.com/linux-audit/audit-userspace/pull/134 - https://github.com/linux-audit/audit-testsuite/pull/97

Max Englander committed 6 years ago

Commit b43870c1 parent f1d9b232 files · +36 −17Browse files

Unified · Split

2 files
  1. include/uapi/linux/audit.h +11 −7
  2. kernel/audit.c +25 −10
include/uapi/linux/audit.h+11−7
@@ -333,14 +333,15 @@ enum { · 332 unmodified lines
333};333};
334 334
335/* Status symbols */335/* Status symbols */
336 /* Mask values */336 /* Mask values */
337#define AUDIT_STATUS_ENABLED 0x0001337#define AUDIT_STATUS_ENABLED 0x0001
338#define AUDIT_STATUS_FAILURE 0x0002338#define AUDIT_STATUS_FAILURE 0x0002
339#define AUDIT_STATUS_PID 0x0004339#define AUDIT_STATUS_PID 0x0004
340#define AUDIT_STATUS_RATE_LIMIT 0x0008340#define AUDIT_STATUS_RATE_LIMIT 0x0008
341#define AUDIT_STATUS_BACKLOG_LIMIT 0x0010341#define AUDIT_STATUS_BACKLOG_LIMIT 0x0010
342#define AUDIT_STATUS_BACKLOG_WAIT_TIME 0x0020342#define AUDIT_STATUS_BACKLOG_WAIT_TIME 0x0020
343#define AUDIT_STATUS_LOST 0x0040343#define AUDIT_STATUS_LOST 0x0040
344#define AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL 0x0080
344 345
345#define AUDIT_FEATURE_BITMAP_BACKLOG_LIMIT 0x00000001346#define AUDIT_FEATURE_BITMAP_BACKLOG_LIMIT 0x00000001
346#define AUDIT_FEATURE_BITMAP_BACKLOG_WAIT_TIME 0x00000002347#define AUDIT_FEATURE_BITMAP_BACKLOG_WAIT_TIME 0x00000002
@@ -467,6 +468,9 @@ struct audit_status { · 120 unmodified lines
467 __u32 feature_bitmap; /* bitmap of kernel audit features */468 __u32 feature_bitmap; /* bitmap of kernel audit features */
468 };469 };
469 __u32 backlog_wait_time;/* message queue wait timeout */470 __u32 backlog_wait_time;/* message queue wait timeout */
471 __u32 backlog_wait_time_actual;/* time spent waiting while
472 * message limit exceeded
473 */
470};474};
471 475
472struct audit_features {476struct audit_features {
kernel/audit.c+25−10
@@ -136,6 +136,11 @@ u32 audit_sig_sid = 0; · 135 unmodified lines
136*/136*/
137static atomic_t audit_lost = ATOMIC_INIT(0);137static atomic_t audit_lost = ATOMIC_INIT(0);
138 138
139/* Monotonically increasing sum of time the kernel has spent
140 * waiting while the backlog limit is exceeded.
141 */
142static atomic_t audit_backlog_wait_time_actual = ATOMIC_INIT(0);
143
139/* Hash for inode-based rules */144/* Hash for inode-based rules */
140struct list_head audit_inode_hash[AUDIT_INODE_BUCKETS];145struct list_head audit_inode_hash[AUDIT_INODE_BUCKETS];
141 146
@@ -1201,17 +1206,18 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · 1059 unmodified lines
1201 case AUDIT_GET: {1206 case AUDIT_GET: {
1202 struct audit_status s;1207 struct audit_status s;
1203 memset(&s, 0, sizeof(s));1208 memset(&s, 0, sizeof(s));
1204 s.enabled = audit_enabled;1209 s.enabled = audit_enabled;
1205 s.failure = audit_failure;1210 s.failure = audit_failure;
1206 /* NOTE: use pid_vnr() so the PID is relative to the current1211 /* NOTE: use pid_vnr() so the PID is relative to the current
1207 * namespace */1212 * namespace */
1208 s.pid = auditd_pid_vnr();1213 s.pid = auditd_pid_vnr();
1209 s.rate_limit = audit_rate_limit;1214 s.rate_limit = audit_rate_limit;
1210 s.backlog_limit = audit_backlog_limit;1215 s.backlog_limit = audit_backlog_limit;
1211 s.lost = atomic_read(&audit_lost);1216 s.lost = atomic_read(&audit_lost);
1212 s.backlog = skb_queue_len(&audit_queue);1217 s.backlog = skb_queue_len(&audit_queue);
1213 s.feature_bitmap = AUDIT_FEATURE_BITMAP_ALL;1218 s.feature_bitmap = AUDIT_FEATURE_BITMAP_ALL;
1214 s.backlog_wait_time = audit_backlog_wait_time;1219 s.backlog_wait_time = audit_backlog_wait_time;
1220 s.backlog_wait_time_actual = atomic_read(&audit_backlog_wait_time_actual);
1215 audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &s, sizeof(s));1221 audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &s, sizeof(s));
1216 break;1222 break;
1217 }1223 }
@@ -1315,6 +1321,12 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · 97 unmodified lines
1315 audit_log_config_change("lost", 0, lost, 1);1321 audit_log_config_change("lost", 0, lost, 1);
1316 return lost;1322 return lost;
1317 }1323 }
1324 if (s.mask == AUDIT_STATUS_BACKLOG_WAIT_TIME_ACTUAL) {
1325 u32 actual = atomic_xchg(&audit_backlog_wait_time_actual, 0);
1326
1327 audit_log_config_change("backlog_wait_time_actual", 0, actual, 1);
1328 return actual;
1329 }
1318 break;1330 break;
1319 }1331 }
1320 case AUDIT_GET_FEATURE:1332 case AUDIT_GET_FEATURE:
@@ -1826,12 +1838,15 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, · 505 unmodified lines
1826 /* sleep if we are allowed and we haven't exhausted our1838 /* sleep if we are allowed and we haven't exhausted our
1827 * backlog wait limit */1839 * backlog wait limit */
1828 if (gfpflags_allow_blocking(gfp_mask) && (stime > 0)) {1840 if (gfpflags_allow_blocking(gfp_mask) && (stime > 0)) {
1841 long rtime = stime;
1842
1829 DECLARE_WAITQUEUE(wait, current);1843 DECLARE_WAITQUEUE(wait, current);
1830 1844
1831 add_wait_queue_exclusive(&audit_backlog_wait,1845 add_wait_queue_exclusive(&audit_backlog_wait,
1832 &wait);1846 &wait);
1833 set_current_state(TASK_UNINTERRUPTIBLE);1847 set_current_state(TASK_UNINTERRUPTIBLE);
1834 stime = schedule_timeout(stime);1848 stime = schedule_timeout(rtime);
1849 atomic_add(rtime - stime, &audit_backlog_wait_time_actual);
1835 remove_wait_queue(&audit_backlog_wait, &wait);1850 remove_wait_queue(&audit_backlog_wait, &wait);
1836 } else {1851 } else {
1837 if (audit_rate_check() && printk_ratelimit())1852 if (audit_rate_check() && printk_ratelimit())

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t