From owner-freebsd-bugs@freebsd.org Thu Dec 21 18:35:47 2017 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4D223E81D5E for ; Thu, 21 Dec 2017 18:35:47 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3C04A72AD9 for ; Thu, 21 Dec 2017 18:35:47 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id vBLIZl6a028210 for ; Thu, 21 Dec 2017 18:35:47 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 224503] rpcbind: Broken in the face of signal termination Date: Thu, 21 Dec 2017 18:35:47 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: cem@freebsd.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Dec 2017 18:35:47 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D224503 Bug ID: 224503 Summary: rpcbind: Broken in the face of signal termination Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: cem@freebsd.org Rpcbind may crash in signal-induced termination. E.g.: > (gdb) bt > ... > #12 __free (ptr=3D0x8006f8140) at jemalloc_jemalloc.c:1277 > #13 0x0000000800d4c8e7 in vector_free (esize=3D, vec=3D, count=3D, esize=3D, free_elem= =3D) > at /b/mnt/src/lib/libc/net/nsdispatch.c:250 > #14 nss_atexit () at /b/mnt/src/lib/libc/net/nsdispatch.c:577 > #15 0x0000000800d4d5b9 in __cxa_finalize (dso=3D0x0) at /b/mnt/src/lib/li= bc/stdlib/atexit.c:200 > #16 0x0000000800cfe1ac in exit (status=3D2) at /b/mnt/src/lib/libc/stdlib= /exit.c:67 > #17 0x0000000000404df5 in terminate (signum=3D-26832) at /b/mnt/src/usr.s= bin/rpcbind/rpcbind.c:860 > #18 0x000000080337f67b in handle_signal (actp=3D, sig=3D15= , info=3D0x7fffffffa9f0, ucp=3D0x7fffffffa680) at /b/mnt/src/lib/libthr/thr= ead/thr_sig.c:240 > #19 0x000000080337f263 in thr_sighandler (sig=3D15, info=3D0x7fffffffa9f0= , _ucp=3D0x800700210) at /b/mnt/src/lib/libthr/thread/thr_sig.c:183 rpcbind got a sig 15 (TERM) and attempted to call exit(3) from a signal handler. But, exit(3) is not an async-signal safe function. Probably these crashes are the result of the program manipulating jemalloc internal struct= ures at the time the SIGTERM is delivered and handled unsafely. The cause can be explained: 195 /* catch the usual termination signals for graceful exit */ 196 (void) signal(SIGCHLD, reap); 197 (void) signal(SIGINT, terminate); 198 (void) signal(SIGTERM, terminate); 199 (void) signal(SIGQUIT, terminate); ... 758 /* 759 * Catch the signal and die 760 */ 761 static void 762 terminate(int signum __unused) 763 { 764 close(rpcbindlockfd); 765 #ifdef WARMSTART 766 syslog(LOG_ERR, 767 "rpcbind terminating on signal %d. Restart with \"rpcbind -w\"", 768 signum); 769 write_warmstart(); /* Dump yourself */ 770 #endif 771 exit(2); 772 } ... // close(2) is async-safe -- rpcbindlockfd must be initalized before the si= gnal is // delivered, though. // // syslog() is definitely not safe. // // write_warmstart() uses fopen(3), syslog(3), ... definitely not safe. // // Finally, exit(3) itself is not safe either. 857 void 858 reap(int dummy __unused) 859 { 860 int save_errno =3D errno; 861 862 while (wait3(NULL, WNOHANG, NULL) > 0) 863 ; 864 errno =3D save_errno; 865 } // wait(2) and waitpid(2) are allowed, but wait3() is not documented as all= owed in // sigaction(2). It likely is allowed, though, given it is implemented identically // to wait(2) (in terms of wait4(2)). So `reap` for SIGCHLD is probably ok. --=20 You are receiving this mail because: You are the assignee for the bug.=