From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yVJXC2h1NzDr5J for ; Mon, 6 Nov 2017 01:50:33 +1100 (AEDT) Subject: Re: POWER: Unexpected fault when writing to brk-allocated memory To: Nicholas Piggin , "Aneesh Kumar K . V" Cc: linuxppc-dev@lists.ozlabs.org, linux-mm References: <20171105231850.5e313e46@roar.ozlabs.ibm.com> From: Florian Weimer Message-ID: <6d293bb3-78bd-6d20-3684-be6358bd3d7b@redhat.com> Date: Sun, 5 Nov 2017 15:50:28 +0100 MIME-Version: 1.0 In-Reply-To: <20171105231850.5e313e46@roar.ozlabs.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 11/05/2017 01:18 PM, Nicholas Piggin wrote: > Something like the following patch may help if you could test. The patch appears to fix it: # /lib64/ld64.so.1 ./a.out initial brk value: 0x7fffe4590000 probing at 0x80000001fffc I used the follow simplified reproducer: #include #include #include #include #include int main (void) { errno = 0; void *p = sbrk (0); if (errno != 0) err (1, "sbrk (0)"); printf ("initial brk value: %p\n", p); unsigned long long target = 0x800000020000ULL; if ((uintptr_t) p >= target) errx (1, "initial brk value is already above target"); unsigned long long increment = target - (uintptr_t) p; errno = 0; sbrk (increment); if (errno != 0) err (1, "sbrk (0x%llx)", increment); volatile int *pi = (volatile int *) (target - 4); printf ("probing at %p\n", pi); *pi = 1; } It is still probabilistic because if the increment is too large, the second sbrk call will fail with an out of memory error (which is expected), so you'll have to run it a couple of times. If the test fails, the write at the will segfault. Thanks, Florian