Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp199938ima; Fri, 1 Feb 2019 01:51:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN44v5dLOguMxr+3QwtDYqQHeFfLdKQ6Q8v2K4zvBmBcRV/98Em2Xawa6rztmP3Cv/JECiP6 X-Received: by 2002:a62:4549:: with SMTP id s70mr38206898pfa.233.1549014708097; Fri, 01 Feb 2019 01:51:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549014708; cv=none; d=google.com; s=arc-20160816; b=Fhz/wOj/vTgO/MF1ut0YHEZMnwXAQjwek32HGZflypPTgsMVeiRm/ERi93Qi6q/ySk K1JN6DCPhBZ+W48o9eyJI/z0RqDQlGdaevpbbkqmGDZa91XwjnemfKbXvpRB98OKLW5q qY4ly9s5q8sF69ekhJhpujrfGgpFgxknybs0G/WGy8S5zQg42MQOizachr6225zopWN+ vtNidR5fQ0fYxAjNRCtyDz+ck1iXRC9LgoPqEV/dI2xhiIM5RnFjJ4giBhCNI4yZIzci RVS61Xx5IS+rkxt+un4LQsqV7dC8SO2ZUhXIv4GHDsjZ2mH9EL2v1IJHPJ/YRWyQ9ayY 1Uug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=9HQshfyVGRws0MdboZyPdXjcmSt7YBRFEVxVfP0X5/E=; b=VjmzosnQCzTHUJhlqS64IdPkPOVpklslLjL9upoezlehI0On0yq+c4krVo2ItALi6i gif5aifh+Bj+izNGuIMlCHS4qFUVMY1nwc94SW56qNjQdoKUb8GStbpf6pD82RQ2xiVH qYj/BwHTZ2bFS223zvkN7Az+xB5BixY7b4PsxhAIAl3iOe6v6vdegS/3RKQWNlE0xUdG K8R1dnNc1/W5trYq9qcFn9ayqerPjVX/MhbkKJFSMHY1hqshA8DizYEEkzSVqqn0FdwW OH7C4fIuZHgsYpo2BLDiN7ImMgkdVZUXF2Lhhnac4rPVqGyPQJDORfFhM0k0xiHc9gvM v8YQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6si6983796pgc.137.2019.02.01.01.51.32; Fri, 01 Feb 2019 01:51:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729551AbfBAJl6 (ORCPT + 99 others); Fri, 1 Feb 2019 04:41:58 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:25412 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728565AbfBAJl5 (ORCPT ); Fri, 1 Feb 2019 04:41:57 -0500 X-IronPort-AV: E=Sophos;i="5.56,547,1539619200"; d="scan'208";a="53397825" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 01 Feb 2019 17:41:55 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 17D0E4C4BB9B; Fri, 1 Feb 2019 17:41:53 +0800 (CST) Received: from [10.167.226.60] (10.167.226.60) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 1 Feb 2019 17:41:54 +0800 Subject: Re: [PATCH] x86/boot: minor improvement in kaslr To: Kees Cook CC: LKML , X86 ML , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Baoquan He , Chao Fan References: <20190201054853.28541-1-caoj.fnst@cn.fujitsu.com> From: Cao jin Message-ID: <7463228f-3749-8cab-c727-433bba4131b4@cn.fujitsu.com> Date: Fri, 1 Feb 2019 17:41:50 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.167.226.60] X-yoursite-MailScanner-ID: 17D0E4C4BB9B.AD5B8 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: caoj.fnst@cn.fujitsu.com X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/1/19 4:20 PM, Kees Cook wrote: > On Fri, Feb 1, 2019 at 6:51 PM Cao jin wrote: >> >> comments fix: input_size is ZO image size which just don't count .bss >> in, but has .text, .data, etc; >> drop unecessary alignment: minimum is either 512M or output, both are >> CONFIG_PHYSICAL_ALIGN aligned(output is aligned in head_32/64.S). But >> mention it in earlier comments. >> >> Signed-off-by: Cao jin >> --- >> arch/x86/boot/compressed/kaslr.c | 9 +++------ >> 1 file changed, 3 insertions(+), 6 deletions(-) >> >> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c >> index 9ed9709d9947..a947c5aba34e 100644 >> --- a/arch/x86/boot/compressed/kaslr.c >> +++ b/arch/x86/boot/compressed/kaslr.c >> @@ -360,7 +360,7 @@ static void handle_mem_options(void) >> * (i.e. it does not include its run size). This range must be avoided >> * because it contains the data used for decompression. >> * >> - * [input+input_size, output+init_size) is [_text, _end) for ZO. This >> + * [input+input_size, output+init_size) is [_bss, _end) for ZO. This > > This isn't right. The comment was correct before. See > arch/x86/boot/compressed/vmlinux.lds.S for the layout of the ZO image: > after the compressed image is _text, _rodata, _got, _data, _bss, > _pgtable, and _end. "[_text, _end)" correctly identifies the span > used. > I am confused, doesn't input_size = ZO image size = .head.text + .rodata..compressed + .rodata + .got + .data + .pgtable ? As I know, .bss don't occupy any space in file, and ZO's full run size is against the end of buffer, so I think the tiny gap here is just .bss, which is also the stack and heap. Do I get it wrong? >> * range includes ZO's heap and stack, and must be avoided since it >> * performs the decompression. >> * >> @@ -763,9 +763,6 @@ static unsigned long find_random_phys_addr(unsigned long minimum, >> return 0; >> } >> >> - /* Make sure minimum is aligned. */ >> - minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN); >> - > > I would prefer to keep this runtime calculation since it enforces the > requirement instead of making leaving it in a comment. When this goes > wrong, you get an unbootable kernel, which is very frustrating to > debug. > I find that I maybe wrong here. It is said that CONFIG_PHYSICAL_ALIGN must be a multiple of 0x200000 on 64-bit, so it could be 2M, 4M, 6M, 8M, 12M, 14M, 16M, while 512M can't be divided by 6, 10, 12, 14 without remainder. -- Sincerely, Cao jin