From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 5D56D3321CA for ; Mon, 15 Dec 2025 08:50:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765788634; cv=none; b=EQOAr/22jWcralF8cwbqMIVlSCIjllhPmhrRPSbpiUDgTDJe0dLT2ptwyRLJ1LcvjdY5vTMLF8eNTQOVF//0UYBitPgzcQzhlH9UfvyXhmKoymLGYwRc6kb+cyg00YIKIVkxuiGBKfmdtV618R/6a1RIPZ1FgMBtGO9kcgxoaq4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765788634; c=relaxed/simple; bh=eYaa0jvePZq/vAdO8sWnuueHTogbp2sDXIm+G7VvxIc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NF0aF9cSqgqOHWkyydqHfcikkMgq0MU8aSgOj4VVGnq+iadqArltFA7AzUZ4FTwovze/TTwTT7gIcQY3Gi6PEmM88mBFqqQpkr0hcO5wSQLmYOp8Duo4KfmExmJOhNiRrwJHjr9H+WSX0Luyks6U53/fzKLkgC0NV+TMPHU1iRw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=W30j/E+e; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W30j/E+e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765788631; 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=iqS8vgdM/pXRgmehW35ywc17iyd/2eXl+mmS1YO1Ya4=; b=W30j/E+ewleUVRq+sYEP70FRC1YFiPUhOnjn9mB4N80GdqPsaiiY+oiFwFyhIyfhCAnswF rY1j1JAIyUdbfKZRQmusTsUZEVuHdvljtExyD6snMb33PEnnfOn5JGAQ5aJIJ9BVXSLVg3 hzN29HrelgFZPP7NWP2mN+LuNQITCFY= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-22-GK6b0kyxN5CKldTZLk9MoA-1; Mon, 15 Dec 2025 03:50:29 -0500 X-MC-Unique: GK6b0kyxN5CKldTZLk9MoA-1 X-Mimecast-MFC-AGG-ID: GK6b0kyxN5CKldTZLk9MoA_1765788628 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2CAB018001FE; Mon, 15 Dec 2025 08:50:28 +0000 (UTC) Received: from localhost (unknown [10.72.112.95]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4EB7819560A7; Mon, 15 Dec 2025 08:50:25 +0000 (UTC) Date: Mon, 15 Dec 2025 16:50:21 +0800 From: Baoquan He To: Qiang Ma Cc: akpm@linux-foundation.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kexec: Fix uninitialized struct kimage *image pointer Message-ID: References: <20251212071656.834079-1-maqianga@uniontech.com> <84FB6FCADDAE5EBE+e11782ba-7483-40f4-8a40-a5e26f51183d@uniontech.com> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 On 12/15/25 at 12:41pm, Qiang Ma wrote: > > 在 2025/12/15 09:18, Baoquan He 写道: > > On 12/14/25 at 07:35pm, Qiang Ma wrote: > > > 在 2025/12/12 18:53, Baoquan He 写道: > > > > On 12/12/25 at 03:16pm, Qiang Ma wrote: > > > > > The image is initialized to NULL. Then, after calling kimage_alloc_init, > > > > > we can directly goto 'out' because at this time, the kimage_free will > > > > > determine whether image is a NULL pointer. > > > > Rechecked the code flow, in kimage_alloc_init(), if anything wrong, the > > > > allocated memory are all freed via out_free_control_pages and > > > > out_free_image accordingly, any place missed? If no, I think the current > > > > code is correctly handled. > > > I rechecked the code and found no omissions. > > Hmm, my bad, I didn't say my question clearly. I checked code, didn't > > find anything wrong in the current code. In kimage_alloc_init(), the > > allocated memory are all freed on failure, no memory leaked. Means you > > are fixing correct code. > Oh, I see. I recalled that this fix was in preparation for patch > "kexec: add kexec flag to control debug printing" for kexec_dbg_print > to be reset to false in kimage_free. > > In that case, I don't think this patch should be posted separately. If it's prepared for later patch, it should not be saying it's fixing issue. People may be confused and try to add it to stable kernel. > > > > > > > Signed-off-by: Qiang Ma > > > > > --- > > > > > kernel/kexec.c | 4 +++- > > > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > Acked-by: Baoquan He > > > > > > > > > diff --git a/kernel/kexec.c b/kernel/kexec.c > > > > > index 28008e3d462e..9bb1f2b6b268 100644 > > > > > --- a/kernel/kexec.c > > > > > +++ b/kernel/kexec.c > > > > > @@ -95,6 +95,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > > > > > unsigned long i; > > > > > int ret; > > > > > + image = NULL; > > > > > + > > > > > /* > > > > > * Because we write directly to the reserved memory region when loading > > > > > * crash kernels we need a serialization here to prevent multiple crash > > > > > @@ -129,7 +131,7 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > > > > > ret = kimage_alloc_init(&image, entry, nr_segments, segments, flags); > > > > > if (ret) > > > > > - goto out_unlock; > > > > > + goto out; > > > > > if (flags & KEXEC_PRESERVE_CONTEXT) > > > > > image->preserve_context = 1; > > > > > -- > > > > > 2.20.1 > > > > > > > >