Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1550579lqz; Mon, 1 Apr 2024 09:28:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWa/33Kawy+UaF90SthhCtMiVwlTsHD8pWzJMX6U+qzWC9C21Wti4dw9hczvkXscxMBLCk/zXkdTOT/U0gckVoNN0aWoo1j8g3/2IbVbw== X-Google-Smtp-Source: AGHT+IE+kf4bPksMO3628tzXC2T1//o72umqg+2MyREM99h+DKJ+Y9mV8HiSlFxSoaakrh0AMQuw X-Received: by 2002:a05:6a20:3d8b:b0:1a5:6c2c:2db9 with SMTP id s11-20020a056a203d8b00b001a56c2c2db9mr18335403pzi.3.1711988881417; Mon, 01 Apr 2024 09:28:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711988881; cv=pass; d=google.com; s=arc-20160816; b=Ej+1l5n1b4VOQlUAcyLmXJegIvo7qdW4/gNHe+3Ib0ArdHSSsUteJDeudQzygkStZ+ o3XsSkLd3zJEKF8ukIPbynFqMdiL/0B6e4bixGqxLxv/3c2iPq/MF4oXcIjMVXV/NUDs 9Ohn4XoU+ICh/cetWlj85lYWF42XoZ/H8f1fixpGGw70Qc1OFrhKPxxbaxwRCKFG+1L/ oHeEOcrIKPX5QH8uxNq4R5L+x1epgFUlJggvOaplirqdtlYjeTcYvlF64+w/MZQeDP1D tcf4GFTgNEbECPaXJCnTnFY+FTkbFXlu9DmQfMZgoN29Mtwxfd6HjV2yw8f5yTK6n71s SvGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=6cqhpZv7VvH7bReHfBwLDuZw7Kg30fL8AoB+U13x9r0=; fh=CM4VWZ2lhCNQJ0JDIxawEK+TE4UuHPyV8l/fd0QlPik=; b=ljP+i8HXKB3IE9f9+Vn0Pd77bd66EWn+HHjJt/IevMUSRuNWzvRvtFqZvfgpmm5fzX I4btPKqh+D0VvExHuW86Vmh5nF/IEoncT0+5ZJ216h2DZ2eyiIRkDN3KMYQFCUMBmVny s5CvCXGkShPnZsvj8kgqGwR76NJxk8iDB0jFdxN0802g5EBDTGFrGR7jc4VrXOIFiVWt MuBKqDAwQ5eOi7Dd19Zeev10WhMzJa7JSEWjH0MBFBUquCTNmYSqV/ozSG4YqqwzE0wk 2GnAH2X4ofJ1TRzSzNN1cbmw6E1zMC5hbv/y8fcER53/ZggXKTWIGljmPin3JqoPK2dq ubqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ND1vihcI; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-126850-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126850-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f10-20020a631f0a000000b005dc1b73dd16si9362288pgf.372.2024.04.01.09.28.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 09:28:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-126850-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ND1vihcI; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-126850-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126850-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 19ED628189F for ; Mon, 1 Apr 2024 16:28:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66A33481B4; Mon, 1 Apr 2024 16:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ND1vihcI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82C27C129; Mon, 1 Apr 2024 16:27:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711988875; cv=none; b=ITUftiZ2wZcdSRSq1GZDkSyrcAASp0QCuoSGmFt+/a+1mqJz+eivxS3Yx2ODQjrj0Pjq7J5UlL7Mto8fE+qRH9YIlV+FU/47fQmxCT7te+rt8KimRmqmCq55wHhm+g18EMCQzLfoOwZlw1hGvH4HvNKQ2/dJjptKRkz67HwfAtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711988875; c=relaxed/simple; bh=Ya4h15FkpoXHhaMquYV0OAHhjoJCo638P01fWR22oqA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FmYHqUkdpyDv4he26yskw9pjjcU8fJW79u0/ffVbwtABHTDkGUl+wiQhP3jUlJc6UjnDoSVM4tiQ7N4Q2EKK5igwj6i0YTW8l33FFt2INaEcIi0FF+9fdliXXG5ctsiGeL4oBaE4a1nrDqvO8q3DVzDh0jECJ4QSBQM0DfWG6GE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ND1vihcI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C30A2C433C7; Mon, 1 Apr 2024 16:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1711988875; bh=Ya4h15FkpoXHhaMquYV0OAHhjoJCo638P01fWR22oqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ND1vihcIz81AMfxstjMQTE4GzR0SOgWZx3kAtH94vGVkdGDZWbdnYcBXaGVFsUUe6 TzBYf5mS9poSePyAiKKw5SPxigbvubsMrPKB4aH6rUo5bSBXM01cn4F2gw9Do4kumE moYua1GoccKVEGmacInkbEeK69OLxNEZmezZ1Chg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, linux-efi@vger.kernel.org, Tom Englund , linux-kernel@vger.kernel.org, Kazuma Kondo , Ard Biesheuvel , Sasha Levin Subject: [PATCH 6.7 314/432] efi/libstub: fix efi_random_alloc() to allocate memory at alloc_min or higher address Date: Mon, 1 Apr 2024 17:45:01 +0200 Message-ID: <20240401152602.551725613@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240401152553.125349965@linuxfoundation.org> References: <20240401152553.125349965@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: KONDO KAZUMA(近藤 和真) [ Upstream commit 3cb4a4827596abc82e55b80364f509d0fefc3051 ] Following warning is sometimes observed while booting my servers: [ 3.594838] DMA: preallocated 4096 KiB GFP_KERNEL pool for atomic allocations [ 3.602918] swapper/0: page allocation failure: order:10, mode:0xcc1(GFP_KERNEL|GFP_DMA), nodemask=(null),cpuset=/,mems_allowed=0-1 ... [ 3.851862] DMA: preallocated 1024 KiB GFP_KERNEL|GFP_DMA pool for atomic allocation If 'nokaslr' boot option is set, the warning always happens. On x86, ZONE_DMA is small zone at the first 16MB of physical address space. When this problem happens, most of that space seems to be used by decompressed kernel. Thereby, there is not enough space at DMA_ZONE to meet the request of DMA pool allocation. The commit 2f77465b05b1 ("x86/efistub: Avoid placing the kernel below LOAD_PHYSICAL_ADDR") tried to fix this problem by introducing lower bound of allocation. But the fix is not complete. efi_random_alloc() allocates pages by following steps. 1. Count total available slots ('total_slots') 2. Select a slot ('target_slot') to allocate randomly 3. Calculate a starting address ('target') to be included target_slot 4. Allocate pages, which starting address is 'target' In step 1, 'alloc_min' is used to offset the starting address of memory chunk. But in step 3 'alloc_min' is not considered at all. As the result, 'target' can be miscalculated and become lower than 'alloc_min'. When KASLR is disabled, 'target_slot' is always 0 and the problem happens everytime if the EFI memory map of the system meets the condition. Fix this problem by calculating 'target' considering 'alloc_min'. Cc: linux-efi@vger.kernel.org Cc: Tom Englund Cc: linux-kernel@vger.kernel.org Fixes: 2f77465b05b1 ("x86/efistub: Avoid placing the kernel below LOAD_PHYSICAL_ADDR") Signed-off-by: Kazuma Kondo Signed-off-by: Ard Biesheuvel Signed-off-by: Sasha Levin --- drivers/firmware/efi/libstub/randomalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c index 4e96a855fdf47..7e18528595502 100644 --- a/drivers/firmware/efi/libstub/randomalloc.c +++ b/drivers/firmware/efi/libstub/randomalloc.c @@ -120,7 +120,7 @@ efi_status_t efi_random_alloc(unsigned long size, continue; } - target = round_up(md->phys_addr, align) + target_slot * align; + target = round_up(max(md->phys_addr, alloc_min), align) + target_slot * align; pages = size / EFI_PAGE_SIZE; status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, -- 2.43.0