git: aeb91e95cfc2 - main - Log euid, rgid and jail on listen queue overflow

From: Alexander Leidinger <netchild_at_FreeBSD.org>
Date: Sat, 26 Mar 2022 10:17:59 UTC
The branch main has been updated by netchild:

URL: https://cgit.FreeBSD.org/src/commit/?id=aeb91e95cfc2d86e6f5eea4114247d2987ba06b6

commit aeb91e95cfc2d86e6f5eea4114247d2987ba06b6
Author:     Alexander Leidinger <netchild@FreeBSD.org>
AuthorDate: 2022-03-26 10:14:16 +0000
Commit:     Alexander Leidinger <netchild@FreeBSD.org>
CommitDate: 2022-03-26 10:17:55 +0000

    Log euid, rgid and jail on listen queue overflow
    
    If you have numerous jails with multiple similar services running,
    this helps to narrow down which services this log is referring to.
---
 sys/kern/uipc_socket.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index ab8e5d6e1b69..4c4fde0d6a26 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -699,12 +699,24 @@ sonewconn(struct socket *head, int connstatus)
 			}
 			KASSERT(sbuf_len(&descrsb) > 0,
 			    ("%s: sbuf creation failed", __func__));
-			log(LOG_DEBUG,
-			    "%s: pcb %p (%s): Listen queue overflow: "
-			    "%i already in queue awaiting acceptance "
-			    "(%d occurrences)\n",
-			    __func__, head->so_pcb, sbuf_data(&descrsb),
-			    qlen, overcount);
+			if (head->so_cred == 0) {
+				log(LOG_DEBUG,
+			    	"%s: pcb %p (%s): Listen queue overflow: "
+			    	"%i already in queue awaiting acceptance "
+			    	"(%d occurrences)\n",
+			    	__func__, head->so_pcb, sbuf_data(&descrsb),
+			    	qlen, overcount);
+			} else {
+				log(LOG_DEBUG, "%s: pcb %p (%s): Listen queue overflow: "
+				    "%i already in queue awaiting acceptance "
+				    "(%d occurrences), euid %d, rgid %d, jail %s\n",
+				    __func__, head->so_pcb, sbuf_data(&descrsb),
+				    qlen, overcount,
+				    head->so_cred->cr_uid, head->so_cred->cr_rgid,
+				    head->so_cred->cr_prison ?
+					head->so_cred->cr_prison->pr_name :
+					"not_jailed");
+			}
 			sbuf_delete(&descrsb);
 
 			overcount = 0;