From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C291EC4167B for ; Wed, 28 Dec 2022 14:39:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pAXaZ-0005Fk-7R; Wed, 28 Dec 2022 09:39:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pAXaX-0005FJ-Fz for qemu-devel@nongnu.org; Wed, 28 Dec 2022 09:39:25 -0500 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pAXaU-0001fM-Oq for qemu-devel@nongnu.org; Wed, 28 Dec 2022 09:39:25 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6F671B8170E; Wed, 28 Dec 2022 14:39:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0D5AC433D2; Wed, 28 Dec 2022 14:39:18 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="FmUMzWAF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1672238355; h=from:from: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=Vq5HU2e0An2dJOWNwYu6KJi6n2DVTujSQj+JRa+gkDQ=; b=FmUMzWAFC2yEV6GXbLI3DRDJiJgom9v72rI8zcZKK2t9r+6e2GXZGvhXCOvtYKczJyhotJ WfjgePUsf1eEY22FIA3HNWFg7cB1POt0HctY1G00Kzby0bU2OPKcjzt/POiXXjQDY8zaOM BBHiFg0BpsUFOq56eBmnNX/tpkuDiw4= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id d267fddd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 28 Dec 2022 14:39:15 +0000 (UTC) Date: Wed, 28 Dec 2022 15:39:12 +0100 From: "Jason A. Donenfeld" To: Eric Biggers , x86@kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, Laurent Vivier , "Michael S . Tsirkin" , Peter Maydell , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Richard Henderson , Ard Biesheuvel , Gerd Hoffmann , kasan-dev@googlegroups.com, Dmitry Vyukov Subject: Re: [PATCH v5 4/4] x86: re-enable rng seeding via SetupData Message-ID: References: <20220921093134.2936487-1-Jason@zx2c4.com> <20220921093134.2936487-4-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Received-SPF: pass client-ip=2604:1380:4601:e00::1; envelope-from=SRS0=vu6c=42=zx2c4.com=Jason@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Wed, Dec 28, 2022 at 04:07:13AM +0100, Jason A. Donenfeld wrote: > On Tue, Dec 27, 2022 at 02:36:54PM +0100, Jason A. Donenfeld wrote: > > On Mon, Dec 26, 2022 at 05:57:30PM +0100, Jason A. Donenfeld wrote: > > > On Mon, Dec 26, 2022 at 03:43:04PM +0100, Jason A. Donenfeld wrote: > > > > On Mon, Dec 26, 2022 at 03:24:07PM +0100, Jason A. Donenfeld wrote: > > > > > Hi, > > > > > > > > > > I'm currently stumped at the moment, so adding linux-mm@ and x86@. Still > > > > > working on it though. Details of where I'm at are below the quote below. > > > > > > > > > > On Sat, Dec 24, 2022 at 05:21:46AM +0100, Jason A. Donenfeld wrote: > > > > > > On Sat, Dec 24, 2022 at 04:09:08AM +0100, Jason A. Donenfeld wrote: > > > > > > > Hi Eric, > > > > > > > > > > > > > > Replying to you from my telephone, and I'm traveling the next two days, > > > > > > > but I thought I should mention some preliminary results right away from > > > > > > > doing some termux compiles: > > > > > > > > > > > > > > On Fri, Dec 23, 2022 at 04:14:00PM -0800, Eric Biggers wrote: > > > > > > > > Hi Jason, > > > > > > > > > > > > > > > > On Wed, Sep 21, 2022 at 11:31:34AM +0200, Jason A. Donenfeld wrote: > > > > > > > > > This reverts 3824e25db1 ("x86: disable rng seeding via setup_data"), but > > > > > > > > > for 7.2 rather than 7.1, now that modifying setup_data is safe to do. > > > > > > > > > > > > > > > > > > Cc: Laurent Vivier > > > > > > > > > Cc: Michael S. Tsirkin > > > > > > > > > Cc: Paolo Bonzini > > > > > > > > > Cc: Peter Maydell > > > > > > > > > Cc: Philippe Mathieu-Daudé > > > > > > > > > Cc: Richard Henderson > > > > > > > > > Cc: Ard Biesheuvel > > > > > > > > > Acked-by: Gerd Hoffmann > > > > > > > > > Signed-off-by: Jason A. Donenfeld > > > > > > > > > --- > > > > > > > > > hw/i386/microvm.c | 2 +- > > > > > > > > > hw/i386/pc_piix.c | 3 ++- > > > > > > > > > hw/i386/pc_q35.c | 3 ++- > > > > > > > > > 3 files changed, 5 insertions(+), 3 deletions(-) > > > > > > > > > > > > > > > > > > > > > > > > > After upgrading to QEMU 7.2, Linux 6.1 no longer boots with some configs. There > > > > > > > > is no output at all. I bisected it to this commit, and I verified that the > > > > > > > > following change to QEMU's master branch makes the problem go away: > > > > > > > > > > > > > > > > diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c > > > > > > > > index b48047f50c..42f5b07d2f 100644 > > > > > > > > --- a/hw/i386/pc_piix.c > > > > > > > > +++ b/hw/i386/pc_piix.c > > > > > > > > @@ -441,6 +441,7 @@ static void pc_i440fx_8_0_machine_options(MachineClass *m) > > > > > > > > pc_i440fx_machine_options(m); > > > > > > > > m->alias = "pc"; > > > > > > > > m->is_default = true; > > > > > > > > + PC_MACHINE_CLASS(m)->legacy_no_rng_seed = true; > > > > > > > > } > > > > > > > > > > > > > > > > I've attached the kernel config I am seeing the problem on. > > > > > > > > > > > > > > > > For some reason, the problem also goes away if I disable CONFIG_KASAN. > > > > > > > > > > > > > > > > Any idea what is causing this? > > > > > > > > > > > > > > - Commenting out the call to parse_setup_data() doesn't fix the issue. > > > > > > > So there's no KASAN issue with the actual parser. > > > > > > > > > > > > > > - Using KASAN_OUTLINE rather than INLINE does fix the issue! > > > > > > > > > > > > > > That makes me suspect that it's file size related, and QEMU or the BIOS > > > > > > > is placing setup data at an overlapping offset by accident, or something > > > > > > > similar. > > > > > > > > > > > > I removed the file systems from your config to bring the kernel size > > > > > > back down, and voila, it works, even with KASAN_INLINE. So perhaps I'm > > > > > > on the right track here... > > > > > > > > > > QEMU sticks setup_data after the kernel image, the same as kexec-tools > > > > > and everything else. Apparently, when the kernel image is large, the > > > > > call to early_memremap(boot_params.hdr.setup_data, ...) returns a value > > > > > that points some place bogus, and the system crashes or does something > > > > > weird. I haven't yet determined what this limit is, but in my current > > > > > test kernel, a value of 0x0000000001327650 is enough to make it point to > > > > > rubbish. > > > > > > > > > > Is this expected? What's going on here? > > > > > > > > Attaching gdb to QEMU and switching it to physical memory mode > > > > (`maintenance packet Qqemu.PhyMemMode:1 `) indicates that it > > > > early_memremap is actually working fine and something *else* is at this > > > > address? That's kinda weird... Is KASAN populating physical addresses > > > > immediately after the kernel image extremely early in boot? I'm seeing > > > > the crash happen from early_reserve_memory()-> > > > > memblock_x86_reserve_range_setup_data(), which should be before > > > > kasan_init() even runs. Is QEMU calculating kernel_size wrong, when it > > > > goes to determine where to put the setup_data data? But that's the same > > > > calculation as used everywhere else, so hmm... > > > > > > > > Jason > > > > > > If bzImage is 15770544 bytes, it does not boot. If bzImage is 15641776 > > > bytes, it does boot. So something is happening somewhat close to the > > > 16MB mark? > > > > > > > Okay, the issue is that it's being decompressed to an area that overlaps > > the source. So for example in my test kernel: > > > > input_addr: 0x3f112bf > > output_addr: 0x1000000 > > output_len: 0x3a5d7d8 > > > > Since 0x3a5d7d8 + 0x1000000 > 0x3f112bf, eventually this corrupts the > > setup_data at the end there. > > > > Now digging into what can be done about it. > > Not quite. input_addr doesn't matter, since setup_data still points to > the old mapping. > > So the actual issue is: > > compressed_size: 0xf028d4 > decompressed_size: 0x3a5d7d8 > setup_data: 0x100000 + compressed_size > output_addr: 0x1000000 (this is LOAD_PHYSICAL_ADDR) > > Since `output_addr + decompressed_size > setup_data && output_addr < > setup_data`, then it means the decompressor will write over setup_data. > > Note that this is also a problem for SETUP_DTB, so it's a longstanding > bug. > > I'm experimenting now with appending lots of zeros between the kernel > image and setup_data, so that the decompressor doesn't overwrite > setup_data, but so far it's not working. > > Another option would be to have the build system warn when this is going > to happen, and suggest that the user increase the value of > CONFIG_PHYSICAL_START. This might be the best option... I posted a patch: https://lore.kernel.org/qemu-devel/20221228143831.396245-1-Jason@zx2c4.com/ We can move discussion on the topic over to that thread now. Jason