Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2697647pxb; Thu, 3 Feb 2022 12:10:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKUPuCM7LfSoMufMq6qv7OlzmDXmB/pCiOp8/smPaBAWlwFcWl+2E+h01QfAzGYXO7lWaX X-Received: by 2002:a63:6882:: with SMTP id d124mr29229868pgc.305.1643919056826; Thu, 03 Feb 2022 12:10:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643919056; cv=none; d=google.com; s=arc-20160816; b=GEYDT48bfqVNJ4ewWZGVoPng5Hd/g5PgCD+OyBN/lJ8W38kRdtuDqzWTWSuDhFUThC HXp23WCWaGPEDRduwuOJHPoS6RTR3dONHqIJXUZlAEsa4NNYEChuAzz6vEWotux9Zm2f S7R1T2ebUjLZPXtdAHHr1SjnkpqbFSxstQmZL9lfcJIAusvNt6GpIkq6rA5P4fulkZtM 1QOWk6VE4nxv3449TqgMUOzOFTP/f+PEzetJKe+CwLaAyHYFu4vtG9axAoNi3nuwYIby 0QSO8JoP+Ok0r20RlAKG7FeaIFeUETz39IMHmjaF1P4yHUFIckI88oCfhc2KIQY3vu/y 788A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3hEUlQM4dFF1likJfgdhXv9CdGZyb6v9vnQiScxWZYk=; b=XwR34Zg0eG3EGBKFV6ebbXlHrw19KniWBHdLa94C3eV0v6iGmerHYzBOwAw6yIn5Ot wLcXwQaNl2uDfav418Qq4JMzrP8BGwfrC4Fb5W0sOw1XonjAU9oceFWX4n978KDTS3zb O5qirIVgQun+kBpRDKkCOab4qRLtl4Iqd/3d1zkLpLu9xuar20qWb3URselUozACYIA5 mZsTs6bsBMSv2jzjqYgDLjMg0bf3dRepz4dphaUJ9UTjsX1ie9Iqlt1hzHBmQMI7FijL tV8EvwCbj6KVq1xot1FdL7iN8eeXWxbf1jgFucFh6mZMPEKXGUfrgfCRxzBUl2hhi0zu iNcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=O4r1+Q87; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1si25815855plk.424.2022.02.03.12.10.43; Thu, 03 Feb 2022 12:10:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=O4r1+Q87; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233916AbiBAGSh (ORCPT + 99 others); Tue, 1 Feb 2022 01:18:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232987AbiBAGSf (ORCPT ); Tue, 1 Feb 2022 01:18:35 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70E7CC061714 for ; Mon, 31 Jan 2022 22:18:35 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id z4so31675212lft.3 for ; Mon, 31 Jan 2022 22:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3hEUlQM4dFF1likJfgdhXv9CdGZyb6v9vnQiScxWZYk=; b=O4r1+Q879TfID7W4pIrexC8RQMXkBxxu+F/YAH8K9FEd3od9Bzv9tqiX8tgZ/NfcoC 7uW0L6V6cvdDuSsTkSkfJdN48CS5hpwPx9qu/Pei5/DXraHRrWpXABRF94DUS4P78CHk yKK0zn9USS9Lz2MJ5IpKyFwUWeajiClL3aO6zWtuO8aKJ1X1XCNVzBUvYaTWO+1uoqm4 bsStkB8MyDFU/t3BRiwHKwMD5s994q9O6mYuO0u4QwURHgz5C95v8eW05U35Rq6oY/dp 6dP08uzq1ZsVWGkPkhn5DpHP41ZYV4iZ/d6Ee0ydOXslOLk8q2E9SuH5mJ5ZXuQBATej CTDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3hEUlQM4dFF1likJfgdhXv9CdGZyb6v9vnQiScxWZYk=; b=2ZEE6OBZYLmt93LG37icW4tPlYF4Ob8FzgPXbFZleXlc6t+YXP9oR4VwngussjbV6P T4vJBB+gNuja6CqNqMh76vAmmu2809PPjDcybK2/jY+XfPQpOhdK5wz6ggev8IluJP4E 6cMZj7v0sA0qFup7rxctpeGqHWwvS8JiTtKMkV1nygVNSQwDIYPDcOzf9Ez4v/lHUnwP RdRfBetsGnD4mCPe5goGo9w0J58ZsJT/lAwiZpmW3OnRgXiYuKxqIb85E3BVVIEhPi1z jzeyw/x6Cc75kh6eEImWnk/HVM1nY03XFWALI3fEb/uCHYLDwTUn3kHIEpl4wtIVy+lX zLqA== X-Gm-Message-State: AOAM530fX6hrOavTRZZj8HzeYcZGGFmgnvSnCjhyZSUXER3pWOw6THWh wSer3ONs2LEoOFUmolqfKmiyE5xckWp1Yw== X-Received: by 2002:a05:6512:4014:: with SMTP id br20mr13309465lfb.217.1643696313584; Mon, 31 Jan 2022 22:18:33 -0800 (PST) Received: from localhost ([146.66.199.134]) by smtp.gmail.com with ESMTPSA id bj13sm892449ljb.140.2022.01.31.22.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 22:18:33 -0800 (PST) Date: Tue, 1 Feb 2022 09:18:32 +0300 From: Azat Khuzhin To: "H.J. Lu" Cc: LKML , Chris Kennelly , Al Viro , Alexey Dobriyan , Song Liu , David Rientjes , Ian Rogers , Hugh Dickins , Suren Baghdasaryan , Sandeep Patil , Fangrui Song , Nick Desaulniers , "Kirill A . Shutemov" , Mike Kravetz , Shuah Khan Subject: Re: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries Message-ID: <20220201061832.yatgwglxvi7ho4yr@carbon.azat> References: <20220131201716.5198-1-a3at.mail@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 31, 2022 at 01:30:38PM -0800, H.J. Lu wrote: > On Mon, Jan 31, 2022 at 12:17 PM Azat Khuzhin wrote: > > > > Since 9630f0d60fec ELF_ET_DYN_BASE is not used as a load_bias anymore > > and this breaks PIE binaries, since after this change data segment > > became too nearby the stack: > > > > Before 9630f0d60fec: > > > > $ strace -febrk /tmp/test-stack |& head > > brk(NULL) = 0x555555559000 > > $ /tmp/test-stack > > bottom_of_stack = 0x7fffffffc5c0 > > recursion depth: 1 (stack diff: 32) > > ... > > recursion depth: 7690 (stack diff: 8365664) > > Segmentation fault (core dumped) > > > > After 9630f0d60fec: > > > > $ strace -ebrk /tmp/test-stack |& head > > brk(NULL) = 0x7ffff7fff000 > > > > $ /tmp/test-stack > > bottom_of_stack = 0x7fffffffc640 > > recursion depth: 1 (stack diff: 32) > > ... > > recursion depth: 146 (stack diff: 157792) > > Segmentation fault (core dumped) > > > > Found this during compiling with clang, that started to randomly > > SIGSEGV when it eats some heap. > > How do I reproduce it on x86-64? It fails for me for pretty big C++ unit, so I don't have a simple reproducer with clang, but the attached reproducer below should show the problem. > > Reproducer: > > > > #include > > #include > > #include > > > > static int depth = 0; > > static void* bottom_of_stack; > > > > int inner() > > { > > char buffer[1024]; > > ptrdiff_t diff; > > int ret; > > > > ++depth; > > diff = bottom_of_stack - __builtin_frame_address(0); > > > > fprintf(stderr, > > "recursion depth: %i (stack diff: %zu)\n", > > depth, (size_t)diff); > > > > for (size_t i = 0; i < 1024; ++i) > > ret += buffer[i]; > > > > ret += inner(); > > > > return ret; > > } > > > > int main() > > { > > for (size_t size = 0; size < 128<<20; size += 16<<10) > > malloc(16<<10); > > > > bottom_of_stack = __builtin_frame_address(0); > > fprintf(stderr, "bottom_of_stack = %p\n", bottom_of_stack); > > inner(); > > }