Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV on FreeBSD with version 1.13.0 #376

Closed
kapfenho opened this issue Dec 14, 2020 · 10 comments
Closed

SIGSEGV on FreeBSD with version 1.13.0 #376

kapfenho opened this issue Dec 14, 2020 · 10 comments

Comments

@kapfenho
Copy link

kapfenho commented Dec 14, 2020

With version 1.13.0 I got a segmentation violation (sorry, no core file). That's the first time, after years of stability.

Last messages:

Dec 14 01:03:59 <daemon.notice> homer unbound[72482]: [72482:0] notice: sendto failed: Permission denied  
Dec 14 01:03:59 <kern.info> homer kernel: pid 72482 (unbound), jid 0, uid 59: exited on signal 11  

System:

FreeBSD homer 12.2-RELEASE-p1 FreeBSD 12.2-RELEASE-p1 GENERIC  amd64

Unbound config (using IPv4 & IPv6):

server:
        verbosity: 1
        statistics-interval: 3600
        interface: ::1
        interface: ...
        interface-automatic: yes
        outgoing-interface: ...
        access-control: ... allow
        root-hints: "/usr/local/etc/unbound/root.hints"
        hide-identity: yes
        hide-version: yes
        harden-algo-downgrade: yes
        auto-trust-anchor-file: "/usr/local/etc/unbound/root.key"
remote-control:
        control-enable: yes
        control-interface: 127.0.0.1
@rozhuk-im
Copy link

rozhuk-im commented Dec 14, 2020

Crash for me too, build from sources: TFOCL, TFOSE, THREADS options is set.

@kapfenho
Copy link
Author

Options here: ECDSA GOST LIBEVENT THREADS

@emikulic
Copy link

Some debugging and backtraces in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=251821

@delphij
Copy link

delphij commented Dec 15, 2020

I think this was caused by commit 15e8f5c .

The problem is that the logging code really expects a valid addr pointer, and now in udp_connect case it's no longer true.

I think this would stop unbound from crashing for the FreeBSD case:

diff --git a/services/outside_network.c b/services/outside_network.c
index 0886907f..e2843573 100644
--- a/services/outside_network.c
+++ b/services/outside_network.c
@@ -1901,6 +1901,9 @@ randomize_and_send_udp(struct pending* pend, sldns_buffer* packet, int timeout)
 	/* send it over the commlink */
 	if(outnet->udp_connect) {
 		if(!comm_point_send_udp_msg(pend->pc->cp, packet, NULL, 0)) {
+			log_addr(VERB_OPS, "remote address is",
+				(struct sockaddr_storage*)&pend->addr,
+				pend->addrlen);
 			portcomm_loweruse(outnet, pend->pc);
 			return 0;
 		}
diff --git a/util/netevent.c b/util/netevent.c
index 7c6da50b..27e94438 100644
--- a/util/netevent.c
+++ b/util/netevent.c
@@ -367,9 +367,14 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
 #endif
 			int e;
 			fd_set_block(c->fd);
-			sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), 
-				sldns_buffer_remaining(packet), 0,
-				addr, addrlen);
+			if (addr) {
+				sent = sendto(c->fd, (void*)sldns_buffer_begin(packet),
+					sldns_buffer_remaining(packet), 0,
+					addr, addrlen);
+			} else {
+				sent = send(c->fd, (void*)sldns_buffer_begin(packet),
+					sldns_buffer_remaining(packet), 0);
+			}
 			e = errno;
 			fd_set_nonblock(c->fd);
 			errno = e;
