public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Junaid Shahid <junaids@google.com>
To: dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] x86/mm/KASLR: Account for minimum padding when calculating entropy
Date: Thu, 22 Oct 2020 17:39:16 -0700	[thread overview]
Message-ID: <20201023003916.82906-1-junaids@google.com> (raw)

Subtract the minimum padding between regions from the initial
remain_entropy. Without this, the last region could potentially
overflow past vaddr_end if we happen to get a specific sequence
of random numbers (although extremely unlikely in practice).
The bug can be demonstrated by replacing the prandom_bytes_state
call with "rand = entropy;"

Signed-off-by: Junaid Shahid <junaids@google.com>
---
 arch/x86/mm/kaslr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 6e6b39710e5f..fe3eec30f736 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -109,7 +109,8 @@ void __init kernel_randomize_memory(void)
 	kaslr_regions[2].size_tb = DIV_ROUND_UP(vmemmap_size, 1UL << TB_SHIFT);
 
 	/* Calculate entropy available between regions */
-	remain_entropy = vaddr_end - vaddr_start;
+	remain_entropy = vaddr_end - vaddr_start -
+			 (ARRAY_SIZE(kaslr_regions) - 1) * PUD_SIZE;
 	for (i = 0; i < ARRAY_SIZE(kaslr_regions); i++)
 		remain_entropy -= get_padding(&kaslr_regions[i]);
 
-- 
2.29.0.rc2.309.g374f81d7ae-goog


                 reply	other threads:[~2020-10-23  0:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201023003916.82906-1-junaids@google.com \
    --to=junaids@google.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox