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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 2D25DCFD376 for ; Mon, 1 Dec 2025 02:51:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gujTNJmqpRdBHyk9LK5Ef8CldG/P1liKZSq/4bE3y54=; b=1NC0zRgH46rR7nzmzappnXZAOU hoNpOlEVAp0+o7aHT4Yf6eW73gPiZEb3JzI4oJF64mkHo4tAYn/SrV1Gm95xCs6hHAbMSW+DWFalq zafMTLhbzpcUXjyFmTK00bynN+RgcjJSF3jbm+uqtGuwn9Kcs5u04vUV6XS5vPuanZzia3xgy4wal IYNlok7A+KEgRfOc2XhkkTv24lTwRKKpCs51+5zWSODL+cLkKjW0UMlJjDK92sdl0OmKZkMVFufRn 0dKGIw9udqk2+n7qpz63OJV+rA/LOTMpAoaaHhvFc8sTWunAaEbEBWrkHrU1twUX4Vkpe5W24PXVT 4JBydllQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPu0L-00000002pxp-0hYU; Mon, 01 Dec 2025 02:51:09 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPu0E-00000002pwb-45x8 for linux-arm-kernel@lists.infradead.org; Mon, 01 Dec 2025 02:51:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764557460; 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: in-reply-to:in-reply-to:references:references; bh=gujTNJmqpRdBHyk9LK5Ef8CldG/P1liKZSq/4bE3y54=; b=YwNbmbKrsO0h5Fv5WZ8ypGDFu7QdzJEVABVU/xdSCLmuE2viTd5O9TN0TMQWbJ3OuGvP81 kWX6JzwjyHHvW6yKFatIsx1jTBjwa98SOl1KJc0ImXB5c5jRr6pabWLEg5Bpfa67AOHctz PPGunYXE5jz1g5dGZFn5KHf81G9vxWo= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-335-ELWTYQSANmmOINN0KgfjYQ-1; Sun, 30 Nov 2025 21:50:56 -0500 X-MC-Unique: ELWTYQSANmmOINN0KgfjYQ-1 X-Mimecast-MFC-AGG-ID: ELWTYQSANmmOINN0KgfjYQ_1764557455 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DE816195605A; Mon, 1 Dec 2025 02:50:54 +0000 (UTC) Received: from localhost (unknown [10.72.112.52]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4DA30195608E; Mon, 1 Dec 2025 02:50:51 +0000 (UTC) Date: Mon, 1 Dec 2025 10:50:47 +0800 From: Baoquan He To: Mark Rutland , Yeoreum Yun , Breno Leitao Cc: Andrew Morton , pjw@kernel.org, catalin.marinas@arm.com, will@kernel.org, coxu@redhat.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: kernel: initialize missing kexec_buf->random field Message-ID: References: <20251127182644.1577592-1-yeoreum.yun@arm.com> <20251127113706.d89a84f277dab3ad273dde75@linux-foundation.org> <5wel6vqjwwf25hryvg6s7z6aaog7xc3zxjevupt3jn4gntme6d@74wwwmhvvelt> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251130_185103_429911_E81A8458 X-CRM114-Status: GOOD ( 25.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 11/28/25 at 02:01pm, Mark Rutland wrote: > On Fri, Nov 28, 2025 at 05:55:05AM -0800, Breno Leitao wrote: > > > > On Fri, Nov 28, 2025 at 08:17:21AM +0800, Baoquan He wrote: > > > On 11/27/25 at 11:37am, Andrew Morton wrote: > > > > On Thu, 27 Nov 2025 18:26:44 +0000 Yeoreum Yun wrote: > > > > > > > > > Commit bf454ec31add ("kexec_file: allow to place kexec_buf randomly") > > > > > introduced the kexec_buf->random field to enable random placement of > > > > > kexec_buf. > > > > > > > > > > However, this field was never properly initialized for kexec images > > > > > that do not need to be placed randomly, leading to the following UBSAN > > > > > warning: > > > > > > > > > > [ +0.364528] ------------[ cut here ]------------ > > > > > [ +0.000019] UBSAN: invalid-load in ./include/linux/kexec.h:210:12 > > > > > [ +0.000131] load of value 2 is not a valid value for type 'bool' (aka '_Bool') > > > > > [ +0.000003] CPU: 4 UID: 0 PID: 927 Comm: kexec Not tainted 6.18.0-rc7+ #3 PREEMPT(full) > > > > > [ +0.000002] Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 > > > > > [ +0.000000] Call trace: > > > > > [ +0.000001] show_stack+0x24/0x40 (C) > > > > > [ +0.000006] __dump_stack+0x28/0x48 > > > > > [ +0.000002] dump_stack_lvl+0x7c/0xb0 > > > > > [ +0.000002] dump_stack+0x18/0x34 > > > > > [ +0.000001] ubsan_epilogue+0x10/0x50 > > > > > [ +0.000002] __ubsan_handle_load_invalid_value+0xc8/0xd0 > > > > > [ +0.000003] locate_mem_hole_callback+0x28c/0x2a0 > > > > > [ +0.000003] kexec_locate_mem_hole+0xf4/0x2f0 > > > > > [ +0.000001] kexec_add_buffer+0xa8/0x178 > > > > > [ +0.000002] image_load+0xf0/0x258 > > > > > [ +0.000001] __arm64_sys_kexec_file_load+0x510/0x718 > > > > > [ +0.000002] invoke_syscall+0x68/0xe8 > > > > > [ +0.000001] el0_svc_common+0xb0/0xf8 > > > > > [ +0.000002] do_el0_svc+0x28/0x48 > > > > > [ +0.000001] el0_svc+0x40/0xe8 > > > > > [ +0.000002] el0t_64_sync_handler+0x84/0x140 > > > > > [ +0.000002] el0t_64_sync+0x1bc/0x1c0 > > > > > > > > > > To address this, initialise kexec_buf->random field properly. > > > > > > > > > > Fixes: bf454ec31add ("kexec_file: allow to place kexec_buf randomly") > > > > > > > > Thanks, I'll add a cc:stable to this. > > > > > > This has been fixed in below series from Breno Leitao. > > > > > > [PATCH 0/3] kexec: Fix invalid field access > > > https://lore.kernel.org/all/20250827-kbuf_all-v1-0-1df9882bb01a@debian.org/T/#u > > > > Right, these fixes are on 6.18 since day one. > > > > Yeoreum is hitting another code path that I haven't fixed, it seems > > (through image_load()). > > > > That said, I think the fix should be similar to commit 04d3cd43700 ("arm64: > > kexec: initialize kexec_buf struct in load_other_segments()"). I.e: > > > > --- a/arch/arm64/kernel/kexec_image.c > > +++ b/arch/arm64/kernel/kexec_image.c > > @@ -41,7 +41,7 @@ static void *image_load(struct kimage *image, > > struct arm64_image_header *h; > > u64 flags, value; > > bool be_image, be_kernel; > > - struct kexec_buf kbuf; > > + struct kexec_buf kbuf = {}; > > unsigned long text_offset, kernel_segment_number; > > struct kexec_segment *kernel_segment; > > int ret; > > FWIW, I completey agree; your proposal is a much better solution. Yes, maybe Yeoreum or Breno can post a new version to fix it on arm64. > > From a quick scan, it looks like loongarch also has some more dodgy > instances: In the latest mainline kernel, the problem on loongarch has gone. > > | % git grep 'struct kexec_buf\s[a-z_0-9]\+;' > | arch/arm64/kernel/kexec_image.c: struct kexec_buf kbuf; > | arch/loongarch/kernel/kexec_efi.c: struct kexec_buf kbuf; > | arch/loongarch/kernel/kexec_elf.c: struct kexec_buf kbuf; > | arch/loongarch/kernel/machine_kexec_file.c: struct kexec_buf kbuf; > | kernel/kexec_handover.c: struct kexec_buf scratch; > > The 'scratch' case in kernel/kexec_handover.c gets overwritten with a > struct assignment that'll happen to zero the 'random' field. > > Mark. >