From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19006CE7A89 for ; Mon, 25 Sep 2023 09:21:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A101C8D001F; Mon, 25 Sep 2023 05:21:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C1B28D0001; Mon, 25 Sep 2023 05:21:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 888948D001F; Mon, 25 Sep 2023 05:21:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7B0438D0001 for ; Mon, 25 Sep 2023 05:21:00 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4CF1D1CA47E for ; Mon, 25 Sep 2023 09:21:00 +0000 (UTC) X-FDA: 81274575480.19.2D39484 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 1BDF240004 for ; Mon, 25 Sep 2023 09:20:57 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UojhxFLO; spf=pass (imf11.hostedemail.com: domain of sebott@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=sebott@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695633658; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Vs+s8MbEdlPjqhnrrm1uH19re0iD33TvngqTvSoravg=; b=emr0wON/44z9wqtJJD9AvlBnCcdbE05+91WyFtok+350j1oOngu+y+ZXKXHbbyXsIO4uhf o+SRzmEE1oFO17YHAhooiM3wKmkSVsRNTZL+wiHGpU7jcGUmEctpzLehGJOFDcxarju2Lb WCVga/wcVkZ35pRvFdJUddx4pO9ezpY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UojhxFLO; spf=pass (imf11.hostedemail.com: domain of sebott@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=sebott@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695633658; a=rsa-sha256; cv=none; b=IzxszPwgMnwUXTdZxPNBSpg3TDQ2StQJvCJdH1jMXNVVDR6pkz1j7MgJCgaynrUo74LZL0 rs16q2w2mAmkRgbHHHtzhNTWuysSJ7WszdFxFlp94ubH7NrBL3Z8J5om9VZ14hL/z5tQq6 xGtSMrqeaf2pAj91bVfz7TE2jzpeEkQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695633657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Vs+s8MbEdlPjqhnrrm1uH19re0iD33TvngqTvSoravg=; b=UojhxFLONyYjlF4jwio1KQzu0UA7ZmtccNUAyJU3I7zz/IQxgptziClEblxW+B+fXMZ8Vn vpPqtMhPX8H2v6Zx8QuxqjM9cuvWPM9H92ay9+SpgAcStacdv0/mV5CY6wFJAv7mJaVH2P IBSFJqVTm4gYg/zOxVrPM5TuqwhU4PI= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-281-cRJBFCQRPh6hHJnYMIrC9A-1; Mon, 25 Sep 2023 05:20:56 -0400 X-MC-Unique: cRJBFCQRPh6hHJnYMIrC9A-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-774086da4dbso1103458885a.0 for ; Mon, 25 Sep 2023 02:20:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695633655; x=1696238455; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Vs+s8MbEdlPjqhnrrm1uH19re0iD33TvngqTvSoravg=; b=asO1LA1+dzN8up9naQ48SN0/jYT2H5nquke56jfhsLYE7vbyqx02KnpCzuoJ6EbM6Z 213hWtTIk5rD5J44qZBCGrwJG3vO5bHpX/Gx38Nc85KYLm0HC1PNxID7+RQ/OB0fQsjc qpMOeFaW18M0Q6PK/pHpuQED9726uT6hvvy1HD5PTKApo0ZPhs2OvyB6+ZxafiIEwcSF cLLtcx00F/1BN5NjhSDhBLzQR+FEr25Pcr9YuOHjEnqSriuGv37iV+WO1/i7fuTfb7Oi MWOT7V+B0IzQ9rw6L4MHnVs+V4hPi2uBBobidgfoFJ6Y0MExmxPoJTp0d8C9t7+Btfaj GHqw== X-Gm-Message-State: AOJu0YzWHsCrwyyp6FqzSL1vg17QJjwJgorSF2SmQ529D9E7M1sCX0ut XMs+mSyQB5yXzpmOcJCh2sPXW16o7DB5cpQmv96OLmvxV2tQvMYE/Z1nYcrTZKb3CCEVIV3+ShO qQxOD/ygEkog= X-Received: by 2002:a05:620a:2988:b0:774:2e8a:ccc6 with SMTP id r8-20020a05620a298800b007742e8accc6mr3902483qkp.32.1695633655392; Mon, 25 Sep 2023 02:20:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMfVG4q5k9ZPvMkbAHXmeCcChQBeS4lTv+/XiDIhQ/90pemlHQA/z1amKfCLJr6ZjuCedpAg== X-Received: by 2002:a05:620a:2988:b0:774:2e8a:ccc6 with SMTP id r8-20020a05620a298800b007742e8accc6mr3902467qkp.32.1695633655100; Mon, 25 Sep 2023 02:20:55 -0700 (PDT) Received: from rh (p200300c93f1ec600a890fb4d684902d4.dip0.t-ipconnect.de. [2003:c9:3f1e:c600:a890:fb4d:6849:2d4]) by smtp.gmail.com with ESMTPSA id vr10-20020a05620a55aa00b0076ef7810f27sm3633710qkn.58.2023.09.25.02.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 02:20:54 -0700 (PDT) Date: Mon, 25 Sep 2023 11:20:51 +0200 (CEST) From: Sebastian Ott To: "Eric W. Biederman" cc: =?ISO-8859-15?Q?Thomas_Wei=DFschuh?= , Alexander Viro , Christian Brauner , Kees Cook , Mark Brown , Willy Tarreau , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH RFC] binfmt_elf: fully allocate bss pages In-Reply-To: <87zg1bm5xo.fsf@email.froward.int.ebiederm.org> Message-ID: <37d3392c-cf33-20a6-b5c9-8b3fb8142658@redhat.com> References: <20230914-bss-alloc-v1-1-78de67d2c6dd@weissschuh.net> <36e93c8e-4384-b269-be78-479ccc7817b1@redhat.com> <87zg1bm5xo.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; format=flowed; charset=US-ASCII X-Rspamd-Queue-Id: 1BDF240004 X-Rspam-User: X-Stat-Signature: 5b87ywnya4pis5rt9mcp6sddarpdr178 X-Rspamd-Server: rspam01 X-HE-Tag: 1695633657-370268 X-HE-Meta: U2FsdGVkX18UyuHPa7Bu4ouGt1jQ902IWMmFcMe2LJDplvf7iQXD3dLjIMnZnFO41nWbwNGz/xV3RxKRNJ1S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18+lpKncFnZX1OwRm5/mF9UGLmUMfnzvh2y4cLFVFisI4XL580IoeExwAwtLfCPQLGslS8GJzyjNQ/vvjgYEl+D4I1EbUDz1pQFxOGxv8umHkzrH6Ou2b/qfJSyTY6jYgLQ7v+m8ljfeP95z07a0Q9lBZfLl1ZPjS6mjKpTI61CqHINTF9moJU2OKke5rRDZuDpDQOEerDaokO+AQ3Sx4aR4HwuHIkqhckZ3YGKPKIm+lYu/ip6ZtUC0QNqGwpmB1GYBWG+M0vCS1wca96Bx1Eu1gNt7sd1xKQCSxs1qPettDQ/DUrlHu5fIsSIkePhDusBST X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, 24 Sep 2023, Eric W. Biederman wrote: > Sebastian Ott writes: > >> Hej, >> >> since we figured that the proposed patch is not going to work I've spent a >> couple more hours looking at this (some static binaries on arm64 segfault >> during load [0]). The segfault happens because of a failed clear_user() >> call in load_elf_binary(). The address we try to write zeros to is mapped with >> correct permissions. >> >> After some experiments I've noticed that writing to anonymous mappings work >> fine and all the error cases happend on file backed VMAs. Debugging showed that >> in elf_map() we call vm_mmap() with a file offset of 15 pages - for a binary >> that's less than 1KiB in size. >> >> Looking at the ELF headers again that 15 pages offset originates from the offset >> of the 2nd segment - so, I guess the loader did as instructed and that binary is >> just too nasty? >> >> Program Headers: >> Type Offset VirtAddr PhysAddr >> FileSiz MemSiz Flags Align >> LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 >> 0x0000000000000178 0x0000000000000178 R E 0x10000 >> LOAD 0x000000000000ffe8 0x000000000041ffe8 0x000000000041ffe8 >> 0x0000000000000000 0x0000000000000008 RW 0x10000 >> NOTE 0x0000000000000120 0x0000000000400120 0x0000000000400120 >> 0x0000000000000024 0x0000000000000024 R 0x4 >> GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 >> 0x0000000000000000 0x0000000000000000 RW 0x10 >> >> As an additional test I've added a bunch of zeros at the end of that binary >> so that the offset is within that file and it did load just fine. >> >> On the other hand there is this section header: >> [ 4] .bss NOBITS 000000000041ffe8 0000ffe8 >> 0000000000000008 0000000000000000 WA 0 0 1 >> >> "sh_offset >> This member's value gives the byte offset from the beginning of the file to >> the first byte in the section. One section type, SHT_NOBITS described >> below, occupies no space in the file, and its sh_offset member locates >> the conceptual placement in the file. >> " >> >> So, still not sure what to do here.. >> >> Sebastian >> >> [0] https://lore.kernel.org/lkml/5d49767a-fbdc-fbe7-5fb2-d99ece3168cb@redhat.com/ > > I think that .bss section that is being generated is atrocious. > > At the same time I looked at what the linux elf loader is trying to do, > and the elf loader's handling of program segments with memsz > filesz > has serious remnants a.out of programs allocating memory with the brk > syscall. > > Lots of the structure looks like it started with the assumption that > there would only be a single program header with memsz > filesz the way > and that was the .bss. The way things were in the a.out days and > handling of other cases has been debugged in later. > > So I have modified elf_map to always return successfully when there is > a zero filesz in the program header for an elf segment. > > Then I have factored out a function clear_tail that ensures the zero > padding for an entire elf segment is present. > > Please test this and see if it causes your test case to work. Sadly, that causes issues for other programs: [ 44.164596] Run /init as init process [ 44.168763] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b [ 44.176409] CPU: 32 PID: 1 Comm: init Not tainted 6.6.0-rc2+ #89 [ 44.182404] Hardware name: GIGABYTE R181-T92-00/MT91-FS4-00, BIOS F34 08/13/2020 [ 44.189786] Call trace: [ 44.192220] dump_backtrace+0xa4/0x130 [ 44.195961] show_stack+0x20/0x38 [ 44.199264] dump_stack_lvl+0x48/0x60 [ 44.202917] dump_stack+0x18/0x28 [ 44.206219] panic+0x2e0/0x350 [ 44.209264] do_exit+0x370/0x390 [ 44.212481] do_group_exit+0x3c/0xa0 [ 44.216044] get_signal+0x800/0x808 [ 44.219521] do_signal+0xfc/0x200 [ 44.222824] do_notify_resume+0xc8/0x418 [ 44.226734] el0_da+0x114/0x120 [ 44.229866] el0t_64_sync_handler+0xb8/0x130 [ 44.234124] el0t_64_sync+0x194/0x198 [ 44.237776] SMP: stopping secondary CPUs [ 44.241740] Kernel Offset: disabled [ 44.245215] CPU features: 0x03000000,14028142,10004203 [ 44.250342] Memory Limit: none [ 44.253383] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---