From owner-svn-src-all@FreeBSD.ORG Thu Aug 21 11:12:55 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BC77D317; Thu, 21 Aug 2014 11:12:55 +0000 (UTC) Received: from mail-wi0-x22e.google.com (mail-wi0-x22e.google.com [IPv6:2a00:1450:400c:c05::22e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D77EF3805; Thu, 21 Aug 2014 11:12:54 +0000 (UTC) Received: by mail-wi0-f174.google.com with SMTP id d1so8512178wiv.1 for ; Thu, 21 Aug 2014 04:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=Fct6oz5Lw7zpQOpRzkZIxW/dakvNtS76S2CmGcP+LLk=; b=UNdHPaQyy/1sQ6krH+2EFPe5nzAdNnjWJ8CZQBVyesNY/0C/RQSZiiyhzrGc591hXd BRKWJJxIuOgXW0QBkc7AOhUbfuE9AXlUI+10414ddJ4jWp0fbw9wtuNK0ewW3ZeegWCd Q4q9G0nm6vIoFvIwwE7ONDLIv75TrweETtBCDUJYbsn37ccVBlnqaJTFFmJPLrx2vkmo ezu6gPBfjL2ZdrgA6rRF2ug+LHjkr58RzVunnqoIzwneED95iDVYLzvodrW2BnA77f5Q Ipxtz2mnEdkJlhsnBWLvZevujVDP12q/P6PuEpxWF5l36VEd6v+MuGKYDYgzHu0V1PhF QMuA== X-Received: by 10.194.77.233 with SMTP id v9mr2599078wjw.129.1408619572850; Thu, 21 Aug 2014 04:12:52 -0700 (PDT) Received: from [172.16.1.30] (39.Red-2-136-52.dynamicIP.rima-tde.net. [2.136.52.39]) by mx.google.com with ESMTPSA id ga2sm65923199wjb.44.2014.08.21.04.12.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Aug 2014 04:12:51 -0700 (PDT) Sender: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= Message-ID: <53F5D42E.9080908@FreeBSD.org> Date: Thu, 21 Aug 2014 13:12:46 +0200 From: =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Konstantin Belousov Subject: Re: svn commit: r265003 - head/secure/usr.sbin/sshd References: <201404270528.s3R5SEIm054377@svn.freebsd.org> <53F4B381.5010205@FreeBSD.org> <20140820151310.GB2737@kib.kiev.ua> <53F4BC9B.3090405@FreeBSD.org> <53F4BEB1.6070000@FreeBSD.org> <53F4C022.5050804@FreeBSD.org> <20140821080541.GE2737@kib.kiev.ua> In-Reply-To: <20140821080541.GE2737@kib.kiev.ua> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Bryan Drewery X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Aug 2014 11:12:56 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 21/08/14 10:05, Konstantin Belousov wrote: > On Wed, Aug 20, 2014 at 05:34:58PM +0200, Roger Pau Monn? wrote: >> On 20/08/14 17:28, Bryan Drewery wrote: >>> On 8/20/2014 10:19 AM, Roger Pau Monn? wrote: >>>> On 20/08/14 17:13, Konstantin Belousov wrote: >>>>> On Wed, Aug 20, 2014 at 04:41:05PM +0200, Roger Pau Monn?? >>>>> wrote: >>>>>> On 27/04/14 07:28, Konstantin Belousov wrote: >>>>>>> Author: kib Date: Sun Apr 27 05:28:14 2014 New >>>>>>> Revision: 265003 URL: >>>>>>> http://svnweb.freebsd.org/changeset/base/265003 >>>>>>> >>>>>>> Log: Fix order of libthr and libc in the global dso >>>>>>> list for sshd, by explicitely linking main binary with >>>>>>> -lpthread. Before, libthr appeared in the list due to >>>>>>> dependency of one of the kerberos libs. Due to the >>>>>>> change in ld(1) behaviour of not copying NEEDED entries >>>>>>> from direct dependencies into the link results, the >>>>>>> order becomes reversed. >>>>>>> >>>>>>> The libthr must appear before libc to properly >>>>>>> interpose libc symbols and provide working rtld locks >>>>>>> implementation. The symptom was sshd hanging on rtld >>>>>>> bind lock during nested symbol binding from a signal >>>>>>> handler. >>>>>>> >>>>>>> Approved by: des (openssh maintainer) Sponsored by: >>>>>>> The FreeBSD Foundation MFC after: 1 week >>>>>>> >>>>>>> Modified: head/secure/usr.sbin/sshd/Makefile >>>>>>> >>>>>>> Modified: head/secure/usr.sbin/sshd/Makefile >>>>>>> ============================================================================== >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> - --- head/secure/usr.sbin/sshd/Makefile Sun Apr 27 05:19:01 2014 (r265002) >>>>>>> +++ head/secure/usr.sbin/sshd/Makefile Sun Apr 27 >>>>>>> 05:28:14 2014 (r265003) @@ -57,6 +57,16 @@ CFLAGS+= >>>>>>> -DNONE_CIPHER_ENABLED DPADD+= ${LIBCRYPT} ${LIBCRYPTO} >>>>>>> ${LIBZ} LDADD+= -lcrypt -lcrypto -lz >>>>>>> >>>>>>> +# Fix the order of NEEDED entries for libthr and >>>>>>> libc. The libthr +# needs to interpose libc symbols, >>>>>>> leaving the libthr loading as +# dependency of krb >>>>>>> causes reversed order and broken interposing. Put +# >>>>>>> the threading library last on the linker command line, >>>>>>> just before +# the -lc added by a compiler driver. >>>>>>> +.if ${MK_KERBEROS_SUPPORT} != "no" +DPADD+= >>>>>>> ${LIBPTHREAD} +LDADD+= -lpthread +.endif + .if >>>>>>> defined(LOCALBASE) CFLAGS+= >>>>>>> -DXAUTH_PATH=\"${LOCALBASE}/bin/xauth\" .endif >>>>>> >>>>>> Hello, >>>>>> >>>>>> This change makes the following simple test program fail >>>>>> on the second assert. The problem is that sa_handler == >>>>>> SIG_DFL, and sa_flags == SA_SIGINFO, which according to >>>>>> the sigaction(9) man page is not possible. With this >>>>>> change reverted the test is successful. >>>>> I do not quite follow. >>>>> >>>>> What are the relations between sshd and your test program ? >>>>> Should the test be run somehow specially ? >>>> >>>> No, and frankly that's what I don't understand. I compile >>>> this simple test with `cc -o test test.c`. It fails with >>>> this commit applied, and succeeds without it. >>>> >>>> Roger. >>>> >>> >>> Does it fail if you do not connect with ssh? >> >> Right, it works fine from the serial console, fails when >> executed from ssh. > > I cannot reproduce it locally with your scenario, but the attached > program demonstrates the issue without relying on inheritance and > libthr. > > I think you mis-interpret the man page statement, it only says that > SA_SIGINFO should not be set in new->sa_flags IMO. But I do not see > much sense in the requirement. Note that we do not test flags for > correctness at all. SUSv4 is also silent on the issue. > > If this is important for your case, the following patch prevents > leaking of the flags for ignored of default/action signals. Could > you, please, describe why do you consider this a bug ? IMO, it is an inconsistency to return an invalid old sigaction, I assume that what is returned as the old sigaction should also be valid according to the man page. I realize SUSv4 don't specify such requirement, but it would still be wrong to use SIG_DFL with SA_SIGINFO, since SA_SIGINFO expect the handler to be of the type: void func(int signo, siginfo_t *info, void *context); While SIG_DLF is of type: void func(int signo); There's software out there that (wrongly?) relies on sa_action == SIG_DFL and (sa_flags & SA_SIGINFO) == 0: http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl_fork.c;h=fa150959adcfa6618342ba1eb0085cbba5f75d0a;hb=HEAD#l338 The sa_flags check done here seems too strong in my opinion, but I still think it's right according to the man page. Roger. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (Darwin) iQEcBAEBAgAGBQJT9dQpAAoJEKXZdqUyumTAgsIH/2xAfa0FjWpCpkvDoNXGVs4K tRDurCFTsaCJZ1xt3aQyPvPALm+qOpBX+i3nTiX4Bg86jbrZRGTag4OeAE6uX3KR TCKaUB6jNUjuNsj5djURIQktbojFj71ID40bM3AXExXN8Gc7e9qqdvo+p82hDFS/ RkwwS9NfTv+yeC/djH+PsApq7OYCrpR0CX1fW6TKwtjdEZpJC4jx5S5TVJoZ2Y0B urlCtrjW6b4oNHqoiDMF4nk48SkuU/JWsTGAbFW6lK+1voyt3y1126uFk5jz144M ZYy4fu6mKEddrwrUFD9Qt9r3shaSLbenBxhc2ZxMT9V4Ws87bVxTSqqzrYsHJ0E= =Qwfa -----END PGP SIGNATURE-----