From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BD9F4ADD90 for ; Mon, 11 May 2026 18:43:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778525036; cv=none; b=TTBOo0+TS15X775rqcGAzCRdSTZNllqn+vSwVK+ilXpbHu1X98T+y8l6HR+pzPvyAsUMhHvxd/HKQq+0tcMpwa11Nnd8/2+ZQhhd11eanMhBYwDqEE+ujrVXEoJnxNTx2wU1SShYDfyfXUEgjnL4CBh5PntgHgi0ESY07twf1Dw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778525036; c=relaxed/simple; bh=uHbYBiaVX6StCVS3mjmgpdx/r0kZ5jpDITVdz4K5N0U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ot+pFtOQAtYufIGa5qcqhSIynPsTDn80oR5BAiX2T4yiNsV0LUlux6JSZAeW6CSKy75WHqJGSX6Ozfk9kTGKeNH4PdNGcNsgsL4bi56llNRk3trHrsiinLkYQjuChk8fUMypmN+it9Kikpw7y9QYIEd0aetVbG7xUyYV1J6JnoM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TLkIgD5S; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TLkIgD5S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778525034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KVNlHnyH6Pi2wnbn/0P75oyyCBRiJQi88SIInmQq+gA=; b=TLkIgD5SZX4SD5UFPEDMtC15ZdowqRKBx+kIBAakAUddIeuaoWNUFO4sldBjFpQzMmc8vn OCPeqXKVDeiwMjvavAHORI//weziTb6FGvi08RiUdjuykUsIixboJgpS3EpHHFhIKJltMd 6+LhqHnew5F2NYIIj4OuhaneT8Prblo= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-LUXBaevYOlu4Gt4qEaKMjQ-1; Mon, 11 May 2026 14:43:50 -0400 X-MC-Unique: LUXBaevYOlu4Gt4qEaKMjQ-1 X-Mimecast-MFC-AGG-ID: LUXBaevYOlu4Gt4qEaKMjQ_1778525029 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8FA991800371; Mon, 11 May 2026 18:43:49 +0000 (UTC) Received: from wsxc.redhat.com (unknown [10.96.134.165]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 03EA518004A3; Mon, 11 May 2026 18:43:45 +0000 (UTC) From: Ricardo Robaina To: audit@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: paul@paul-moore.com, eparis@redhat.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, Ricardo Robaina , Steve Grubb Subject: [PATCH] netlink, audit: prevent false ENOBUFS on timeout expiry Date: Mon, 11 May 2026 15:43:38 -0300 Message-ID: <20260511184338.392420-1-rrobaina@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 When auditd is bottlenecked (e.g., by slow disk I/O), kauditd blocks on the netlink socket. If the wait timeout fully expires (timeo == 0), netlink mistakenly interprets the zeroed timeout as a non-blocking request. It then triggers netlink_overrun that drops the event, completely bypassing the audit subsystem's internal retry queue, and falsely returns ENOBUFS to user-space, resulting in the following error: auditd[]: Error receiving audit netlink packet (No buffer space available) Convert the `nonblock` argument in netlink_unicast() into a `flags` bitmask and introduce NETLINK_UNICAST_TIMED. When a caller specifies this flag and exhausts its timeout budget, netlink intercepts the zeroed timeo state. Instead of defaulting to an overrun condition, it safely frees the skb and returns -EAGAIN, allowing the audit subsystem to gracefully enqueue the pending event into its internal backlog. Suggested-by: Steve Grubb Signed-off-by: Ricardo Robaina --- include/linux/netlink.h | 5 ++++- kernel/audit.c | 8 ++++---- net/netlink/af_netlink.c | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/linux/netlink.h b/include/linux/netlink.h index 882e9c1b6c1d..1888c8ee416a 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -226,7 +226,10 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err, int netlink_has_listeners(struct sock *sk, unsigned int group); bool netlink_strict_get_check(struct sk_buff *skb); -int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 portid, int nonblock); +/* Internal flags for netlink_unicast (do not overlap with MSG_* flags) */ +#define NETLINK_UNICAST_TIMED 0x80000 + +int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 portid, int flags); int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 portid, __u32 group, gfp_t allocation); diff --git a/kernel/audit.c b/kernel/audit.c index e1d489bc2dff..005bfd9dc7a4 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -753,7 +753,7 @@ static int auditd_send_unicast_skb(struct sk_buff *skb) portid = ac->portid; rcu_read_unlock(); - rc = netlink_unicast(sk, skb, portid, 0); + rc = netlink_unicast(sk, skb, portid, NETLINK_UNICAST_TIMED); put_net(net); if (rc < 0) goto err; @@ -811,7 +811,7 @@ static int kauditd_send_queue(struct sock *sk, u32 portid, retry: /* grab an extra skb reference in case of error */ skb_get(skb); - rc = netlink_unicast(sk, skb, portid, 0); + rc = netlink_unicast(sk, skb, portid, NETLINK_UNICAST_TIMED); if (rc < 0) { /* send failed - try a few times unless fatal error */ if (++failed >= retry_limit || @@ -967,7 +967,7 @@ int audit_send_list_thread(void *_dest) audit_ctl_unlock(); while ((skb = __skb_dequeue(&dest->q)) != NULL) - netlink_unicast(sk, skb, dest->portid, 0); + netlink_unicast(sk, skb, dest->portid, NETLINK_UNICAST_TIMED); put_net(dest->net); kfree(dest); @@ -1020,7 +1020,7 @@ static int audit_send_reply_thread(void *arg) /* Ignore failure. It'll only happen if the sender goes away, because our timeout is set to infinite. */ - netlink_unicast(audit_get_sk(reply->net), reply->skb, reply->portid, 0); + netlink_unicast(audit_get_sk(reply->net), reply->skb, reply->portid, NETLINK_UNICAST_TIMED); reply->skb = NULL; audit_free_reply(reply); return 0; diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 2aeb0680807d..acaa96695981 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -1325,14 +1325,17 @@ static int netlink_unicast_kernel(struct sock *sk, struct sk_buff *skb, } int netlink_unicast(struct sock *ssk, struct sk_buff *skb, - u32 portid, int nonblock) + u32 portid, int flags) { struct sock *sk; int err; long timeo; + int nonblock; skb = netlink_trim(skb, gfp_any()); + /* Extract blocking mode: strip internal flags, preserve MSG_DONTWAIT */ + nonblock = flags & ~NETLINK_UNICAST_TIMED; timeo = sock_sndtimeo(ssk, nonblock); retry: sk = netlink_getsockbyportid(ssk, portid); @@ -1351,8 +1354,18 @@ int netlink_unicast(struct sock *ssk, struct sk_buff *skb, } err = netlink_attachskb(sk, skb, &timeo, ssk); - if (err == 1) + if (err == 1) { + /* timeo may have been zeroed by schedule_timeout inside + * netlink_attachskb. If the caller is a timed-blocking sender + * (not genuinely nonblocking), don't re-enter with timeo=0 as + * that would misfire netlink_overrun on the next iteration. + */ + if (!timeo && (flags & NETLINK_UNICAST_TIMED)) { + kfree_skb(skb); + return -EAGAIN; + } goto retry; + } if (err) return err; -- 2.53.0