From patchwork Tue Oct 29 21:13:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11218609 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5FA91599 for ; Tue, 29 Oct 2019 21:22:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 60BD42087F for ; Tue, 29 Oct 2019 21:22:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nk4Rl6km"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SwWBWcGn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60BD42087F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ZB9F1UwoKQEjorFvMYTfPcOwUVpYEHYuP7sB+Qs+W/0=; b=nk4Rl6kmWcpQO4XyqOyOmnP2EX zVPHJFUby4K6eac61n3nhOfFHnW9EQ+DKhD5arH8DvaRFgGNzE7K5EGe5pKilybjD3EftCVMWI2jh 78BOFfbO6mrDhM4vA7n4X1Z16ODaAsCPVldodnypiZNxk2MA21zFMoAWgj00Qd9aUQ8oLt/NmAInx TNh5+JiSCeteAnh0Ry8p8Yf0wvIJoON+VAy5AzvGZYWAIUCvnKaeLsx7zHUDsgwm0Gn8UtgsP8XnF JSbb5m47IICM+irztO1Wd2M5XbTJatgMXuQo98hEpgYapsn4mFxowci5tfJkJxB4MKwuwKCB3EdFP p5Fk8amw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPYwz-0005Pz-Pm; Tue, 29 Oct 2019 21:22:49 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPYuv-0003om-Nx for linux-arm-kernel@lists.infradead.org; Tue, 29 Oct 2019 21:20:43 +0000 Received: by mail-pg1-x542.google.com with SMTP id l24so10503637pgh.10 for ; Tue, 29 Oct 2019 14:20:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CyoXOdP2RSQBzcYa2ar7sJXCOKRhNFJ5bhxtCWldzm0=; b=SwWBWcGnfRTErjye2RFJl7Aib5ngymVfhFI6SrLYhwbsvQk+AnQ9NuQ0+LRVqvGhgr zw5WrFykWhH4hCt8QM/JyvhkKumTwsec+ev1e+K6Fcbb1EtKhpHRegK8vb6OM957Q9ZO UG1x/M3i2lCnML1VAM/x8BtKr539SsfdQUXrk= 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; bh=CyoXOdP2RSQBzcYa2ar7sJXCOKRhNFJ5bhxtCWldzm0=; b=Ql/+vI3gdOZmjGtVMfB9rqwJmdLeCW44BUjoq6gJ6u/26mWEFepJxb6UrpQKvoPb/+ LDFRVECdDP0XJ+fWyEshcJ/zpKFGLsDAHBDskAAipnqQDaNUMBvx1FlGyMjzxwyjj0FT NKs7wOcv6UorzVuLHxi/ORWckMLxFO3EjE3vtCwXTNhXnw96uvzuPT55tYUWt4rAk5nj YHs1epbjZ9eZHaoBjf/yDo/CpaQdeWEchqJNJdH7nVHUYZsJHozMJ2TBApIwia+8fZQB eadPncoyTbtN4Ck3miMflvsNsmKDZNnh/krNwrUuVA7xWi4WEvyY2RlRebwdBOG4ecYC um6g== X-Gm-Message-State: APjAAAUARjm3l8N0BIae8YbDwLw85cc+6v0EPsMqOALl8UXmIz4WOfVb eox2nm4sNza7GZcqq+xLOq9FdQ== X-Google-Smtp-Source: APXvYqwBFdMf1cjARJwLnvFrBgEj47UdUQleXizVAEOutN03LaOfJJkqIZHBJa1HNFPv6Xbz9E2F0A== X-Received: by 2002:a63:cf4a:: with SMTP id b10mr28208584pgj.86.1572384040153; Tue, 29 Oct 2019 14:20:40 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 65sm52280pfv.50.2019.10.29.14.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2019 14:20:38 -0700 (PDT) From: Kees Cook To: Borislav Petkov Subject: [PATCH v3 27/29] x86/mm: Report which part of kernel image is freed Date: Tue, 29 Oct 2019 14:13:49 -0700 Message-Id: <20191029211351.13243-28-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191029211351.13243-1-keescook@chromium.org> References: <20191029211351.13243-1-keescook@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_142042_028408_9CD728B8 X-CRM114-Status: GOOD ( 12.38 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:542 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, Michal Simek , linux-ia64@vger.kernel.org, Kees Cook , Arnd Bergmann , Michael Ellerman , Dave Hansen , Segher Boessenkool , linuxppc-dev@lists.ozlabs.org, Heiko Carstens , Yoshinori Sato , Andy Lutomirski , linux-alpha@vger.kernel.org, Rick Edgecombe , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-c6x-dev@linux-c6x.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The memory freeing report wasn't very useful for figuring out which parts of the kernel image were being freed. Add the details for clearer reporting in dmesg. Before: [ 2.150450] Freeing unused kernel image memory: 1348K [ 2.154574] Write protecting the kernel read-only data: 20480k [ 2.157641] Freeing unused kernel image memory: 2040K [ 2.158827] Freeing unused kernel image memory: 172K After: [ 2.329678] Freeing unused kernel image (initmem) memory: 1348K [ 2.331953] Write protecting the kernel read-only data: 20480k [ 2.335361] Freeing unused kernel image (text/rodata gap) memory: 2040K [ 2.336927] Freeing unused kernel image (rodata/data gap) memory: 172K Signed-off-by: Kees Cook --- arch/x86/include/asm/processor.h | 2 +- arch/x86/mm/init.c | 8 ++++---- arch/x86/mm/init_64.c | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 6e0a3b43d027..790f250d39a8 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -958,7 +958,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves) extern unsigned long arch_align_stack(unsigned long sp); void free_init_pages(const char *what, unsigned long begin, unsigned long end); -extern void free_kernel_image_pages(void *begin, void *end); +extern void free_kernel_image_pages(const char *what, void *begin, void *end); void default_idle(void); #ifdef CONFIG_XEN diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index fd10d91a6115..e7bb483557c9 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -829,14 +829,13 @@ void free_init_pages(const char *what, unsigned long begin, unsigned long end) * used for the kernel image only. free_init_pages() will do the * right thing for either kind of address. */ -void free_kernel_image_pages(void *begin, void *end) +void free_kernel_image_pages(const char *what, void *begin, void *end) { unsigned long begin_ul = (unsigned long)begin; unsigned long end_ul = (unsigned long)end; unsigned long len_pages = (end_ul - begin_ul) >> PAGE_SHIFT; - - free_init_pages("unused kernel image", begin_ul, end_ul); + free_init_pages(what, begin_ul, end_ul); /* * PTI maps some of the kernel into userspace. For performance, @@ -865,7 +864,8 @@ void __ref free_initmem(void) mem_encrypt_free_decrypted_mem(); - free_kernel_image_pages(&__init_begin, &__init_end); + free_kernel_image_pages("unused kernel image (initmem)", + &__init_begin, &__init_end); } #ifdef CONFIG_BLK_DEV_INITRD diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index e67ddca8b7a8..dcb9bc961b39 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1334,8 +1334,10 @@ void mark_rodata_ro(void) set_memory_ro(start, (end-start) >> PAGE_SHIFT); #endif - free_kernel_image_pages((void *)text_end, (void *)rodata_start); - free_kernel_image_pages((void *)rodata_end, (void *)_sdata); + free_kernel_image_pages("unused kernel image (text/rodata gap)", + (void *)text_end, (void *)rodata_start); + free_kernel_image_pages("unused kernel image (rodata/data gap)", + (void *)rodata_end, (void *)_sdata); debug_checkwx(); }