Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4266112rdb; Thu, 14 Sep 2023 18:00:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxLCnXjm4FUPw1Sc1tZ03cNBTEt5hKxXcFZv1i/3n8OiU7ecEqagZ9fo0ga9PTPuclfs5t X-Received: by 2002:a05:6a00:2446:b0:68e:236a:93d9 with SMTP id d6-20020a056a00244600b0068e236a93d9mr243976pfj.17.1694739659103; Thu, 14 Sep 2023 18:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694739659; cv=none; d=google.com; s=arc-20160816; b=BpsRXL2q65Z8HZcVnHYq5HoFyARuqAtnhCu/0muWK7Rior43yO5/ga9XhIzhK31Wur RhxtB5FCHWkCGYtVSmuMBfBQM6FDIF06M5wDBH6pK6Ci/68qbDVxfFt4+v7kH5mmRKzD F29fJRF8K9s7XwEWZfGG6rV7NqjHcx9g7BItbzbXbVb0r+BvSo+JbwLev0n8QFmSqHfQ XbaPVRG+WXyfCyo1UN8OdBGqIxnhOWHjTXutwbehAz82SGONarOpup4hv3LrHOfTDadk npc/XdMXkv11ChOt1aDQ8s4ad+JQbqElb8pvmr/2QjFNhZ8LoWWtyJUthZZ9IxQRrRo6 5H3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=XxWXfGTVP4QY+3yA3U7GjqYmRXsjsPRI9eO9Cr8CCt8=; fh=TWa1ukrMv5dvji1A+tjGbpswLpsQeAjwu/Dstihz3lo=; b=E9KHaAiu4aWE0IoD4ygIwmo9l07DL1Vl1twaNzinF7UFNWa2gb9g6i8/HdOr2qdLr/ J0WSG46Nz09CkDsQNaPJowiP1d2Y2RKRTJkzCkd/0r7HsM92OlE7WsfTgJVfwyls6yid 6r8n2PLqFCChQVlcgatR7vehxqid4qq6zEfGqObxuFX/gV4MkaimAPagY5Rkx35kzKoQ XQdz4OvZw9rGcwH0NohomF+A3TILkWLxKnUzCktt+sugfr3QywaceiQZ1ahrTsi2ml7H +lxjc8rt6CbYnar2K2hoDFMLonW3aKap4z89HuJLD47oFJS78fLJu5seulwP++SlpJs6 jS6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=g2rkURrG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id e20-20020a056a001a9400b0069018a768d7si2479051pfv.385.2023.09.14.18.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 18:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=g2rkURrG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id B5A5982B9F86; Thu, 14 Sep 2023 08:59:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241311AbjINP7n (ORCPT + 99 others); Thu, 14 Sep 2023 11:59:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240667AbjINP7m (ORCPT ); Thu, 14 Sep 2023 11:59:42 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31B3B1BDD; Thu, 14 Sep 2023 08:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1694707175; bh=Xy4oeT6FjD8v9CNOFPDcyJo8MblgPr/wtL46w5RATVs=; h=From:Date:Subject:To:Cc:From; b=g2rkURrGUFg0K+EhUVCYp685HNlgScL0D2NzEVczWqYwfzzi/rc6T5Vn9Yby0Xy7r DwYlgXlIhIgLE/VU0l/udDlI59wIy+ytT6mnHylWjJAEBk4lzAjWvAfXxcnoQq13ow CIw5EuBzT+MCNAHJuV7B1xBVr7WC/I4Xz7WsulX0= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 14 Sep 2023 17:59:21 +0200 Subject: [PATCH RFC] binfmt_elf: fully allocate bss pages MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20230914-bss-alloc-v1-1-78de67d2c6dd@weissschuh.net> X-B4-Tracking: v=1; b=H4sIANgtA2UC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI2MDS0MT3aTiYt3EnJz8ZN00UyPjtEQzQ3NDi2QloPqCotS0zAqwWdFKQW7 OSrG1tQBPM4vQYAAAAA== To: Alexander Viro , Christian Brauner , Eric Biederman , Kees Cook Cc: Mark Brown , Willy Tarreau , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sebastian Ott , stable@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1694707174; l=2558; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Xy4oeT6FjD8v9CNOFPDcyJo8MblgPr/wtL46w5RATVs=; b=dTmJBTY1kUzVp+M5Za8hnGEaOf2h8wZGp7RZPk+6qvGpvWNyDehekRbLjiD5C3wwkK8yAX1ss O3djcKTCYWTBg81Hxaq4IjMd6XfZUwlec4bCQ7Bj9DnYzPrJupLCwi8 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 14 Sep 2023 08:59:44 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email When allocating the pages for bss the start address needs to be rounded down instead of up. Otherwise the start of the bss segment may be unmapped. The was reported to happen on Aarch64: Memory allocated by set_brk(): Before: start=0x420000 end=0x420000 After: start=0x41f000 end=0x420000 The triggering binary looks like this: Elf file type is EXEC (Executable file) Entry point 0x400144 There are 4 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 0x0000000000000178 0x0000000000000178 R E 0x10000 LOAD 0x000000000000ffe8 0x000000000041ffe8 0x000000000041ffe8 0x0000000000000000 0x0000000000000008 RW 0x10000 NOTE 0x0000000000000120 0x0000000000400120 0x0000000000400120 0x0000000000000024 0x0000000000000024 R 0x4 GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 RW 0x10 Section to Segment mapping: Segment Sections... 00 .note.gnu.build-id .text .eh_frame 01 .bss 02 .note.gnu.build-id 03 Reported-by: Sebastian Ott Closes: https://lore.kernel.org/lkml/5d49767a-fbdc-fbe7-5fb2-d99ece3168cb@redhat.com/ Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Thomas Weißschuh --- I'm not really familiar with the ELF loading process, so putting this out as RFC. A example binary compiled with aarch64-linux-gnu-gcc 13.2.0 is available at https://test.t-8ch.de/binfmt-bss-repro.bin --- fs/binfmt_elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 7b3d2d491407..4008a57d388b 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -112,7 +112,7 @@ static struct linux_binfmt elf_format = { static int set_brk(unsigned long start, unsigned long end, int prot) { - start = ELF_PAGEALIGN(start); + start = ELF_PAGESTART(start); end = ELF_PAGEALIGN(end); if (end > start) { /* --- base-commit: aed8aee11130a954356200afa3f1b8753e8a9482 change-id: 20230914-bss-alloc-f523fa61718c Best regards, -- Thomas Weißschuh