Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp99083pxa; Mon, 10 Aug 2020 20:08:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+yAwqyKl622yUT/lY/ySzpbnJcnz6SRY96r7Cu7jpQVGJg0YGtyJtYTvoORdMFwXwFQeo X-Received: by 2002:a17:906:d159:: with SMTP id br25mr23614414ejb.16.1597115286510; Mon, 10 Aug 2020 20:08:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597115286; cv=none; d=google.com; s=arc-20160816; b=uAvvJeEmUuuwjW9ZR/o8XnRPYfT1sQQOh3Lxy5EQd1WqDqs4LW0D4Cb8HMQoiEPFxa 6oGANDcRql3Dw9/CN/HcFrDgh713xodCIrukp5CQlrF8QupnZT+qJ93VQb0/bECRiCg8 0zRA94pWX6JmoBE4Bujqs+ieNqvEfdEh3p5djGuiGKq5v6oD/N8RKppBuivSaMGdENrH 16bizczv4qvJd/M0QP7ZnYxwIG+0UrC1YiqE1kjAcoPkrNTr4ATRwTc6nF8Uj5Y4cD2G v/xVWbLEy8YnB0dKsdR7kjI1en+gObHs3YIDUzhx8hr1KHB0TCTFjg5BvepSU0tRcty5 5SzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=lAgPe7LYxrHND6axLhyzWgoGWJo7W6UM/7KYKZFAicY=; b=Zx+O0/4EadMAy8OpKU9VyfcoILCVDftfT/j4TQ3mNO+rWpBINNhg5Wswy+I2gHtdMy 91PYtajZ1F/KdCyMIWPlDO8ynuSARyfAVkmx9EVnCfK7BRS2xXqVi+oxNDeYIGxq+frF vNtldmf5w8/WZYjjmiDXZYkMlR9dqBr3Vh6zf+J5Maz+EnFuRqT85P+IZ1XyDrewgEt4 lhuRpy3gwWywUHOPOyLyQEpgArUghDr23rKwdnTk5K18rgTaKPevRO+X3NJHLtWywVAZ xCUTnapMDq+6QRLU0elQZow88wekfJCjtf9Nc/WULyJUsiueMUMISDPs2B7u6VS/dWmd kDeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Vt/xx+6q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n19si12149675ejc.243.2020.08.10.20.07.43; Mon, 10 Aug 2020 20:08:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Vt/xx+6q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727995AbgHKDGL (ORCPT + 99 others); Mon, 10 Aug 2020 23:06:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727066AbgHKDGL (ORCPT ); Mon, 10 Aug 2020 23:06:11 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC6C8C061756 for ; Mon, 10 Aug 2020 20:06:10 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id m15so5840321lfp.7 for ; Mon, 10 Aug 2020 20:06:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lAgPe7LYxrHND6axLhyzWgoGWJo7W6UM/7KYKZFAicY=; b=Vt/xx+6qknXNsAC24DXedJ+8lw2kZx476DKnzqwxqQHYmJ/b+vSOJ6uzjOOga0I6Pr 9KJ8nvtVaX/cYg14ek3e5Prb2+LHlU5eogRzmyaTtuSoIydVzMVTUSVQWLYvUV6XSFCF gTQaoglRLjuiQYYad1i7Ky+S6jrDOMpFBu0XZspeQyMFPfMtSHSPL3J6j63TuSbtHa37 +L4QJvsOShc6cHCqwJubi8QLmUtIbE3+iA9jtZvfyfWCtZeIA0tUsZ5FrGt8bCCgA0u2 Oq+Id6wDp61B1gJ0CKJntpsULkprxmjKMo5RN2SmtSQFISDi+GEDmKNI6p/WnG6lwjAY MZ1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lAgPe7LYxrHND6axLhyzWgoGWJo7W6UM/7KYKZFAicY=; b=pb/QHXwCI+BJouEabzW6bEtDI10H88gE+SVDENxvBuNWOijheh6dAt7X2Z82HfTYsL xapWxHvJvTg7zfzeTJyeJqeOLaKzhX0++81G+tspqzTxHRXZl40dQxia/DnIEM1ZTDl0 l1MJd0T0VBJWXVVa+vzCQQIl2zkQ20xDpRry3+ajOqPwnicNDZcqNBZN+imVxmWSH5hJ MslULeZoVH8c3T+zamBg+CakTASk40rMg2FQZtFba0ziJjfrm8O546TgjPx1MZTwwHQE 3VUBOoqqnkCHdpnMyKcVVwcew2bPAkT76u0fuUeWLS+I/2lIIepRmyqvKPo1jKSUqWPn +ryQ== X-Gm-Message-State: AOAM530foduI9I7yvLGWILLZ+PZbUhk2Dh8h0C/kUqHfZqTHeN3T7Ec8 b44MHAYcFeYzG1zQwTeNP7VagInVoa5jD7Wc+E5KlQN27pU= X-Received: by 2002:ac2:5f48:: with SMTP id 8mr2044815lfz.157.1597115168800; Mon, 10 Aug 2020 20:06:08 -0700 (PDT) MIME-Version: 1.0 References: <20200429214954.44866-1-jannh@google.com> <20200429214954.44866-2-jannh@google.com> <20200505104805.GA17400@lst.de> <20200505121557.GA24052@lst.de> In-Reply-To: <20200505121557.GA24052@lst.de> From: Jann Horn Date: Tue, 11 Aug 2020 05:05:42 +0200 Message-ID: Subject: Re: [PATCH v2 1/5] binfmt_elf_fdpic: Stop using dump_emit() on user pointers on !MMU To: Christoph Hellwig Cc: Andrew Morton , Linus Torvalds , kernel list , Linux-MM , linux-fsdevel , Alexander Viro , "Eric W . Biederman" , Oleg Nesterov , Russell King , Linux ARM , Mark Salter , Aurelien Jacquiot , linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Rich Felker , Linux-sh list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 5, 2020 at 2:15 PM Christoph Hellwig wrote: > On Tue, May 05, 2020 at 01:42:12PM +0200, Jann Horn wrote: > > On Tue, May 5, 2020 at 12:48 PM Christoph Hellwig wrote: > > > On Wed, Apr 29, 2020 at 11:49:50PM +0200, Jann Horn wrote: > > > > dump_emit() is for kernel pointers, and VMAs describe userspace memory. > > > > Let's be tidy here and avoid accessing userspace pointers under KERNEL_DS, > > > > even if it probably doesn't matter much on !MMU systems - especially given > > > > that it looks like we can just use the same get_dump_page() as on MMU if > > > > we move it out of the CONFIG_MMU block. > > > > > > Looks sensible. Did you get a chance to test this with a nommu setup? > > > > Nope. Do you happen to have a recommendation for a convenient > > environment I can use with QEMU, or something like that? I'm guessing > > that just running a standard armel Debian userspace with a !mmu ARM > > kernel wouldn't work so well? > > Nommu generally needs special userspace either using uclibc-ng or musl. > When I did the RISC-V nommu work I used buildroot for my root file > systems. We haven't gotten elffdpic to work on RISC-V yet, so I can't > use that setup for testing, but it should support ARM as well. I've finally gotten around to testing this, and discovered that I actually had to change something in the patch - thanks for asking me to test this. Some notes on running ARM nommu testing: I ended up running QEMU with "-machine versatilepb". To make that work, I applied this patch: A couple of directories up, there are also a README and a kernel config for that. Note that the emulated harddrive of this board doesn't seem to work, because it's connected via PCI, and nommu generally can't use PCI; but you can boot from initramfs, and you can copy files from/to the host with netcat, since the emulated network card does work. (To avoid having to bring up the interface from userspace, you can use "ip=10.0.2.1::10.0.2.2:255.255.255.0" on the kernel cmdline if the corresponding feature is enabled in the kernel config.) The first trouble I ran into with trying to run FDPIC userspace (based on musl) was that Linux has support for running ARM userspace in "26-bit mode", which is some ARM feature from the dark ages, with no support in QEMU; and while normally Linux only tries to enable that thing when the binary explicitly requires it, the FDPIC path isn't wired up to the appropriate personality logic properly, and so you get a spectacular explosion, where eventually the kernel oopses with a message about how it's trying to load an invalid value into CPSR because first the kernel tries to return to 26-bit mode, and then, through some mysterious spooky action at a distance, the kernel (AFAICS) ends up trying to do a syscall return with the stack pointer pointing somewhere in the middle of the kernel stack (and not where the entry register frame is). Anyway, my hacky workaround for that is: diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h index b9241051e5cb..d5aa409e366c 100644 --- a/arch/arm/include/asm/processor.h +++ b/arch/arm/include/asm/processor.h @@ -70,7 +70,7 @@ static inline void arch_thread_struct_whitelist(unsigned long *offset, if (current->personality & ADDR_LIMIT_32BIT) \ regs->ARM_cpsr = USR_MODE; \ else \ - regs->ARM_cpsr = USR26_MODE; \ + { WARN(1, "setting USR26_MODE"); regs->ARM_cpsr = USR_MODE; } \ if (elf_hwcap & HWCAP_THUMB && pc & 1) \ regs->ARM_cpsr |= PSR_T_BIT; \ regs->ARM_cpsr |= PSR_ENDSTATE; \ Next up: Early on in the libc startup code, musl aborts execution by intentionally executing an undefined instruction in __set_thread_area(), because it can't figure out any working implementation of atomic cmpxchg. For the MMU case, there is a kuser helper (what x86 would call vsyscall); but for NOMMU ARM, no working implementation exists. So I gave up on musl and went with uclibc-ng (built via buildroot) instead, since uclibc-ng has support for compiling out thread support. Annoyingly, buildroot doesn't support FDPIC (at least not for nommu ARM). So I ended up telling it to build a small FLAT userspace, and used a standard ARM toolchain to build a tiny static PIE ELF binary with no reliance on libc (the FDPIC loader can actually load normal ELF mostly fine as long as it's PIE, at the cost of having to duplicate the text section for every instance) - luckily I didn't need the ELF binary to actually do anything complicated, and so working without any libc was tolerable: arm-linux-gnueabi-gcc-10 -fPIC -c -o test_crash.o test_crash.c arm-linux-gnueabi-ld -pie --no-dynamic-linker -o test_crash test_crash.o Next fun part: gdb-multiarch doesn't seem to be able to open FDPIC core dumps properly - none of the register status is available. I took apart the core dump before and after the patch in a hex editor, though, and it seems to have all the expected stuff in it. I'm guessing that maybe GDB got thrown off by struct elf_prstatus having a different layout if the core dump was generated on nommu? GDB's elf32_arm_nabi_grok_prstatus() seems to only handle the struct size for the non-FDPIC struct.