Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10279689rwl; Sun, 1 Jan 2023 22:52:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXth6LmWavEySKZwsKw2dHSzJIeMN+a39Ph+9V1wmcvZW8oO41QA0XhU3APJXQOIFl2FECCA X-Received: by 2002:a05:6a20:e61b:b0:af:7ed7:d370 with SMTP id my27-20020a056a20e61b00b000af7ed7d370mr47160070pzb.43.1672642378034; Sun, 01 Jan 2023 22:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672642378; cv=none; d=google.com; s=arc-20160816; b=Ki8W3zPmiHsWtP8guOvrVDa0QBsCV5e73zzgGVJXZ07ZTkwwUJ7NaU3zSlA8rw15HX oT7xqNsvURIJHal02sssdDnybVgyQSAF8oKSSPnv6Ggv1fB+sB7RZnfzQKMLjbkOueBm Gotabkx2c+cWSjj0A1zwY8S1GyDx2g4Wz1hbHt8tumcKaZOQ5NBn6QTVojobtwUPbqct LGCqfMWvPah384W58QCmTgHTFEyR4JbeQZLYi6WvBgdIssMu07MayzMkmr1r+gdzMXOm fSwEJXOtdUOwTnkFRPpfAEjXNlhPl3DvG0O69mZ3dl7iz9XekhWMBzy+7Qc6ugLIol8d PT/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FC+Jlf27xP9P9TCcinvw5bMB7xljXbe366COrIpKShs=; b=zRHRcT52fCOE2ujZyDyMhySjhmaqBgCzQa0AxtuOr8JNCJtXPz9mGbtMcvYBHb/XjN HlM2Dyb4xW8wOR1wAtZxHfiJ86z1bHsMp71SWN4zxwSJR2sCBvD7XZ1d4ZmeUp2ZUH6e hOUPILkehLnFj1nVk8nSauPdwP6twDm0TDHWKbqfFH6JpR6PfX62mZU02Uuuylev8OVG vw0tKkYn71AJY5lKYw/0QG8InXkgXDrt8HYjgl1hmVmEJiIa0rufP/Wj04Ko9pF4v+Ab AnXU6SaQFOmv8wSHJrn7ku4vbWRQeAqSkim/WTQdck2yhLxyrThb2YTXOaqDcbDegoPD GQwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=iOYzgwCH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 135-20020a63018d000000b004782c6e304bsi28039468pgb.256.2023.01.01.22.52.50; Sun, 01 Jan 2023 22:52:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=iOYzgwCH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230187AbjABGRw (ORCPT + 59 others); Mon, 2 Jan 2023 01:17:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbjABGRu (ORCPT ); Mon, 2 Jan 2023 01:17:50 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7CF25DF for ; Sun, 1 Jan 2023 22:17:49 -0800 (PST) Received: from zn.tnic (p5de8e9fe.dip0.t-ipconnect.de [93.232.233.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 980FE1EC0589; Mon, 2 Jan 2023 07:17:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1672640267; 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:in-reply-to:in-reply-to: references:references; bh=FC+Jlf27xP9P9TCcinvw5bMB7xljXbe366COrIpKShs=; b=iOYzgwCH74Wo/PifxKlDVns/9RXxKV13v0caAk6oZvfoZuqKXScowtozcnk1Xgw7eFGAmc AGsHjUgpgFXJhBfaoPdsML6AxbeA6A8cnR96lc4GmCreLHjC+F/EhF4BYQba9zMHPRSgU/ WElLUAk63oHjC6cLSI2FeksenwmiG90= Date: Mon, 2 Jan 2023 07:17:43 +0100 From: Borislav Petkov To: "H. Peter Anvin" Cc: "Jason A. Donenfeld" , pbonzini@redhat.com, ebiggers@kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, ardb@kernel.org, kraxel@redhat.com, philmd@linaro.org Subject: Re: [PATCH qemu] x86: don't let decompressed kernel image clobber setup_data Message-ID: References: <60566f8b-c90f-12e7-c13e-94e9829eee2d@zytor.com> <8f072588-7d66-0932-7486-ed9159ae93ae@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 02, 2023 at 07:01:50AM +0100, Borislav Petkov wrote: > On Sat, Dec 31, 2022 at 07:31:21PM -0800, H. Peter Anvin wrote: > > It would probably be a good idea to add a "maximum physical address for > > initrd/setup_data/cmdline" field to struct kernel_info, though. It appears > > right now that those fields are being identity-mapped in the decompressor, > > and that means that if 48-bit addressing is used, physical memory may extend > > past the addressable range. > > Yeah, we will probably need that too. > > Btw, looka here - it can't get any more obvious than that after dumping > setup_data too: > > early console in setup code > early console in extract_kernel > input_data: 0x00000000040f92bf > input_len: 0x0000000000f1c325 > output: 0x0000000001000000 > output_len: 0x0000000003c5e7d8 > kernel_total_size: 0x0000000004428000 > needed_size: 0x0000000004600000 > boot_params->hdr.setup_data: 0x00000000010203b0 > trampoline_32bit: 0x000000000009d000 > > Decompressing Linux... Parsing ELF... done. > Booting the kernel. > > > Aligning them vertically: > > output: 0x0000000001000000 > output_len: 0x0000000003c5e7d8 > kernel_total_size: 0x0000000004428000 > needed_size: 0x0000000004600000 > boot_params->hdr.setup_data: 0x00000000010203b0 Ok, waait a minute: ============ ============ Field name: pref_address Type: read (reloc) Offset/size: 0x258/8 Protocol: 2.10+ ============ ============ This field, if nonzero, represents a preferred load address for the kernel. A relocating bootloader should attempt to load at this address if possible. A non-relocatable kernel will unconditionally move itself and to run at this address. so a kernel loader (qemu in this case) already knows where the kernel goes: boot_params->hdr.setup_data: 0x0000000001020450 boot_params->hdr.pref_address: 0x0000000001000000 ^^^^^^^^^^^^^^^^^ now, considering that same kernel loader (qemu) knows how big that kernel is: kernel_total_size: 0x0000000004428000 should that loader *not* put anything that the kernel will use in the range pref_addr + kernel_total_size ? -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette