From patchwork Sat Nov 28 11:59:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Topi Miettinen X-Patchwork-Id: 41230 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B0883972C29; Sat, 28 Nov 2020 12:00:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B0883972C29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606564814; bh=bjVJiQs0V9IHsXT3wCLjR0xcQXBuaf6pRb5Q/9maPeg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=oDMB/MvpS+WdWPhsBWTCZb3gAaZ2rY3KplCcinkUw9lMqE+vLuRGb39H4USSqiNaP aHrupW7YkncbWXnSpXx8/ljErXBablKUjpuO2sb+ruZ2b+AUa+UZJ56ePl51T8mZo5 6CfAcfWZQfrv2y6Qa/Kx+k2UqAH101zlMfFsaIJE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by sourceware.org (Postfix) with ESMTPS id 6F5DF38618D4 for ; Sat, 28 Nov 2020 12:00:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6F5DF38618D4 Received: by mail-lj1-x241.google.com with SMTP id f18so8985602ljg.9 for ; Sat, 28 Nov 2020 04:00:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bjVJiQs0V9IHsXT3wCLjR0xcQXBuaf6pRb5Q/9maPeg=; b=OaTYwf6qtVeYeQJyJALimeAf1yLhECknYAFUn29E05urHp5udzDJxZ3mjUBXBUWT6q S/znpbiS5f7THBR5dDJBOXEdIDV+/1dev022SNakRgFIe9cNC5fpxQDJn7uWL3B+5yax 6PwCLfDqmy32NDdymc4QhCyujkzdfTAQRGkETXGb8UZ74jo/W1A1fuOB4Kthi2KAB33X tLzWiFW3Q5srV0/ePl5sI5E6w33rnsFfNES/17s+Zq7mJ75Jq+0CZ8hqyttdPFk+FuDV 5nhBB1VjWj9O9e1w0aYPP6h+xI3t3hKn+dU46DHwKW2FHMXesufULQlEuSDdsS/a7xlb iZSQ== X-Gm-Message-State: AOAM531PhsRicZ4N1nPPRzJ6FXCKukW7vrbv51YHLVx3wSoyIbPN5pbb aJP8TaN6OcSFqRlzYHigkSbXyezwv004kQ== X-Google-Smtp-Source: ABdhPJxYQGC/QMQ+tNZ750+ux7TwLNNeEml09lUWM8UFoJsJa1XLMbs71YHS5TRlKmukhEcZ5IlyfA== X-Received: by 2002:a2e:86d2:: with SMTP id n18mr52810ljj.26.1606564805067; Sat, 28 Nov 2020 04:00:05 -0800 (PST) Received: from localhost.localdomain (88-114-211-119.elisa-laajakaista.fi. [88.114.211.119]) by smtp.gmail.com with ESMTPSA id w28sm1055145lfk.8.2020.11.28.04.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2020 04:00:04 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 4/4] tunables: use mmap() instead of sbrk() Date: Sat, 28 Nov 2020 13:59:45 +0200 Message-Id: <20201128115945.42732-5-toiwoton@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201128115945.42732-1-toiwoton@gmail.com> References: <20201128115945.42732-1-toiwoton@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Topi Miettinen via Libc-alpha From: Topi Miettinen Reply-To: Topi Miettinen Cc: Topi Miettinen Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Randomize the location of copy of tunable environment variable, at the cost of losing up to 4095 bytes. --- elf/dl-tunables.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c index 2ba2844075..4ca15eb30f 100644 --- a/elf/dl-tunables.c +++ b/elf/dl-tunables.c @@ -43,13 +43,16 @@ tunables_strdup (const char *in) size_t i = 0; while (in[i++] != '\0'); - char *out = __sbrk (i); + + int error = 0; + char *out = __mmap_noerrno (NULL, ALIGN_UP (i, GLRO(dl_pagesize)), PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0, &error); /* For most of the tunables code, we ignore user errors. However, this is a system error - and running out of memory at program startup should be reported, so we do. */ - if (out == (void *)-1) - _dl_fatal_printf ("sbrk() failure while processing tunables\n"); + if (error || out == MAP_FAILED) + _dl_fatal_printf ("mmap() failure while processing tunables\n"); i--;