From mboxrd@z Thu Jan 1 00:00:00 1970 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 F1F7827FB05 for ; Fri, 20 Mar 2026 02:37:36 +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=1773974257; cv=none; b=G8oKqKkCu6u9iBtICvLS5Uzer/u6Wt6ryvt7HRC/EmF9j9vUl4/JT/+bs6RIGIcyIgrDvqEE1BH5LCjcDHrBAEnbSpHglZ5OjWvODvBfG6/6yLFoVHjAWNHrKdiUY6GTPF6Z//f8mIikCwQ3Aeaby7LbHtu0xBi0ahmuN3igOkI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773974257; c=relaxed/simple; bh=Ce9ZvvedBVgFA/+wmV2hIlsGSiYitcDJqHPohquR+Zk=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=NVQum/wyyWJmQsNiqaoetYX7wn5m95XGCrrDKvfjpRJmLGA6bk2FWzOF5e3er8BMZY7QrBZMnIC+xzTkB4nynTY3M3qrdfEP7LEObf4Ie4MZFCAi4DvdKnO4+6ZbuYoUeXcfWwjwMpNprcudzwM7mjSEiO8Aq0sD7hI2m9a41bM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=Om6KcrXu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="Om6KcrXu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ECEDC19424; Fri, 20 Mar 2026 02:37:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1773974256; bh=Ce9ZvvedBVgFA/+wmV2hIlsGSiYitcDJqHPohquR+Zk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Om6KcrXu8DE2JhUZs0+F2J+y4aA2hbY89smr4crrjx5cRej3tpnwOxli02mGOXb5b 0HZvTa5Zfc83wD+u2NAxu5b7wvyTPBmHCZiD+dySxaGGzRg0SxQpDz5fDdp9gdzJlb Obs5tI+hxPgFgGOf2mx7oJ3SOuqr6d+c6LP4BxUU= Date: Thu, 19 Mar 2026 19:37:35 -0700 From: Andrew Morton To: Marco Elver Cc: Alexander Graf , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: Re: [PATCH v2] kho: use checked arithmetic in deserialize_bitmap() Message-Id: <20260319193735.2ea34594b36d37e7850a8c37@linux-foundation.org> In-Reply-To: <20260319210528.1694513-2-elver@google.com> References: <20260319210528.1694513-2-elver@google.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Thu, 19 Mar 2026 22:03:53 +0100 Marco Elver wrote: > The function deserialize_bitmap() calculates the reservation size using: > > int sz = 1 << (order + PAGE_SHIFT); > > If a corrupted KHO image provides an order >= 20 (on systems with 4KB > pages), the shift amount becomes >= 32, which overflows the 32-bit > integer. This results in a zero-size memory reservation. > > Furthermore, the physical address calculation: > > phys_addr_t phys = elm->phys_start + (bit << (order + PAGE_SHIFT)); > > can also overflow and wrap around if the order is large. This allows a > corrupt KHO image to cause out-of-bounds updates to page->private of > arbitrary physical pages during early boot. > > Fix this by changing 'sz' to 'unsigned long' and using checked add and > shift to safely calculate the shift amount, size, and physical address, > skipping malformed chunks. This allows preserving memory with an order > larger than MAX_PAGE_ORDER. AI review asked questions: https://sashiko.dev/#/patchset/20260319210528.1694513-2-elver%40google.com