Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp667752ybg; Tue, 28 Jul 2020 16:01:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLm8m5g6lx4ZIAnhjiAVhLx1CLBSG1Ifo5MLI2sGZuI/f1F3eG0l4LMlg9It9/0sivkWgS X-Received: by 2002:a17:906:1747:: with SMTP id d7mr27282094eje.39.1595977268001; Tue, 28 Jul 2020 16:01:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595977267; cv=none; d=google.com; s=arc-20160816; b=TSD5g8LQJH7mR5Bd5oTZgqy/xEf7/0na6+jl+wZDsQR82/OHac0PYnwOwhKoP/qKQk q7ngoRGh1dFeGVCc6lDY92MgVt2KGTOsPSYt51AoyfVMwZEczQ0BUEiSYF/7yK6oSSGD p+FepyAA2Y7ZYk4hHMYBCdWVzHZrI8hiOCIrKkFMe/vC3jXgK2UWWrklYhRICwW7fBq7 ttRcQC5hSbSZyP3CpQ+xlr6JQyLVZQCrpgILZ3lhMXif22AeepPJorkyl4cdm7kPipo/ 3mY9E82kRVkPnclNj2KMU9Nh0dGMsCukhu9VUWNDwaSfyQ/cwcCJqqsPHFpM4QvQK3M5 o6Dw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=664q02oA7FO52GOLxPk6sglqmKpmRZ9R6+3YdHJlxFE=; b=q7hD2oIY2YlqOOByImtm4UH99GJT0ckm8oEorSIUqEln+Y+c3jcP5tr+wNKMIXMczw 8m1QKVeQMkurD+e/E4wT4k4Ac0cZxucXAZljDUwjljhKk3j3bAmOf6PrMNXpEqAxRY3p cZF7iik3TDIoribo9i7OqSIvEjCRlgH0ZAjkrH/Yg0yDONgu35uFxlMeJRxlzSKBlKCH 3XMohPsSnqpPTiZlG8mghO0kiTjMBJuce2RE2FCvQbZXxNcON0ZVQmAoHifsM0J1NaRs fxLJLWDQ2gEYnKd/ZAwZ///tQXCo9lDlYWCTK19Pc+4SRlKPgFrAH5V907U0NOnSc7tO epIA== ARC-Authentication-Results: i=1; mx.google.com; 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 dm22si5189239ejc.191.2020.07.28.16.00.45; Tue, 28 Jul 2020 16:01:07 -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; 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 S1730240AbgG1W6K (ORCPT + 99 others); Tue, 28 Jul 2020 18:58:10 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:41604 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730097AbgG1W5l (ORCPT ); Tue, 28 Jul 2020 18:57:41 -0400 Received: by mail-qt1-f195.google.com with SMTP id v22so10317973qtq.8 for ; Tue, 28 Jul 2020 15:57:41 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=664q02oA7FO52GOLxPk6sglqmKpmRZ9R6+3YdHJlxFE=; b=r1JD6b+McAe6TiK2794lYOK92aoKdlVBFBPHbCrkNSF4FXeysEAWWjt4vHGjhUIyJv FzfDT0fabD0F34dbDUkKivbOcZrUWjcfJ2kCjBD8j2F2RO6QOB1WQG5qTvX5gLJ4NYrU IxhSanSzOMf8z477/8eZ8dL5ZPTOE5OnD+3Mwe+4Y/P49ihCWfP8cp81nb3LYMxtRFVg eu7grE19Ml0jll4HakyNl50InwEXxavmFKSCceKeE6BEdoin7vwABC8BX5cYHzKoef/M oMHcACbIOyRnvmaPsvyDEC5gfvzt9Pj11QjwVXmVrCdOlS/FmPJOdwDc9OhAfVhZhSEz i99g== X-Gm-Message-State: AOAM532REuS1Wrk2gXrwCEnjLS3PjZtbqJi5aI55cWgNgvzZB/IQB3Z4 c3hDrwRL7RRSnf7xwlF3zzY= X-Received: by 2002:ac8:152:: with SMTP id f18mr17852257qtg.163.1595977060545; Tue, 28 Jul 2020 15:57:40 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id o187sm88118qkd.112.2020.07.28.15.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2020 15:57:39 -0700 (PDT) From: Arvind Sankar To: Kees Cook , x86@kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v3 20/21] x86/kaslr: Make local variables 64-bit Date: Tue, 28 Jul 2020 18:57:21 -0400 Message-Id: <20200728225722.67457-21-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200727230801.3468620-1-nivedita@alum.mit.edu> References: <20200727230801.3468620-1-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Change the type of local variables/fields that store mem_vector addresses to u64 to make it less likely that 32-bit overflow will cause issues on 32-bit. Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/kaslr.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index c49d479245d0..38ecbf2e61c5 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -461,7 +461,7 @@ static bool mem_avoid_overlap(struct mem_vector *img, { int i; struct setup_data *ptr; - unsigned long earliest = img->start + img->size; + u64 earliest = img->start + img->size; bool is_overlapping = false; for (i = 0; i < MEM_AVOID_MAX; i++) { @@ -506,7 +506,7 @@ static bool mem_avoid_overlap(struct mem_vector *img, } struct slot_area { - unsigned long addr; + u64 addr; unsigned long num; }; @@ -537,7 +537,8 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size) static void process_gb_huge_pages(struct mem_vector *region, unsigned long image_size) { - unsigned long pud_start, pud_end, gb_huge_pages; + u64 pud_start, pud_end; + unsigned long gb_huge_pages; struct mem_vector tmp; if (!IS_ENABLED(CONFIG_X86_64) || !max_gb_huge_pages) { @@ -578,7 +579,7 @@ process_gb_huge_pages(struct mem_vector *region, unsigned long image_size) } } -static unsigned long slots_fetch_random(void) +static u64 slots_fetch_random(void) { unsigned long slot; unsigned int i; @@ -594,7 +595,7 @@ static unsigned long slots_fetch_random(void) slot -= slot_areas[i].num; continue; } - return slot_areas[i].addr + slot * CONFIG_PHYSICAL_ALIGN; + return slot_areas[i].addr + ((u64)slot * CONFIG_PHYSICAL_ALIGN); } if (i == slot_area_index) @@ -607,7 +608,7 @@ static void __process_mem_region(struct mem_vector *entry, unsigned long image_size) { struct mem_vector region, overlap; - unsigned long region_end; + u64 region_end; /* Enforce minimum and memory limit. */ region.start = max_t(u64, entry->start, minimum); -- 2.26.2