@@ -378,9 +383,13 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
 	if(sent == -1) {
 		if(!udp_send_errno_needs_log(addr, addrlen))
 			return 0;
-		verbose(VERB_OPS, "sendto failed: %s", sock_strerror(errno));
-		log_addr(VERB_OPS, "remote address is", 
-			(struct sockaddr_storage*)addr, addrlen);
+		if (addr) {
+			verbose(VERB_OPS, "sendto failed: %s", sock_strerror(errno));
+			log_addr(VERB_OPS, "remote address is",
+				(struct sockaddr_storage*)addr, addrlen);
+		} else {
+			verbose(VERB_OPS, "send failed: %s", sock_strerror(errno));
+		}
 		return 0;
 	} else if((size_t)sent != sldns_buffer_remaining(packet)) {
 		log_err("sent %d in place of %d bytes", 

but it would introduce a layer violation; and arguably it's not safe to call udp_send_errno_needs_log with NULL either, although it would not cause a crash with ENOBUFS. It's late here so I'm posting the patch here in the hope that someone familiar with the code can create a better fix.

@gthess
Copy link
Member

gthess commented Dec 16, 2020

@delphij You found a bug for sure, thanks for the patch!
I modified it and included it in 08968ba.

It seems it solves the problems reported here but not sure about the one reported over at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=251821. It seems to be TCP related.

@Sp1l
Copy link

Sp1l commented Dec 17, 2020

Added to FreeBSD ports in 558269 and 558271 (2020Q4)
See freebsd/freebsd-ports@1d6fa91
freebsd/freebsd-ports@aa6db09

uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Dec 17, 2020
PR:		251821
Submitted by:	delphij
Approved by:	Jaap Akkerhuis (maintainer)
Obtained from:	NLnetLabs/unbound#376
MFH:		2020Q4


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@558269 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Dec 17, 2020
PR:		251821
Submitted by:	delphij
Approved by:	Jaap Akkerhuis (maintainer)
Obtained from:	NLnetLabs/unbound#376
MFH:		2020Q4
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Dec 17, 2020
dns/unbound: SIGSEGV fix

PR:		251821
Submitted by:	delphij
Approved by:	Jaap Akkerhuis (maintainer)
Obtained from:	NLnetLabs/unbound#376
Jehops pushed a commit to Jehops/freebsd-ports-legacy that referenced this issue Dec 17, 2020
PR:		251821
Submitted by:	delphij
Approved by:	Jaap Akkerhuis (maintainer)
Obtained from:	NLnetLabs/unbound#376
MFH:		2020Q4


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@558269 35697150-7ecd-e111-bb59-0022644237b5
@delphij
Copy link

delphij commented Dec 27, 2020

@delphij You found a bug for sure, thanks for the patch!
I modified it and included it in 08968ba.

It seems it solves the problems reported here but not sure about the one reported over at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=251821. It seems to be TCP related.

That one looks like a different bug. Unfortunately I was unable to trigger it locally...

@cschuber
Copy link

@delphij You found a bug for sure, thanks for the patch!
I modified it and included it in 08968ba.
It seems it solves the problems reported here but not sure about the one reported over at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=251821. It seems to be TCP related.

That one looks like a different bug. Unfortunately I was unable to trigger it locally...

I'm not able to reproduce this here either.

@wcawijngaards
Copy link
Member

The commit may fix the tcp related issue that the others seem unable to trigger. I could not trigger it also, but I added code to stop double additions and double deletions from the event map. I think that may stop the failure from the libevent library.

@wcawijngaards
Copy link
Member

The fix for #393 has been tested to fix the issue that was still pending for the issue list here. That fixes the problems reported here, so I close the issue. If problems persist, feel free to open a new issue, or continue to comment here.

uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Apr 1, 2021
dns/unbound: SIGSEGV fix

PR:		251821
Submitted by:	delphij
Approved by:	Jaap Akkerhuis (maintainer)
Obtained from:	NLnetLabs/unbound#376
svmhdvn pushed a commit to svmhdvn/freebsd-ports that referenced this issue Jan 10, 2024
PR:		251821
Submitted by:	delphij
Approved by:	Jaap Akkerhuis (maintainer)
Obtained from:	NLnetLabs/unbound#376
MFH:		2020Q4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants