Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1397514pxb; Wed, 2 Feb 2022 04:10:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0gvCKCSdKBR0FZvy431QJ0WjPDJSOlE6iRa4yvlyAT2t6kUsmkM7euaCwlF9AH3NRhsJJ X-Received: by 2002:a17:902:ed85:: with SMTP id e5mr29482934plj.46.1643803844654; Wed, 02 Feb 2022 04:10:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643803844; cv=none; d=google.com; s=arc-20160816; b=dXVftP73LsuMDoKrKM6IrZBfasOoMt0V64fvjgDHr7RU+EwJ2CeE4eLU6K3hDoToQL P8gj/DLLeiBdJWvbaqLV724Zknxk1j6z1J0eajPlln75acgmX3fe6ATQ9l8MSQHz7BVM Z7tzKD9Ty8jede3AED0GVeh62Lp1XfJxIIAXHPKqc2gULU9sSk01iHL1gLQvy/PDq98I LX9wwtflltqBYHKiinODDpU1z9+zHy8BnY8Ffg5ENm6v59o+rZj8Q8SoY4KBQgczr9qv afKFNI2ZOg35ox7oWGgZ/TQXtbqeU3Me24mDPLdeULltUXWbDfGDvHImWR7sQp/vKYOP W5pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vx2vjMlyUXttsNTU/sc6P+/T6SMZYpnVRGM83+IEnII=; b=nk9OcNEy6jKf7N5YJaeUoE8ZLN8VNXqUjtUGY8rJM4CFTrMkqV9aF6eyIJXe19ZZVg OYuZY+Oc93zIEPfxRmCPWOZVt60l4L9Sv9BntKassikkXSezxQIY/78wNe6E+aZekJ3z x4p88wvEhWQdzLs56GKseBCiHsa8xuq8Kt3s/J2eJmWQqLiJyER8hxCrh1WEGcfrMxYH YEDkV8c/6XhFRuIlObmjAMY5wyIb1hHl83y9qDdznX357zXbQLC+f8I7YHmGKmwftAHR BnuU1Wkrps2AAXvshZj/tZ/ozbWgurstLj8T+FFbqFXSjJgRydO90QW5xbM59a0XmeT/ eUFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kirnkQeZ; 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 x13si15548449pge.418.2022.02.02.04.10.30; Wed, 02 Feb 2022 04:10:44 -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=kirnkQeZ; 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 S238811AbiBANkf (ORCPT + 99 others); Tue, 1 Feb 2022 08:40:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234365AbiBANke (ORCPT ); Tue, 1 Feb 2022 08:40:34 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AFFDC061714 for ; Tue, 1 Feb 2022 05:40:34 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id g2so15311643pgo.9 for ; Tue, 01 Feb 2022 05:40:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vx2vjMlyUXttsNTU/sc6P+/T6SMZYpnVRGM83+IEnII=; b=kirnkQeZkeipuwVGTmeRoiNmR+fw3OankYxS5AXzlx+jExadifRtb4y62bwOq4LB6V y8PiPkDAgmRFKIghZO0BwJeNgOTyssyULiwdMM3fiGw0Blsg68mfTtu7nnjjO1j5FDAT OSjaIUFD5rSOreQr5pD9PmRhz7DkhxEo8eyjBr/iRKwmPmgMhBv1Jk9ueJ3RztTmdYua ikw5I+VujZ9FGwJUpvolpOvvYB2GUarBH7o4ezJ6r6v8Wd1PHsQdhZxil5Gkk0e9qBGr 3IqT+xh2/Cel2T+ucEmfGFbuC8DJ5IgG1T6UXE8ABGOyrQAd3PjjWhf5/VDU0LCM1wa+ SFQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vx2vjMlyUXttsNTU/sc6P+/T6SMZYpnVRGM83+IEnII=; b=YHAp5QhLfmISR/rtmA0VzCPXojuMHeQ8frlwbjY4VNjFfytcKwQBHM+zhmV6WQmacv 8wK3GUZtV9I1TdnCrDhR4X4ZI7/QJ+2k1+0UIK7SxulbDTXFkgycjVFV3iCr1tbJSB4q 5Xt4sZhVMj68NY2vw9ZKfoR/BdWq8kVznOHFrX7Se6h4Zb0fcw/FOVpTE3oStywk0kIW dVkZIUtryHwkoZ5ak8BCtfmoIy/dwWJyBV5MYKUXQnwn38liACHER9jd5Fy8xgWbzAwY /oI0LEf0jdppaocyi5GAP5CsKJinr46KzydTVW8/ds7Eyy7k3IOtIEzTG60KdkmTj6tC gKFg== X-Gm-Message-State: AOAM5333d0NWUUM14CvpJL09dSjr2adWdr5jKPv0ohs68+cSJOzSfLaS DTF3WyLOTU5hrVYQn15SfWlDP/1sEEdBK2B2cIg= X-Received: by 2002:a63:3e8b:: with SMTP id l133mr20407349pga.210.1643722833675; Tue, 01 Feb 2022 05:40:33 -0800 (PST) MIME-Version: 1.0 References: <20220131201716.5198-1-a3at.mail@gmail.com> <20220201061832.yatgwglxvi7ho4yr@carbon.azat> <20220201132807.m7xtogotjlg54pzl@carbon.azat> In-Reply-To: <20220201132807.m7xtogotjlg54pzl@carbon.azat> From: "H.J. Lu" Date: Tue, 1 Feb 2022 05:39:57 -0800 Message-ID: Subject: Re: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries To: Azat Khuzhin 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 1, 2022 at 5:28 AM Azat Khuzhin wrote: > > On Tue, Feb 01, 2022 at 05:15:38AM -0800, H.J. Lu wrote: > > On Mon, Jan 31, 2022 at 10:18 PM Azat Khuzhin wrote: > > > > > > 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. > > > > The reproducer doesn't fail for me under 5.17-rc2 on Fedora 35/x86-64 > > with 32GB RAM. Did you turn off PF_RANDOMIZE? > > Oh, yep, forgot to mention that I have kernel.randomize_va_space=0. PIE with interpreter and PIE with alignment > ELF_MIN_ALIGN should always be loaded from ELF_ET_DYN_BASE. Otherwise, either PIE is loaded at an address which is too low or isn't properly aligned. -- H.J.