Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3177433pxb; Fri, 4 Feb 2022 03:06:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzu+R8pdHky9A/tORJ86l7EmTF1gcv2wM+tfDCrw84/lcLDRDfOcbJkUdmX0YZ49HlUm/qt X-Received: by 2002:a17:907:9688:: with SMTP id hd8mr2079388ejc.80.1643972809239; Fri, 04 Feb 2022 03:06:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643972809; cv=none; d=google.com; s=arc-20160816; b=hIHcZV8Cdtw9UQ4JHeM+gAYYws/M0RXSlIpZVXeEoDgLq+Skc9TkZ00a2iFFF/GSoN oW9LtObtx9LswPsk5SHhZSb+VXfIIaY3Zlh5aVpe6GTh4FqsP5uD1iyWguNmHlH4oU32 YNndCdycJg41kxktDHd8CVtAXFCiu0+6Q6/sXiimeYgf2SSdMY3sGTFyxE47B6+Ihf9A PkjO6F9QMVUTdj6CiK7pUPhWjtAfxD8lecy6nKKoeOMMCUO2qYDMdnPfG1aj/H/RoUIG T+H/LO05ehDTtBi4xBi0SGaA3mh0dYLyW5EJBuoeFYEAeFt+2H1zETvHTXNC3/fuiLMI Pb8A== 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=ksCYgL+3G+j9avSh44FJZlckNASik0bTPJz1BLZJ1iY=; b=Tqi7RuKwRxJ1Igvz21Vpn4l8KBC6fHWaE/GpU+aSrjJ2z/G3tc4ZTAgMJI8Qdl8bOX xsfRa91jy/N/Kcu8yWldDFLvueZkRfHrllMHm7cUPtECuX+yrgpETUe/fZhrj/egk6Oc A/qPlaJyMCrcW1tE/2oiONiD+ted89yBLjyZFoDrN2Jd2CXt5ZWhs/ODFYnJJtjLD944 YJf7EFfEBtfcBynSOs9i3fj4dfkDBD2pnzB63Bmc66cRX8yubJh7XxvDPeK+qCS7tAvf 2nxTCv5FEU2r8EmJkvZdrGSritRmUTh5XhfoaEuFixqlJkqmO9qafwYzlMIKy6ysDrke L+eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WrLORAoz; 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 s1si1294181ejn.33.2022.02.04.03.06.24; Fri, 04 Feb 2022 03:06:49 -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=WrLORAoz; 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 S238422AbiBANQQ (ORCPT + 99 others); Tue, 1 Feb 2022 08:16:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238332AbiBANQP (ORCPT ); Tue, 1 Feb 2022 08:16:15 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1C03C061714 for ; Tue, 1 Feb 2022 05:16:15 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id h20-20020a17090adb9400b001b518bf99ffso2863218pjv.1 for ; Tue, 01 Feb 2022 05:16:15 -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=ksCYgL+3G+j9avSh44FJZlckNASik0bTPJz1BLZJ1iY=; b=WrLORAozns9nqKfWJE0RmkGcRAJ4bsY/NR7hTUmc9ksd0oFpyHwC8eO/J2XFksSXxz ejTpMykgL1Qq2UHt6zSujHFnHl64tNURmaaHWASNoVqHQGWgtSppjWNnenU608rbLcJB KPIN+yO51crgFI+xSfFWvrGS3reoRpiDOWl1J4bCA/vT/xrbZ6FsGGUYx6aGFCi8RtGS 5hlDyFyK+NZe3UxNuqrrZbQTgGo5lHhjojEC5k+ISgeJ9xRonHwLlMoKv+IZBaxawDHZ xHEDYZJsowsJTq/WzvvOMzGIF2OJfCsLW25rxGyHlIYOsVZ8CzPD7uSkBp/iIrkkze4r E2hQ== 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=ksCYgL+3G+j9avSh44FJZlckNASik0bTPJz1BLZJ1iY=; b=1wqA+MtO21qGpSgMF+Lm6nucpmyJndWPIu9Sj7MQhCiMThkAHGohdqJ55S812uSL61 yCkKqDgmPiiixYSBuPXqHaAgJkylGVygZAU7lWfjRjMFE7/pKSbgyf1Oaeq5G51evIpO 5nmIWSlAyum8pj+D1Q6hR3E0sBKgQeQkhrsiK6u8nuF81p5O/UtXOPnKRhEN2lVIKe3t A5mYQ6nI3mcPhH0JhgdjooyuypIB5xwtO2+2FYUa+54M/LGCKY1U5MxNOFKa0HX6Z0YU LIG8a3U6hxGShjVQ70Di+jkTJcimth/HbQ3jF454u2dixHej3/bzOPWQtzpUdmtHvFXw cv9g== X-Gm-Message-State: AOAM531ytgE789AX6za3dPiJhQOZ09Dj4lZf8GFb4TKid5h4PPP5jKzZ iKk7PPi9X+E8cWywEkojFC8y5lTqj84fwh1AjHs= X-Received: by 2002:a17:90b:4f83:: with SMTP id qe3mr2264212pjb.120.1643721374784; Tue, 01 Feb 2022 05:16:14 -0800 (PST) MIME-Version: 1.0 References: <20220131201716.5198-1-a3at.mail@gmail.com> <20220201061832.yatgwglxvi7ho4yr@carbon.azat> In-Reply-To: <20220201061832.yatgwglxvi7ho4yr@carbon.azat> From: "H.J. Lu" Date: Tue, 1 Feb 2022 05:15:38 -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 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? > > > 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(); > > > } -- H.J.