Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1800200pxa; Thu, 6 Aug 2020 16:43:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFBMAPq3moXUeqqmZQBtQiOF0rZr9dP+q/95w1P8BdKmwyGd0TrnaQCg+kE5MXcOoty2je X-Received: by 2002:a17:906:7d6:: with SMTP id m22mr6515841ejc.229.1596757399093; Thu, 06 Aug 2020 16:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596757399; cv=none; d=google.com; s=arc-20160816; b=0234Sh68qR6lFFLB6SYbITyYEDinLt9Y6WWr9Qt5tGyn+YSCQ4G085sGmfEjRbhBEM a0dZ645YTOFtz7XtvGCB3RKUbubQbqt5NZZ67WQliF7RknvU71ESxibNSZd49AiBrQtP xJz2tO89QiruYQ750QDoc+VpKNRaZ5yU1YMcC5hJ0Z6RUcHjwkFwwODA7fp2yGcTenfL Xas2jzB5T8fjly5iVBLf0wFVSjYw1FrWqJLRY1e7yhBNSsgU2NdxqDA9aMY3M2W4nyRU 6Ss6pGoJiZVNn0OJxWkhy+I45ryHiJerL/Mop4rsXQ6A/32SDCoo1J45B4hBF18U6St6 xI7w== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=2R5Q1dWK/hb6Z0v4CJ605VU5izTAXbniCYChQw+63X0=; b=O7yGHqWu3SuWineYn9JmAByBl41WDVOPC5iagMmIjxSI2tNPlMkFRzHCKJcTna45or Z8psX20g8BTNde9LTw+Tt+2Q6AGzbDxOv+CuzAaGYtryXAKdaPBZEfioK8WkM99xgAkC Gran45m5bpWfzYT/quFdzCNZ3iimCHBg3ODJXbse0k+gBnHl0TjZSj/frYxEEy31dIZk 0OYAzDJQsY9ZF2wHDO+uTMAoYekGD7EE8jUWxJ7N7H6zXcgP9+X9eNqB1AoYchgwqlzM 1zoA/I5k+cyuh1mCF5Qxf4VFbuX41XjhiHVA+dUbR0GgADbcI3hBHFAtRNitCy0FqYt0 WVdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=i8vSvWNl; dkim=neutral (no key) header.i=@vger.kernel.org; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v22si4356552eji.185.2020.08.06.16.42.56; Thu, 06 Aug 2020 16:43:19 -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=fail header.i=@linutronix.de header.s=2020 header.b=i8vSvWNl; dkim=neutral (no key) header.i=@vger.kernel.org; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727038AbgHFXkE (ORCPT + 99 others); Thu, 6 Aug 2020 19:40:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726578AbgHFXi4 (ORCPT ); Thu, 6 Aug 2020 19:38:56 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6618C061757; Thu, 6 Aug 2020 16:38:55 -0700 (PDT) Date: Thu, 06 Aug 2020 23:38:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1596757134; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2R5Q1dWK/hb6Z0v4CJ605VU5izTAXbniCYChQw+63X0=; b=i8vSvWNlefsfg9kU1FRZvBJ4RH714a6ZJ00wBQhTL6YJtDa8opVKG/xNhhKNaroBytjh87 WpPYLvXRTknvu6egkHLBfBRlJfyB18QvviAaNjhRDFhG+pPGmoPv7GC0kNDu8qxAeGFY3F iUg00fccKZ7oP6OD+NO4NA3eDKyI5iJoW5oB27LIvN1ix4m4yYMbwHCd9Snk84mgHX/Zq/ 5pBqjl7EreyV5rFyO/RToP0TU+cyDTi/+Qk692o0ShLMAqhk3J/yXEJvsKwJMMeYOlzW7p cCPM6GJH0KiXqIEtG2NSZDQWsg8T77xzyYCR9H33QZ2VgGN8b7EDAaW65cdlzQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1596757134; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2R5Q1dWK/hb6Z0v4CJ605VU5izTAXbniCYChQw+63X0=; b=1JOeaMKI9h3i0WRZyRr4pnDhQakAaDo4QmP23kGRSIVdQIrbADUHsTU7k6s3Ch0SxmnemI qKMEtyGc8ZOCTFAQ== From: "tip-bot2 for Arvind Sankar" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/kaslr] x86/kaslr: Drop unnecessary alignment in find_random_virt_addr() Cc: Arvind Sankar , Ingo Molnar , x86 , LKML In-Reply-To: <20200728225722.67457-17-nivedita@alum.mit.edu> References: <20200728225722.67457-17-nivedita@alum.mit.edu> MIME-Version: 1.0 Message-ID: <159675713376.3192.5137291775003011083.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/kaslr branch of tip: Commit-ID: eb38be6db516fb72ccf7282628b545a185b3bc7a Gitweb: https://git.kernel.org/tip/eb38be6db516fb72ccf7282628b545a185b3bc7a Author: Arvind Sankar AuthorDate: Tue, 28 Jul 2020 18:57:17 -04:00 Committer: Ingo Molnar CommitterDate: Fri, 31 Jul 2020 11:08:17 +02:00 x86/kaslr: Drop unnecessary alignment in find_random_virt_addr() Drop unnecessary alignment of image_size to CONFIG_PHYSICAL_ALIGN in find_random_virt_addr, it cannot change the result: the largest valid slot is the largest n that satisfies minimum + n * CONFIG_PHYSICAL_ALIGN + image_size <= KERNEL_IMAGE_SIZE (since minimum is already aligned) and so n is equal to (KERNEL_IMAGE_SIZE - minimum - image_size) / CONFIG_PHYSICAL_ALIGN even if image_size is not aligned to CONFIG_PHYSICAL_ALIGN. Signed-off-by: Arvind Sankar Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20200728225722.67457-17-nivedita@alum.mit.edu --- arch/x86/boot/compressed/kaslr.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 0c64026..ce34a05 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -825,16 +825,12 @@ static unsigned long find_random_virt_addr(unsigned long minimum, { unsigned long slots, random_addr; - /* Align image_size for easy slot calculations. */ - image_size = ALIGN(image_size, CONFIG_PHYSICAL_ALIGN); - /* * There are how many CONFIG_PHYSICAL_ALIGN-sized slots * that can hold image_size within the range of minimum to * KERNEL_IMAGE_SIZE? */ - slots = (KERNEL_IMAGE_SIZE - minimum - image_size) / - CONFIG_PHYSICAL_ALIGN + 1; + slots = 1 + (KERNEL_IMAGE_SIZE - minimum - image_size) / CONFIG_PHYSICAL_ALIGN; random_addr = kaslr_get_random_long("Virtual") % slots;