Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751323AbaFLSiv (ORCPT ); Thu, 12 Jun 2014 14:38:51 -0400 Received: from mail-ve0-f173.google.com ([209.85.128.173]:60502 "EHLO mail-ve0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751114AbaFLSiu (ORCPT ); Thu, 12 Jun 2014 14:38:50 -0400 MIME-Version: 1.0 In-Reply-To: References: From: Andy Lutomirski Date: Thu, 12 Jun 2014 11:38:27 -0700 Message-ID: Subject: Re: Segmentation fault on all golang executables To: Kui Zhang Cc: "linux-kernel@vger.kernel.org" , "H. Peter Anvin" Content-Type: multipart/mixed; boundary=047d7b3a9b7430326004fba7df35 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --047d7b3a9b7430326004fba7df35 Content-Type: text/plain; charset=UTF-8 On Thu, Jun 12, 2014 at 10:20 AM, Andy Lutomirski wrote: > On Thu, Jun 12, 2014 at 9:59 AM, Kui Zhang wrote: >> Hello, >> >> This commit seem to cause Segmentation fault on any of my golang executables. > > Well, crap. It looks like the Go people took my sample vDSO parser... > and broke it. WTF were they thinking? I should have noticed that > they screwed it up when I was cc'd on this thing: > > https://code.google.com/p/go/source/detail?r=56ea40aac72b > > but I didn't. Sorry, everyone. And the issue isn't even something > sensibly broken like trying to find vdso symbols in the symbol table. > No, they're using the size of the SHT_DYNSYM section to deduce the > number of entries *in the dynamic table*. This is just completely > wrong. > > But even that's not all. They borrowed by error handling, so they > should have silently failed to parse the vdso instead of crashing. > But then they broke it completely by failing to zero the state, so > they're just reading from initialized memory. Grr. > > The current offending code is here: > > https://code.google.com/p/go/source/browse/src/pkg/runtime/vdso_linux_amd64.c > > Since we don't get to break all Go executables, here are two options: > > 1. Try to keep the whole symbol table intact. This is annoying: > there's a reason I removed it. The linker script doesn't know how big > it is, so it's hard to make it compatible with the vvar table. > > 2. Write a dummy section table that contains a single empty section of > type SHT_DYNSYM. Hopefully the Go runtime will then get far enough to > fail cleanly. And they can go and write a real ELF parser or copy my > reference parser correctly. (hpa, can you apply my patches to make > the reference parser 32-bit clean?) Sigh. See attached. It seems to work for me. Can you test it? It'll hurt performance for Go programs, but I don't feel too bad about that. --Andy --047d7b3a9b7430326004fba7df35 Content-Type: text/x-patch; charset=US-ASCII; name="0001-x86-vdso-Hack-to-keep-64-bit-Go-programs-working.patch" Content-Disposition: attachment; filename="0001-x86-vdso-Hack-to-keep-64-bit-Go-programs-working.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_hwcesr4c0 RnJvbSBhZDlmMzEzMDI2OTQ5MjQ3ZWQyMDY3NjMxYjRlNWMyN2MxOTM1MDY0IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpNZXNzYWdlLUlkOiA8YWQ5ZjMxMzAyNjk0OTI0N2VkMjA2NzYzMWI0ZTVj MjdjMTkzNTA2NC4xNDAyNTk4MjMzLmdpdC5sdXRvQGFtYWNhcGl0YWwubmV0PgpGcm9tOiBBbmR5 IEx1dG9taXJza2kgPGx1dG9AYW1hY2FwaXRhbC5uZXQ+CkRhdGU6IFRodSwgMTIgSnVuIDIwMTQg MTE6MzE6NDYgLTA3MDAKU3ViamVjdDogW1BBVENIXSB4ODYsdmRzbzogSGFjayB0byBrZWVwIDY0 LWJpdCBHbyBwcm9ncmFtcyB3b3JraW5nCgpUaGUgR28gcnVudGltZSBoYXMgYSBidWdneSB2RFNP IHBhcnNlciB0aGF0IGN1cnJlbnRseSBzZWdmYXVsdHMuClRoaXMgd3JpdGVzIGFuIGVtcHR5IFNI VF9EWU5TWU0gZW50cnkgdGhhdCBjYXVzZXMgR28ncyBydW50aW1lIHRvCm1hbGZ1bmN0aW9uIGJ5 IHRoaW5raW5nIHRoYXQgdGhlIHZEU08gaXMgZW1wdHkgcmF0aGVyIHRoYW4KbWFsZnVuY3Rpb25p bmcgYnkgcnVubmluZyBvZmYgdGhlIGVuZCBhbmQgc2VnZmF1bHRp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ZHItPmVfc2hlbnRzaXplID0gZmFrZV9zZWN0aW9uc192YWx1ZSA/IHNpemVvZihFbGZf U2hkcikgOiAwOworCWhkci0+ZV9zaG51bSA9IGZha2Vfc2VjdGlvbnNfc2l6ZSAvIHNpemVvZihF bGZfU2hkcik7CiAJaGRyLT5lX3Noc3RybmR4ID0gU0hOX1VOREVGOyAvKiBTSE5fVU5ERUYgPT0g MCAqLwogCiAJaWYgKCFuYW1lKSB7Ci0tIAoxLjkuMwoK --047d7b3a9b7430326004fba7df35-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/