为什么我在 EC2 Linux 实例的屏幕截图和系统日志中看到“审计:超出积压限制”错误,我该如何避免这种情况?

3 分钟阅读
0

我在 Amazon Elastic Compute Cloud (Amazon EC2) Linux 实例的屏幕截图和系统日志中看到“已阻止审计回调”和“审计:超出积压限制”错误消息。为什么我会收到这些消息,以及如何防止它们再次发生?

简短描述

Linux 系统中的审计积压缓冲区是操作系统用来维护或记录审计事件的内核级套接字缓冲区队列。当新的审计事件触发时,系统会记录该事件并将其添加到审计积压缓冲区队列中。

backlog_limit 参数值是审计积压缓冲区的数量。默认情况下,参数设置为 320,如以下示例所示:

# auditctl -s
enabled 1
failure 1
pid 2264
rate_limit 0
backlog_limit 320
lost 0
backlog 0

当记录的审计事件超出默认数量 320 时,将导致实例上出现以下错误:

audit: audit_backlog=321 > audit_backlog_limit=320 

audit: audit_lost=44393 audit_rate_limit=0 audit_backlog_limit=320 

audit: backlog limit exceeded

– 或 –

audit_printk_skb: 153 callbacks suppressed

audit_printk_skb: 114 callbacks suppressed

达到或超出容量的审计缓冲区队列也可能导致实例锁定或保持无响应状态。

为避免出现超出积压限制错误,请增加 backlog_limit 参数值。大型服务器会触发大量审计日志,因此增加缓冲区空间有助于避免出现错误消息。

**注意:**增加审计缓冲区会消耗实例的更多内存。设置 backlog_limit 参数的大小取决于实例的总内存。如果系统有足够的内存,则可以尝试将现有的 backlog_limit 参数值加倍。

以下是审计积压所需内存的计算公式。使用此计算公式来确定在不对实例造成内存压力的情况下可以设置多大的积压队列。

一个审计缓冲区 = 8970 字节
审计缓冲区的默认数量(backlog_limit 参数)= 320
320 * 8970 = 2870400 字节或 2.7MiB

审计缓冲区的大小由 MAX_AUDIT_MESSAGE_LENGTH 参数定义。有关更多信息,请参阅 github.com 上的 Linux 审计库中的 MAX_AUDIT_MESSAGE_LENGTH

注意:如果您的实例不可访问,并且在系统日志中看到超出积压限制消息,请停止并启动该实例。然后,执行以下步骤以更改审计缓冲区值。

解决方法

**注意:**在本示例中,我们将 backlog_limit 参数值更改为 8192 个缓冲区。根据上述计算公式,8192 个缓冲区等于 70MiB 内存。您可以根据内存计算公式使用任何值。

1.使用 SSH 访问实例。

2.验证当前审计缓冲区大小。

**注意:**backlog_limit 参数以 -b 形式列出。有关更多信息,请参阅 auditctl-man-page 上的 auditctl(8)

Amazon Linux 1 和其他未使用 systemd 的操作系统:

$ sudo cat /etc/audit/audit.rules
# This file contains the auditctl rules that are loaded
# whenever the audit daemon is started via the initscripts.
# The rules are simply the parameters that would be passed
# to auditctl.

# First rule - delete all
-D

# Increase the buffers to survive stress events.
# Make this bigger for busy systems
-b 320

# Disable system call auditing.
# Remove the following line if you need the auditing.
-a never,task

# Feel free to add below this line. See auditctl man page

Amazon Linux 2 和其他使用 systemd 的操作系统:

$ sudo cat /etc/audit/audit.rules
# This file is automatically generated from /etc/audit/rules.d
-D
-b 320
-f 1

3.使用编辑器(如 vi 编辑器)访问 audit.rules 文件:

Amazon Linux 1 和其他未使用 systemd 的操作系统:

$ sudo vi /etc/audit/audit.rules

Amazon Linux 2 和其他使用 systemd 的操作系统:

$ sudo vi /etc/audit/rules.d/audit.rules

4.将 -b 参数编辑为较大的值。以下示例将 -b 值更改为 8192

$ sudo cat /etc/audit/audit.rules
# This file contains the auditctl rules that are loaded
# whenever the audit daemon is started via the initscripts.
# The rules are simply the parameters that would be passed
# to auditctl.

# First rule - delete all
-D

# Increase the buffers to survive stress events.
# Make this bigger for busy systems
-b 8192

# Disable system call auditing.
# Remove the following line if you need the auditing.
-a never,task

# Feel free to add below this line. See auditctl man page

$ sudo auditctl -s
enabled 1
failure 1
pid 2264
rate_limit 0
backlog_limit 320
lost 0
backlog 0

5.重新启动 auditd 服务。新的 backlog_limit 值将生效。该值也会在 auditctl -s 中更新,如以下示例所示:

# sudo service auditd stop
Stopping auditd:                                           [  OK  ]
# sudo service auditd start
Starting auditd:                                           [  OK  ]
# auditctl -s
enabled 1
failure 1
pid 26823
rate_limit 0
backlog_limit 8192
lost 0
backlog 0

注意:如果您的实例不可访问,并且在系统日志中看到超出积压限制消息,请停止并启动该实例。然后,执行上述步骤以更改审计缓冲区值。


AWS 官方
AWS 官方已更新 4 年前