Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1194224pxa; Thu, 20 Aug 2020 05:18:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQPF4zw/BnnIj+5zjcflN2n3mKUqQq05V7cNxWDurJ1q64TTzGZDHs5Zr/xVbrFTZo67Mx X-Received: by 2002:a50:f311:: with SMTP id p17mr2710106edm.37.1597925884627; Thu, 20 Aug 2020 05:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597925884; cv=none; d=google.com; s=arc-20160816; b=OqoWadIgbyvNtacNRCkJ7NZeZcrcxzTRz1VmABGwNJYZytMuY5cR4n9AlTABYBglYU QFDH/fGG3KMH5pufCRFD9ftbsyR3RGdLuN28MxnWSwpQJBgEYd2SloeUj5TlTzp74Cf9 FRBTjN4J8DEay3u4Un0FI8zAHv/3G71cxoY7VdRwWpLOMjAGXccVuLzdMqNZ4odTY1i4 x8ZoC9z57q9p2C88YWeX6FGYzGyhJQgkLvtDYehD1griJKFWxim/ca2+hvZwdbcdF//r QTlsVbGrCEWdKcpmEdXAGEPy9L8TgurBLaWiuVjDG6k+d/4mLROif/gmim7l5giF+GHF X5HA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E59NGk1nvK+mbqbwu/TZ4OKtQ+h4xEyLr5Eno5oacwg=; b=REhOOvQxNhopUFrRAwGsvHrhxOtMXfk5+3Bs5CpY67azzC7O0PT/hQ72rERj7WO+VL pXaEamXoAn5Fa5khp1ON0E5vBGYtoW3oo7ePIq5jYpRQeJBkRUs45DS7u/ipc2IwLqZ2 LnhpROE9OX3Yna4eA9EgnB7w4gq6sPma+pfOkXjc/YRjc1D+eE7CBs+qiN4RClbeXaMw HCI643Kfwq6BxDg8hwqYMiYIyx7YenNx4c6lgmcV6YCm6Qssl0csvng04OUBmVI+zbYl mk5+DCe9kvwHFVhoxypWNs/lWHDl0Tp8chr/fd8fxFfzktFdecEvdfC4wVU1Vd4C98gH HreA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B9vQGaZJ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l14si1263014edv.603.2020.08.20.05.17.40; Thu, 20 Aug 2020 05:18:04 -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=@kernel.org header.s=default header.b=B9vQGaZJ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725834AbgHTMQn (ORCPT + 99 others); Thu, 20 Aug 2020 08:16:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:40160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728018AbgHTJ4k (ORCPT ); Thu, 20 Aug 2020 05:56:40 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 922682067C; Thu, 20 Aug 2020 09:56:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917399; bh=d2a5Hbbktp632+zIHqHVtSxvKpr65FFnZhZqKx3Udg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B9vQGaZJqRPBwofcHfBfn+fy2sU5Cpvo3inaW/H9OFHMccO9vGkuIDtviXB+6PkDF wc8xB1l6w5oMpTZGHtISDqh969K9Ksm+bsnMscgRqadZQvWukEidXCwtIBJd1gTPVL Sji3xurS9zdXM6U/ZtaWHOfDM/vZm6V/zKe9p3WU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joerg Roedel , Thomas Gleixner , Kees Cook , Sasha Levin Subject: [PATCH 4.9 018/212] x86, vmlinux.lds: Page-align end of ..page_aligned sections Date: Thu, 20 Aug 2020 11:19:51 +0200 Message-Id: <20200820091603.261226300@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091602.251285210@linuxfoundation.org> References: <20200820091602.251285210@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel [ Upstream commit de2b41be8fcccb2f5b6c480d35df590476344201 ] On x86-32 the idt_table with 256 entries needs only 2048 bytes. It is page-aligned, but the end of the .bss..page_aligned section is not guaranteed to be page-aligned. As a result, objects from other .bss sections may end up on the same 4k page as the idt_table, and will accidentially get mapped read-only during boot, causing unexpected page-faults when the kernel writes to them. This could be worked around by making the objects in the page aligned sections page sized, but that's wrong. Explicit sections which store only page aligned objects have an implicit guarantee that the object is alone in the page in which it is placed. That works for all objects except the last one. That's inconsistent. Enforcing page sized objects for these sections would wreckage memory sanitizers, because the object becomes artificially larger than it should be and out of bound access becomes legit. Align the end of the .bss..page_aligned and .data..page_aligned section on page-size so all objects places in these sections are guaranteed to have their own page. [ tglx: Amended changelog ] Signed-off-by: Joerg Roedel Signed-off-by: Thomas Gleixner Reviewed-by: Kees Cook Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20200721093448.10417-1-joro@8bytes.org Signed-off-by: Sasha Levin --- arch/x86/kernel/vmlinux.lds.S | 1 + include/asm-generic/vmlinux.lds.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 0df44e4fe7cb1..a1082dc61bb96 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -329,6 +329,7 @@ SECTIONS .bss : AT(ADDR(.bss) - LOAD_OFFSET) { __bss_start = .; *(.bss..page_aligned) + . = ALIGN(PAGE_SIZE); *(BSS_MAIN) . = ALIGN(PAGE_SIZE); __bss_stop = .; diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 1462071a19bf2..4fdb1d9848444 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -250,7 +250,8 @@ #define PAGE_ALIGNED_DATA(page_align) \ . = ALIGN(page_align); \ - *(.data..page_aligned) + *(.data..page_aligned) \ + . = ALIGN(page_align); #define READ_MOSTLY_DATA(align) \ . = ALIGN(align); \ @@ -625,7 +626,9 @@ . = ALIGN(bss_align); \ .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \ BSS_FIRST_SECTIONS \ + . = ALIGN(PAGE_SIZE); \ *(.bss..page_aligned) \ + . = ALIGN(PAGE_SIZE); \ *(.dynbss) \ *(BSS_MAIN) \ *(COMMON) \ -- 2.25.1