Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp626128iog; Mon, 13 Jun 2022 09:23:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sMOMrjh4beIVYmu+Mtr50A/Xxjrd8WEMj34rkehosk6pgEeDD0VQQeO8zAoh0d9w1oAyha X-Received: by 2002:a17:902:830b:b0:168:e27c:1a56 with SMTP id bd11-20020a170902830b00b00168e27c1a56mr433167plb.152.1655137431525; Mon, 13 Jun 2022 09:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655137431; cv=none; d=google.com; s=arc-20160816; b=kDu3YC3teJGN9tRg9hXBBSxsJF6LxlCKNitWY1LQpJ4UfdBcKK/nVXr/QN6dyYg21E GUtpEVZHW//ZkUBgQPHuri89eueTzQo7xfVQgIcmbsmqOeqBIWkvkGjPpju34vTmBfGT DKqTTMKLKwsg5iUVG7UcXH0oOwu7h+XRviV9i7zCh/pQ+1PnyvkLaHHcn7a2WwBTowjU OUAlfFCn0mY/WDu2MASd3UBhNlA7tRjBYlsp5of2Og9+QZdvSNEFkXHgUb3js0f/6wje glN9Kf12fYn+qsLIyfyMffx53gk6pYBn7vycT8oO63GzcH3sLBoYtLcM6xzxMBT49d5v F4Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TDKprvpbRwftE38hIEc++1FwYUSTqX8XcD2p9WcmPnw=; b=im2tSV/nPK6GiKXe7RodtEb4ypkjCMhg1Y0uStCB9B9OkwMDKazMGkcdYrAZ0+ch9V IzaJp1pNuMWJt3gu69Foc153jRakMNFyVPMoFrecau1X7LhdZ6pQrNi1Iev6PStE43WP HWb1JgVGb0yDBAK/gAq4vl4FwkT523sNuN1m3Q/X/MAIkOQ5MMgnjCDzbJJ7vAZcYpD8 6spMZ1r0lU1/T1Tw/ngSmoXUmYa8PgGujg/o670DuUG+htsoygoD36GfjoN68rRnBHfj 9vM8/dD3zyDvBGmREqUEPZf6mo2CpqnacOEAIM9NjJdMITvWpzzUadm6BlehKAxxwXkv Qc/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tLkrBctf; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020a170902dacd00b001622a77631esi11255099plx.594.2022.06.13.09.23.37; Mon, 13 Jun 2022 09:23:51 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=tLkrBctf; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358989AbiFMNIs (ORCPT + 99 others); Mon, 13 Jun 2022 09:08:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357313AbiFMM6j (ORCPT ); Mon, 13 Jun 2022 08:58:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D43562BC3; Mon, 13 Jun 2022 04:17:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B342360F0D; Mon, 13 Jun 2022 11:17:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1B8AC34114; Mon, 13 Jun 2022 11:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119062; bh=orI7NLzyYAo4r79BAJZsq8oCnJd/A00pdqYpG0bPBhw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tLkrBctfky2R9cv4dnvIPfr8qTqSgi/Dx899ummZqwnn3yzolAw3LCAWLrVJqEkZZ JmpWd8XJnioqA9ryqu6M9fDSyg4F/f1cIeBr3pPgLIixHts5uyNR7bBvtjNvFtB83F NTi6HCe3NDWYkQhScd77R8ezfwquxoMFVezdHK0M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liao Chang , Palmer Dabbelt , Sasha Levin Subject: [PATCH 5.15 126/247] RISC-V: use memcpy for kexec_file mode Date: Mon, 13 Jun 2022 12:10:28 +0200 Message-Id: <20220613094926.782568314@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Liao Chang [ Upstream commit b7fb4d78a6ade6026d9e5cf438c2a46ab962e032 ] The pointer to buffer loading kernel binaries is in kernel space for kexec_fil mode, When copy_from_user copies data from pointer to a block of memory, it checkes that the pointer is in the user space range, on RISCV-V that is: static inline bool __access_ok(unsigned long addr, unsigned long size) { return size <= TASK_SIZE && addr <= TASK_SIZE - size; } and TASK_SIZE is 0x4000000000 for 64-bits, which now causes copy_from_user to reject the access of the field 'buf' of struct kexec_segment that is in range [CONFIG_PAGE_OFFSET - VMALLOC_SIZE, CONFIG_PAGE_OFFSET), is invalid user space pointer. This patch fixes this issue by skipping access_ok(), use mempcy() instead. Signed-off-by: Liao Chang Link: https://lore.kernel.org/r/20220408100914.150110-3-lizhengyu3@huawei.com Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/kernel/machine_kexec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c index cbef0fc73afa..df8e24559035 100644 --- a/arch/riscv/kernel/machine_kexec.c +++ b/arch/riscv/kernel/machine_kexec.c @@ -65,7 +65,9 @@ machine_kexec_prepare(struct kimage *image) if (image->segment[i].memsz <= sizeof(fdt)) continue; - if (copy_from_user(&fdt, image->segment[i].buf, sizeof(fdt))) + if (image->file_mode) + memcpy(&fdt, image->segment[i].buf, sizeof(fdt)); + else if (copy_from_user(&fdt, image->segment[i].buf, sizeof(fdt))) continue; if (fdt_check_header(&fdt)) -- 2.35.1