From 4e4ac87b037bda8b0997bf4f7d5c4d2fe740a1cc Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 14 May 2018 22:54:33 +0000 Subject: [PATCH] socketutils: use exact match of unix domain sockets on fresh kernels * socketutils.c (unix_send_query): Do not add NLM_F_DUMP to nlmsg_flags when kernel version is 4.4.4 or later, initialize udiag_cookie unconditionally. Complements: v4.12~536 ("Change unix_diag requests back to use full dump instead of exact match") --- socketutils.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/socketutils.c b/socketutils.c index b6b12c76..a646b5b2 100644 --- a/socketutils.c +++ b/socketutils.c @@ -252,6 +252,13 @@ receive_responses(struct tcb *tcp, const int fd, const unsigned long inode, static bool unix_send_query(struct tcb *tcp, const int fd, const unsigned long inode) { + /* + * The kernel bug was fixed in mainline by commit v4.5-rc6~35^2~11 + * and backported to stable/linux-4.4.y by commit v4.4.4~297. + */ + const uint16_t dump_flag = + os_release < KERNEL_VERSION(4, 4, 4) ? NLM_F_DUMP : 0; + struct { const struct nlmsghdr nlh; const struct unix_diag_req udr; @@ -259,13 +266,14 @@ unix_send_query(struct tcb *tcp, const int fd, const unsigned long inode) .nlh = { .nlmsg_len = sizeof(req), .nlmsg_type = SOCK_DIAG_BY_FAMILY, - .nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST + .nlmsg_flags = NLM_F_REQUEST | dump_flag }, .udr = { .sdiag_family = AF_UNIX, .udiag_ino = inode, .udiag_states = -1, - .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER + .udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER, + .udiag_cookie = { ~0U, ~0U } } }; return send_query(tcp, fd, &req, sizeof(req)); -- 2.40.0