Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4882143pjb; Mon, 27 Jul 2020 07:30:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrickX2Ao+FAnvo3p7acxjjSqVW+j4q+2vfPpFOxXvLqtI2I3txwTnrVw6D88dq4ynorqN X-Received: by 2002:a50:9fc9:: with SMTP id c67mr10732861edf.69.1595860258994; Mon, 27 Jul 2020 07:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860258; cv=none; d=google.com; s=arc-20160816; b=r0GquaWHI/560MnERfTa/iVOYFR78ew9Aa0NnVv6br56IWlJO4Q2ERZRtYPHDOfyya scaSw/OeLO6XVWh0G1kWLl4Qd7n7qPWyl/Jcx7vAVst/5bKWVRlrZuLiULL/oaeG4cg2 G8bZspzrFYFGbPIjJnRqOB7Mj6ES7cp7DI9ILqYAyVIGSh5xwhAZEktE+FgCj35gv5E4 B4kn9yIIrkHuLpdeombx2kTVuUc125CbFaGYn5wYuiofd4mmCBHBp38VDQLFS6q9+G0t 8aCu6ErcVyTNHxkpvqrqpk5rSW31tbs1hVXAvO45oUomc1tqhZ2DEM/m7m96FsE0A1RT 9b2Q== 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=0Bg/c74kWqJj/fVCiMXUEa0/QLnVgBuDsqolTVIftyI=; b=S0W3gGqRm72QzQEZrPu2HudYAD5udaO2hk2ik4H8I1lOe/tF37mOJdXQ6OY+lR3tMx OkHmXBchrqyUvCVW2TCoxvTL32LzhYDzQ8RNpf7LcWageOTl076xSblLlFl6vcJqETpo o4UWi3kim1I6RPT1lvSXLyWY+j6uKtqaQXl3UTBWBB4L98S1ZyjuNK7mIn8QBZFtNzT5 zhp2UrT6C/BL5ti6zff65K2ltBEFpWdN4puvyMw+Yv+xWfzBU9hoBCw1cceLU7R52z7O sS2fjblaarvBN7uQgopydKn3Ret1z2ifQE86c4UMmcWyIwlWVk2z73wmAuG/wR+W7XA1 JlDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PefvtI82; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r5si5477165edo.130.2020.07.27.07.30.37; Mon, 27 Jul 2020 07:30:58 -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=PefvtI82; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732544AbgG0O0C (ORCPT + 99 others); Mon, 27 Jul 2020 10:26:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:56188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731914AbgG0O0A (ORCPT ); Mon, 27 Jul 2020 10:26:00 -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 4994C20663; Mon, 27 Jul 2020 14:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859959; bh=3lp9F/q/UKq3lzCvqmcLxffs+qCnhmssQ3/hMtsRgNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PefvtI82D4DAUZKNSdzYbv6bqQ8sKuf1XSRmTvD+eCRtiekEuzhx6jq3hZr5jj5Ce A5RaagGMl4Z6AsOSuntQD2y4RFmxKcGcjyXXmsw7d2a4wT5Q61Gdg869G23xNcy1Ea tIDv1FZq8ApxJ9jLI+md1e3AqI3K7TRI2ILrumh4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joerg Roedel , Thomas Gleixner , Kees Cook Subject: [PATCH 5.7 171/179] x86, vmlinux.lds: Page-align end of ..page_aligned sections Date: Mon, 27 Jul 2020 16:05:46 +0200 Message-Id: <20200727134940.988811740@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@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 commit de2b41be8fcccb2f5b6c480d35df590476344201 upstream. 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: Greg Kroah-Hartman --- arch/x86/kernel/vmlinux.lds.S | 1 + include/asm-generic/vmlinux.lds.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -359,6 +359,7 @@ SECTIONS .bss : AT(ADDR(.bss) - LOAD_OFFSET) { __bss_start = .; *(.bss..page_aligned) + . = ALIGN(PAGE_SIZE); *(BSS_MAIN) BSS_DECRYPTED . = ALIGN(PAGE_SIZE); --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -341,7 +341,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); \ @@ -727,7 +728,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) \