From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932452AbbJPK5Z (ORCPT ); Fri, 16 Oct 2015 06:57:25 -0400 Received: from foss.arm.com ([217.140.101.70]:40750 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753839AbbJPK5W (ORCPT ); Fri, 16 Oct 2015 06:57:22 -0400 Date: Fri, 16 Oct 2015 11:57:17 +0100 From: Mark Rutland To: yalin wang Cc: catalin.marinas@arm.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, matt.fleming@intel.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: change to use memmove in efi-stub Message-ID: <20151016105716.GB975@leverpostej> References: <1444992367-11121-1-git-send-email-yalin.wang2010@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1444992367-11121-1-git-send-email-yalin.wang2010@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Oct 16, 2015 at 06:46:07PM +0800, yalin wang wrote: > Change to use memmove(), in case the dest address overlap with the > source address. This cannot happen, and memove would not be sufficient if it did. The destination is a region returned by EFI_BOOT_SERVICES.AllocatePages, which can only allocate pages which were free to begin with. Therefore the new region cannot overlap with the stub (whose pages are not free). Were the new region to overlap with the stub, the memmove could corrupt the code/data in use by the stub, and things would explode shortly thereafter. Thanks, Mark. > > Signed-off-by: yalin wang > --- > arch/arm64/kernel/efi-stub.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c > index 816120e..b6dc44b 100644 > --- a/arch/arm64/kernel/efi-stub.c > +++ b/arch/arm64/kernel/efi-stub.c > @@ -59,7 +59,7 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg, > } > *image_addr = *reserve_addr + TEXT_OFFSET; > } > - memcpy((void *)*image_addr, old_image_addr, kernel_size); > + memmove((void *)*image_addr, old_image_addr, kernel_size); > *reserve_size = kernel_memsize; > } > > -- > 1.9.1 >