Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp684077pxx; Wed, 28 Oct 2020 14:24:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgcjjnYbWC8Yvk+HngGC3k3uM42y+s1w5RTx3KIp2+5pr6KguOo7DJcPZjyTfPJD7/bGWD X-Received: by 2002:a17:906:745:: with SMTP id z5mr1103871ejb.408.1603920271739; Wed, 28 Oct 2020 14:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603920271; cv=none; d=google.com; s=arc-20160816; b=en+uh0BNfUK32D2gHSuEZgzmvOjGii3qRIFaLobVEDzo38Vm5JIoT40uY5okbShKWz bMLKpHkedcGz6/KyEx7TimwTmZ7W56fDrJRuiqYtZdsHpyMAGLRjqHiGdS4mmKmavQA4 azwDpSs3avbECUpPQCRb6c+G7ZCni/uvx62ooNjODP7r+W5NOM3+z3zoqAyBB/1ni1Xb 8k1tHB2qhZ6zHoRjWbpOaeF79ohbIJ4VY70Gj/sH+jiTEvlqaw7Y1qTSEy+co6BHgnjw XaOmPWjzhoZuqM/Ng9B468JQG5FcliOd6bKmZf/kZjMCHBzZ1D2/utqrel+jmGT0CCjn Lo4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+i5e7y4zrzzXLxL+wnxdCVox1HHvWMsATZ7U/XZnHdA=; b=O6qJnFPsrFJIaaj8t82d7ugfRQhNoCd3zi0Hjru2Ma/H4rk9VS+UNyZNJj1t1585dF H3g4lqdc5FBjWAqkfP2Kbpm5RlaWSeXy0ChUWtvoyTTSg1FInsBZzcusf4trqb7Lr6/O P4IMq90I4wPKZBijwSR4HBOROfTSPMqMtmUm+LWjkcyDI447MP8VTNq+ue7EhAusKzBe bLEEBdkkmjkJobI+D0ifT75nqA9tIn+2KglZqL6bYlRI5Me+L/BPpw18xQcU5rgY0w37 g4O0NEP+e1tZRpQh5cgHXH+tMX7KmQ0abXGcFgwkcj4FR1mMDFgDJ+6dlObZy0tnxQ3I AiPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="Mkla+x/U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay1si32292edb.3.2020.10.28.14.24.08; Wed, 28 Oct 2020 14:24:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="Mkla+x/U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1830913AbgJ0UIN (ORCPT + 99 others); Tue, 27 Oct 2020 16:08:13 -0400 Received: from mail.skyhub.de ([5.9.137.197]:55130 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504820AbgJ0UIM (ORCPT ); Tue, 27 Oct 2020 16:08:12 -0400 Received: from zn.tnic (p200300ec2f0dae0027de8a0d2c2515c8.dip0.t-ipconnect.de [IPv6:2003:ec:2f0d:ae00:27de:8a0d:2c25:15c8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id AF33A1EC03C1; Tue, 27 Oct 2020 21:08:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1603829290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=+i5e7y4zrzzXLxL+wnxdCVox1HHvWMsATZ7U/XZnHdA=; b=Mkla+x/UCwglP/js+4HkoEspPrCtO4l/TZWsSuX3Ywdn1ccMJyrMVZD9U4N4c5p112N5oK 0DqMjlh8YVSHF9d00O3KRmNHWudyp2quh2erQ4sSFPwOqG98JzKPdwFSYtVo3IhR9UH7+v SEk+jvSTfKBhoPhdiBnyMXqGeqvTIoE= Date: Tue, 27 Oct 2020 21:08:03 +0100 From: Borislav Petkov To: Arvind Sankar Cc: x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/build: Fix vmlinux size check on 64-bit Message-ID: <20201027200803.GL15580@zn.tnic> References: <20201005151539.2214095-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201005151539.2214095-1-nivedita@alum.mit.edu> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 05, 2020 at 11:15:39AM -0400, Arvind Sankar wrote: > Commit b4e0409a36f4 ("x86: check vmlinux limits, 64-bit") added a check > that the size of the 64-bit kernel is less than KERNEL_IMAGE_SIZE. > > The check uses (_end - _text), but this is not enough. The initial PMD > used in startup_64() (level2_kernel_pgt) can only map upto > KERNEL_IMAGE_SIZE from __START_KERNEL_map, not from _text. > > The correct check is the same as for 32-bit, since LOAD_OFFSET is > defined appropriately for the two architectures. Just check > (_end - LOAD_OFFSET) against KERNEL_IMAGE_SIZE unconditionally. > > Signed-off-by: Arvind Sankar > --- > arch/x86/kernel/vmlinux.lds.S | 11 ++--------- > 1 file changed, 2 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S > index bf9e0adb5b7e..b38832821b98 100644 > --- a/arch/x86/kernel/vmlinux.lds.S > +++ b/arch/x86/kernel/vmlinux.lds.S > @@ -454,13 +454,12 @@ SECTIONS > ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!") > } > > -#ifdef CONFIG_X86_32 > /* > * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility: > */ > . = ASSERT((_end - LOAD_OFFSET <= KERNEL_IMAGE_SIZE), > "kernel image bigger than KERNEL_IMAGE_SIZE"); > -#else > +#ifdef CONFIG_X86_64 > /* > * Per-cpu symbols which need to be offset from __per_cpu_load > * for the boot processor. > @@ -470,18 +469,12 @@ INIT_PER_CPU(gdt_page); > INIT_PER_CPU(fixed_percpu_data); > INIT_PER_CPU(irq_stack_backing_store); > > -/* > - * Build-time check on the image size: > - */ > -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE), > - "kernel image bigger than KERNEL_IMAGE_SIZE"); So we have this: SECTIONS { #ifdef CONFIG_X86_32 . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR; phys_startup_32 = ABSOLUTE(startup_32 - LOAD_OFFSET); #else . = __START_KERNEL; ^^^^^^^^^^ which sets the location counter to #define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START) which is 0xffffffff80000000 + ALIGN(CONFIG_PHYSICAL_START, CONFIG_PHYSICAL_ALIGN) and that second term after the '+' has effect only when CONFIG_RELOCATABLE=n and that's not really used on modern kernel configs as RELOCATABLE is selected by EFI_STUB and RANDOMIZE_BASE depends on at and and ... So IOW, in a usual .config we have: __START_KERNEL_map at 0xffffffff80000000 _text at 0xffffffff81000000 So practically and for the majority of configs, the kernel image really does start at _text and not at __START_KERNEL_map and we map 16Mb which is 4 PMDs of unused pages. So basically you're correcting that here - that the number tested against KERNEL_IMAGE_SIZE is 16Mb more. Yes, no? Or am I missing some more important aspect and this is more than just a small correctness fixlet? Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette