Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1222062lqb; Thu, 18 Apr 2024 04:00:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/De4msRDUHTfxoJzySQvmgoDRotdo1UgrLPpWQ937yYwV6f33SEnibQ9JD1Gj/ZoiSbyuBM+EwoZR/s2UlrgbywF593NYidVwQ6Omwg== X-Google-Smtp-Source: AGHT+IHkz8178kPl9aG7r7/7N5Uoq6/naS/glFuoyZBKe8JQiCXOb6fyXocAxa17KuL/oTBjDelF X-Received: by 2002:a05:6a20:3945:b0:1a7:aa08:4b6c with SMTP id r5-20020a056a20394500b001a7aa084b6cmr3577412pzg.17.1713438040906; Thu, 18 Apr 2024 04:00:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713438040; cv=pass; d=google.com; s=arc-20160816; b=kCH/x53t2avV4XsTDF0NLC1Xvc1qJW2DeAhuniCDyD3gRwv7BaCOzvsp7ybq9uz2Ft AeOi5LII90vmE/2k1ndXbBc3PMgehnabI+1GUTEw2CJVqm6hpXQ7U10fhwPjp7Jqoqhz NThh4k+7aqM1o/Khm1UzyyDAsqHIlVhK5HezmwK1fh1AbBGuXWcV+jX5gQNg7cxRRfOR dKbNLX1QnOfEYs3B5p7YEtv8K7h+dD09eODmOdp9sxDAXv8hZoSNbZcmOeJubcz03yoe 0yblgzpytvuHoGqT5XYMAuRZzdbElnEKXOBLji+MXGkfiu4Ibc0DMF5ZwI2UirEtL3ee EKmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=kG6u44vstsJgens35JQUK2zu8yiIn4wsjtULEx80ESs=; fh=0LpBTjzXasFkQBbV3UFluc/3DZChKFo4ZetNVgn+jac=; b=XGPG1jWV+nEZMBfPPPqnQezP3rg4d693OEM4+tUJ/wxhUE+k6Q7vebDOaF+YoJDms1 EZ3JOixhrc3n7BCYln2nnxGkSPZ5LQ9FYgDcMm9PsWpHZ+/RSuMo+TfcPZoOhA6FnZVB E8ZoXfWogRdTl4yZjDz6e+Y+DjlSvRt5+fbmBshiI59qyRZQfPAuLfViJl7OyoOCBDaf rp93yBnaEnjE4Z+hKcAEeRvNXE3f6P9o3JUf7nH2q+q3uDhiA41xORyn+QiCwkiLq6dZ KdKMvq4iUkSseUHatKRuFonKk613uS7FhvFA05seU4//pLYg6KXV9aqbruELBKmOJOgD kC6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o9EE8h6c; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-149928-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149928-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c25-20020a62e819000000b006ecf6ce1e4esi1195177pfi.230.2024.04.18.04.00.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 04:00:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149928-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o9EE8h6c; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-149928-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149928-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id F2554B216F5 for ; Thu, 18 Apr 2024 10:56:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 167D515E1EF; Thu, 18 Apr 2024 10:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o9EE8h6c" 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 39F5E15AAA5; Thu, 18 Apr 2024 10:55:57 +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=1713437758; cv=none; b=K5rgZytab3stFOJhvpogXWxpDXQP5uOvY2VZOOoFW3Sy3NaiDdENRlo+NEi0e2l41+gEEJGb744dH9Lq6+wh0gAgz3IxmZ0vmyQYxd+OsgI3upHDEHndNO6WKf/jeMMEfAPlamH3OpyKkVaqIHMG2DVdTt1UCF8PJkgvmgAD04c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713437758; c=relaxed/simple; bh=QKZFgiAAxVmB0Ab5Gva4C9DkDubO+iF3SWJEtPIsX54=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bCL78Rw8HjquFGSWQi/inyK1Z3tGti9uPprtrWvN655wUZAr5pusCvy5gnqAg2/o13FC8xh2eNJV2T7IWvXuwzA22InSCFYOMIlA+7Qo4f9MqlElN3QzNE0WmXafjJc23l3+NByEiWoAE62N6wzrrggyu6fTCH5A4I9nNvgHYWM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o9EE8h6c; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B970C113CC; Thu, 18 Apr 2024 10:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713437757; bh=QKZFgiAAxVmB0Ab5Gva4C9DkDubO+iF3SWJEtPIsX54=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=o9EE8h6c6EWLkKWVpIDYsnrXuMlaE30U6yItOJCjmn5/bI3ZabIyA4UKpilHNOIdr QcM3XONAwYtkblNReNMkGnUWnxmhPXC3l38oIX1599gIR3sr2TMgyY7VnG9Kshg+jT 14j16rC9ARdf0SX+YRY0zBXWMislAXOQsKLpVxpGGGhLICGI1WLSNPsmnivIlaZqgL ch79sKBN2oGs6LILzeZri63UzbcUYpHD0UiSTRxj2JsuPjsfv9WhANU0yE2+gOeCv6 sLgfsrsCGRJiT0sNsvzJ1vZeGRWQXuqFQbJIl1zqcKFde14VmQJsKRXUgqJWavd08I 2n4Gf9BPpjcAA== Date: Thu, 18 Apr 2024 13:54:46 +0300 From: Mike Rapoport To: Nam Cao Cc: Andreas Dilger , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , linux-riscv@lists.infradead.org, Thomas Gleixner , Andrew Morton , "ndesaulniers @ google . com" , Luis Chamberlain , Ingo Molnar , Christophe Leroy , Tejun Heo , Krister Johansen , Changbin Du , Arnd Bergmann , Geert Uytterhoeven , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] init: fix allocated page overlapping with PTR_ERR Message-ID: References: <20240418102943.180510-1-namcao@linutronix.de> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240418102943.180510-1-namcao@linutronix.de> On Thu, Apr 18, 2024 at 12:29:43PM +0200, Nam Cao wrote: > There is nothing preventing kernel memory allocators from allocating a > page that overlaps with PTR_ERR(), except for architecture-specific > code that setup memblock. > > It was discovered that RISCV architecture doesn't setup memblock > corectly, leading to a page overlapping with PTR_ERR() being allocated, > and subsequently crashing the kernel (link in Close: ) > > The reported crash has nothing to do with PTR_ERR(): the last page > (at address 0xfffff000) being allocated leads to an unexpected > arithmetic overflow in ext4; but still, this page shouldn't be > allocated in the first place. > > Because PTR_ERR() is an architecture-independent thing, we shouldn't > ask every single architecture to set this up. There may be other > architectures beside RISCV that have the same problem. > > Fix this one and for all by reserving the physical memory page that > may be mapped to the last virtual memory page as part of low memory. > > Unfortunately, this means if there is actual memory at this reserved > location, that memory will become inaccessible. However, if this page > is not reserved, it can only be accessed as high memory, so this > doesn't matter if high memory is not supported. Even if high memory is > supported, it is still only one page. > > Closes: https://lore.kernel.org/linux-riscv/878r1ibpdn.fsf@all.your.base.are.belong.to.us > Signed-off-by: Nam Cao > Cc: # all versions Reviewed-by: Mike Rapoport (IBM) > --- > init/main.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/init/main.c b/init/main.c > index 881f6230ee59..f8d2793c4641 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -900,6 +900,7 @@ void start_kernel(void) > page_address_init(); > pr_notice("%s", linux_banner); > early_security_init(); > + memblock_reserve(__pa(-PAGE_SIZE), PAGE_SIZE); /* reserve last page for ERR_PTR */ > setup_arch(&command_line); > setup_boot_config(); > setup_command_line(command_line); > -- > 2.39.2 > -- Sincerely yours, Mike.