From owner-freebsd-threads@FreeBSD.ORG Thu Nov 20 18:32:30 2014 Return-Path: Delivered-To: freebsd-threads@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2474B787; Thu, 20 Nov 2014 18:32:30 +0000 (UTC) Received: from 0.mx.codelabs.ru (0.mx.codelabs.ru [144.206.233.71]) (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 B9D4C610; Thu, 20 Nov 2014 18:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codelabs.ru; s=three; h=Sender:Content-Type:MIME-Version:Message-ID:Subject:Cc:To:From:Date; bh=fW37QGGusbSFQlVdny3KC/GAHL7OBS1Gilalbyw0w+E=; b=fz2EFk0XpodUAYE7gJoHfY30nOmnhKPVXI7ras8ToX8eRiCux3y+zLkRJz5AOqJcGNq7HYb8LsuOf7uBRPuEDgQaE4Nrx8xFlkw9pBMHfn67mSqCNNSUxi8sM9KVaFcXnPKiZ8gYF3WmchoxjTj46Uj5S7UoUeATb4UEfn0fmp9SuGPCtT1/VxrKnTNp2C3b0pFC5JkqcTg5jBcJZvsn19nc3LyarttSMvxB1GwDzpKj9Kn+Z9/aCna8mh9n34uFi3QAOVjIzv2wiqpSyZS360ijxtHYOM8RKdGBuWaUCIRv+Frf/dtK+Sp7qp9Bx9TDe0sTVYrMvkBcmWI5bTNiU+1HfuF2n+iHS5wooO0r0FzMxE8LjGrq79cfIvBqmO6eUTG5Iuo+61JwRd55GyaJFwAKrSIb5DedCmSale+44D0xzQXN+mBvJp4CsH8p9gGjme9vjHl3bHEHna0c0k0ge4yfMBW1nXu4YsHHbtcJDo1xAGgEZ62zS+jl4ckReD/goBO4vVH9twUXPmcplGXTKzQeuXmY4l32Vx5VCyFpTtjoUSngltttvI5PRAuIv5d2E6L+6nZWUvMM+kabGk4xZ5GAf8xIHyCNUU7/wrUkUfB31LQ3rV7nZbnjjru43xbziunRnN0OQCMcW1MWgEpT992v/J3WZSxs4pyFVYR2160=; Received: from void.codelabs.ru (void.codelabs.ru [144.206.233.66]) by 0.mx.codelabs.ru with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) id 1XrWWj-000JUT-IR; Thu, 20 Nov 2014 22:32:21 +0400 Date: Thu, 20 Nov 2014 21:32:19 +0300 From: Eygene Ryabinkin To: freebsd-threads@FreeBSD.org Subject: [CFR][PATCH] Call proper signal handler from libthr for non-SA_SIGINFO case Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="3D7yMlnunRPwJqC7" Content-Disposition: inline Sender: rea@codelabs.ru Cc: kib@FreeBSD.org, davidxu@FreeBSD.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Nov 2014 18:32:30 -0000 --3D7yMlnunRPwJqC7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Good day. Was hacking on Squid that used to dump core when signal 15 was delivered to it via 'squid -k shutdown' and found out that the reason for core dumps is that thr_sighandler() is _sometimes_ passed 0x10001 as the value of "info" argument despite that _sigaction() always arms flags for __sys_sigaction() with SA_SIGINFO. But looking at handle_signal() I had discovered that if libthr client wants no SA_SIGINFO, then actp->sa_sigaction() will be called, though specs, http://pubs.opengroup.org/onlinepubs/009695399/functions/sigaction.html say that in this case sa_handler should be used. And this is consistent with the non-threaded case. Moreover, the called handler is passed 4 extra arguments, {{{ info->si_code, (struct sigcontext *)ucp, info->si_addr, (__sighandler_t *= )sigfunc); }}} and for my poor Squid this is the root of the problem, because 0x10001 gets dereferenced (as info->SOMETHING), so SIGSEGV gets delivered immediately. By the way, the issue with seamonkey (but not Python) at https://lists.freebsd.org/pipermail/freebsd-current/2013-June/042199.html https://lists.freebsd.org/pipermail/freebsd-current/2013-June/042210.html has the same pattern: inside one invocation of signal handler we see SIGSEGV that can be triggered by this very problem: frame #5 handles initial signal, while frame #4 is in-kernel stuff for SIGSEGV and #3 is its userspace counterpart that takes us into libthr once again, but this time for the different signal, I guess. And this one goes with proper "info", so no more harm is inflicted by libthr's code. The origin of 0x10001 as info isn't yet clear to me, though I have a feeling that it is SI_USER that is slipping somewhere to the wrong place. Will dig further. Anyway, it seems like that the currend code inside handle_signal() should be modified with the patch like http://codelabs.ru/fbsd/patches/libthr/11-CURRENT-fix-sighandler-invocati= on.patch Could anyone, please, review it and, probably, come up with the idea of why the current code is such as it is. Revision when it first appeared is 212076, https://svnweb.freebsd.org/base/head/lib/libthr/thread/thr_sig.c?r1=3D211= 737&r2=3D212076&view=3Dpatch Thanks. PS: I am not subscribed to the list, so, please, keep me CC'ed. --=20 Eygene Ryabinkin ,,,^..^,,, [ Life's unfair - but root password helps! | codelabs.ru ] [ 82FE 06BC D497 C0DE 49EC 4FF0 16AF 9EAE 8152 ECFB | freebsd.org ] --3D7yMlnunRPwJqC7 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iL4EABEKAGYFAlRuM7NfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3Bl bnBncC5maWZ0aGhvcnNlbWFuLm5ldDgyRkUwNkJDRDQ5N0MwREU0OUVDNEZGMDE2 QUY5RUFFODE1MkVDRkIACgkQFq+eroFS7PvMKwD+M1RGSFvorQD2H+GGSPSVr7Fo 4A3B8LzBRiEVcCv83AEBAIKsbLuoEPwoAjFNLu9DB+4TW+DC3o2S0sjsdiZhRbPg =85DT -----END PGP SIGNATURE----- --3D7yMlnunRPwJqC7--