From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH conntrack-tools 2/2] conntrackd: remove double close() in multicast resulting in EBADFD
Date: Mon, 10 Nov 2025 11:35:31 +0100 [thread overview]
Message-ID: <20251110103531.2158-2-pablo@netfilter.org> (raw)
In-Reply-To: <20251110103531.2158-1-pablo@netfilter.org>
When using multicast for synchronization, misconfiguration results in
misleading EBADFD log errors due to double close() on the file
descriptor from the error path.
The caller of __mcast_client_create_{ipv4,ipv6} already deals with
closing the socket file descriptor.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/mcast.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/mcast.c b/src/mcast.c
index 88300da32673..9d441e6f0b28 100644
--- a/src/mcast.c
+++ b/src/mcast.c
@@ -135,7 +135,7 @@ void mcast_server_destroy(struct mcast_sock *m)
free(m);
}
-static int
+static int
__mcast_client_create_ipv4(struct mcast_sock *m, struct mcast_conf *conf)
{
int no = 0;
@@ -143,25 +143,21 @@ __mcast_client_create_ipv4(struct mcast_sock *m, struct mcast_conf *conf)
m->addr.ipv4.sin_family = AF_INET;
m->addr.ipv4.sin_port = htons(conf->port);
m->addr.ipv4.sin_addr = conf->in.inet_addr;
- m->sockaddr_len = sizeof(struct sockaddr_in);
+ m->sockaddr_len = sizeof(struct sockaddr_in);
if (setsockopt(m->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &no,
- sizeof(int)) < 0) {
- close(m->fd);
+ sizeof(int)) < 0)
return -1;
- }
if (setsockopt(m->fd, IPPROTO_IP, IP_MULTICAST_IF,
&conf->ifa.interface_addr,
- sizeof(struct in_addr)) == -1) {
- close(m->fd);
+ sizeof(struct in_addr)) == -1)
return -1;
- }
return 0;
}
-static int
+static int
__mcast_client_create_ipv6(struct mcast_sock *m, struct mcast_conf *conf)
{
int no = 0;
@@ -171,20 +167,16 @@ __mcast_client_create_ipv6(struct mcast_sock *m, struct mcast_conf *conf)
memcpy(&m->addr.ipv6.sin6_addr,
&conf->in.inet_addr6,
sizeof(struct in6_addr));
- m->sockaddr_len = sizeof(struct sockaddr_in6);
+ m->sockaddr_len = sizeof(struct sockaddr_in6);
if (setsockopt(m->fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &no,
- sizeof(int)) < 0) {
- close(m->fd);
+ sizeof(int)) < 0)
return -1;
- }
if (setsockopt(m->fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
&conf->ifa.interface_index6,
- sizeof(unsigned int)) == -1) {
- close(m->fd);
+ sizeof(unsigned int)) == -1)
return -1;
- }
return 0;
}
--
2.30.2
next prev parent reply other threads:[~2025-11-10 10:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 10:35 [PATCH conntrack-tools 1/2] conntrackd: restrict multicast reception Pablo Neira Ayuso
2025-11-10 10:35 ` Pablo Neira Ayuso [this message]
2025-11-10 12:35 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251110103531.2158-2-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.