Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp7084288rdb; Fri, 15 Dec 2023 18:22:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMyh2ZtxQ5cNQqI/NKQNSlXi4C+hjb/yoECxXhrkpaCgTp2W8uR6+WUGjJ7iRGatcm0bxn X-Received: by 2002:a05:6830:1508:b0:6da:e0f:b45e with SMTP id k8-20020a056830150800b006da0e0fb45emr11165375otp.2.1702693336063; Fri, 15 Dec 2023 18:22:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702693336; cv=none; d=google.com; s=arc-20160816; b=gzs5/sH/m21EUZWI+csphyyTM15gawkwWrRR1jQQUMpRLAE5oQKSN1jYKyaQlpM37t 0v2laaOmIWJych6tEBAsLUxuc9mEEDomgxzJSZNCMGS3we/DtJ4KTSvsSkErxZ2nGZb7 m1rI3TmqFAsVN56TP/MXTR6OcOSK1LgD14q7VE6Dq2O6MN1ZJNVp8E9MXDyc8jvyd80d 7ArUxA7hjck/4eZIQVsu5FQdH1oghY8qMoH78GQj9WRKOV2FAvq46bY0jyZWgbdisgfM kPfrTsU10W0Y/CYDV647NVcNF8tF4z/VhPsrL78BQV25TVbx0qgeQ4eIN9jLvHZ/mXXB JKcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YDbMrrJMxJaNaZxmdjaWs9yxNCXUr/R3B3gdWPDjk0k=; fh=Ni8vHQ6GXst/Ww32zTnD27fDqsZlSGj0CR0B9yAYxVg=; b=DBReSqt88BhMeWcycEFAfHzBdVHU05B9JtJo+fHODdwkBZH4t56CK8qnD5BIXAPxg7 IWgDhu7PH7TxNVFJrkt3xdsduJUoJ8sbtYlSzW5WxAS9Tw9i+DbEwqmTqR0MCZXpeWGq H2pmVZevG+X4uFAW+dbr1ODmXMIbTCq4wrAEXwbA2TAksrzLrzfZD0/+d1194Gkx1rj+ C3d6W+slm9Ydmu4RbXmv0MbC7f/JOqlYSGYpsEpuDA1FSzWg3WbtNb+QerQLF3ycT0G9 bahxweVNyKgVdlIamT7kqjcqcZnmtGqNDHTkYDaqK2fJaGxTcFtUkTtNeZIK4puFs17M MjuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fEA3rY3e; spf=pass (google.com: domain of linux-kernel+bounces-1956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f13-20020a056a001acd00b006cdce1d5ac7si14311808pfv.17.2023.12.15.18.22.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 18:22:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fEA3rY3e; spf=pass (google.com: domain of linux-kernel+bounces-1956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 802ACB23E49 for ; Sat, 16 Dec 2023 02:22:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41B381875; Sat, 16 Dec 2023 02:22:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fEA3rY3e" X-Original-To: linux-kernel@vger.kernel.org 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 CDA7317E8 for ; Sat, 16 Dec 2023 02:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702693322; 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=YDbMrrJMxJaNaZxmdjaWs9yxNCXUr/R3B3gdWPDjk0k=; b=fEA3rY3eiznHEi3gyBPLVBBsONlahCgJXFbhIHYftpDYiueXoHqZX8QSPpUMyhRC//KQvc XSh+jgIAAsh+/kLjZYVjzE2DAEtIL5c3AWkaPtwn6EVr6Q9c2N0bUIFO/OIpQE+hVN4zHm TWmnbPJSOEnHaMIo+ogXM62yfe34ew8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-VuBV7y_tPXOverfdkz6vmw-1; Fri, 15 Dec 2023 21:21:59 -0500 X-MC-Unique: VuBV7y_tPXOverfdkz6vmw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 427523C025BD; Sat, 16 Dec 2023 02:21:58 +0000 (UTC) Received: from localhost (unknown [10.72.116.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E9F871C060B1; Sat, 16 Dec 2023 02:21:56 +0000 (UTC) Date: Sat, 16 Dec 2023 10:21:53 +0800 From: Baoquan He To: "Eric W. Biederman" Cc: Yuntao Wang , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, x86@kernel.org, Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Jonathan Corbet Subject: Re: [PATCH 1/3] kexec_file: fix incorrect end value passed to kimage_is_destination_range() Message-ID: References: <20231215080910.173338-1-ytcoode@gmail.com> <20231215080910.173338-2-ytcoode@gmail.com> <87a5qb4avf.fsf@email.froward.int.ebiederm.org> 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-Disposition: inline In-Reply-To: <87a5qb4avf.fsf@email.froward.int.ebiederm.org> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 On 12/15/23 at 11:46am, Eric W. Biederman wrote: > Yuntao Wang writes: > > > The end parameter received by kimage_is_destination_range() should be the > > last valid byte address of the target memory segment plus 1. However, in > > the locate_mem_hole_bottom_up() and locate_mem_hole_top_down() functions, > > the corresponding value passed to kimage_is_destination_range() is the last > > valid byte address of the target memory segment, which is 1 less. Fix > > it. > > If that is true we I think we should rather fix > kimage_is_destination_range. It's true wit the current implementation of kimage_is_destination_range(). Its callers pass the start/end+1 pair. Agree we should fix kimage_is_destination_range() instead and adjust callers, such as kimage_alloc_normal_control_pages(), and kimage_alloc_page(). > > Otherwise we run the risk of having areas whose end is not > representable, epecially on 32bit. > > > Eric > > > > Signed-off-by: Yuntao Wang > > --- > > kernel/kexec_file.c | 7 +++---- > > 1 file changed, 3 insertions(+), 4 deletions(-) > > > > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > > index f9a419cd22d4..26be070d3bdd 100644 > > --- a/kernel/kexec_file.c > > +++ b/kernel/kexec_file.c > > @@ -435,13 +435,12 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end, > > if (temp_start < start || temp_start < kbuf->buf_min) > > return 0; > > > > - temp_end = temp_start + kbuf->memsz - 1; > > - > > /* > > * Make sure this does not conflict with any of existing > > * segments > > */ > > - if (kimage_is_destination_range(image, temp_start, temp_end)) { > > + if (kimage_is_destination_range(image, temp_start, > > + temp_start + kbuf->memsz)) { > > temp_start = temp_start - PAGE_SIZE; > > continue; > > } > > @@ -475,7 +474,7 @@ static int locate_mem_hole_bottom_up(unsigned long start, unsigned long end, > > * Make sure this does not conflict with any of existing > > * segments > > */ > > - if (kimage_is_destination_range(image, temp_start, temp_end)) { > > + if (kimage_is_destination_range(image, temp_start, temp_end + 1)) { > > temp_start = temp_start + PAGE_SIZE; > > continue; > > } > > _______________________________________________ > kexec mailing list > kexec@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kexec >