From patchwork Tue Mar 2 07:28:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 12111043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99232C433DB for ; Tue, 2 Mar 2021 07:28:43 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F135D60295 for ; Tue, 2 Mar 2021 07:28:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F135D60295 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=dsvVSQq4rtVQJ+eBWmFlGFKjyPX/dQ+KNkQvI9VFB6Y=; b=0GrqJ+SiIBgWUm/PP8wT2RCMx2 5hzJY7LHFJVlYa2FgJo0fbuYdPOi4xd5Prq9oAzqlLKQnXX084sLVNWvoe3gO/CbHc2sQiggtmWpU yZdcBD1/81Hhn+/jk/DkpJxlYaix031ho7APtOmidkmv42hm2e1Gs9so0p2E/m5j8bKGv+p4+9WdN Rg6R19S1BrdsZkGAwu3j7vtsSOFkfyRi00VnpeWlZIET8ho0vketLJVbPt0IobV8biJjJOmmKLC6m avzPlxp/PObEUlAdQOQLZwDhC8sez7Epk9w7aQoIw2bblAHlVqpoIgTyFcoNepL+D5Qmw7sc4EPgn 7J2q00sw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lGzSK-0005aD-Pr; Tue, 02 Mar 2021 07:28:32 +0000 Received: from mail.loongson.cn ([114.242.206.163] helo=loongson.cn) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lGzSH-0005Z8-8y for linux-riscv@lists.infradead.org; Tue, 02 Mar 2021 07:28:30 +0000 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxr_AR6T1ggTMTAA--.7754S2; Tue, 02 Mar 2021 15:28:18 +0800 (CST) From: Tiezhu Yang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Subject: [PATCH] riscv: Return -EFAULT if copy_to_user() failed in signal.c Date: Tue, 2 Mar 2021 15:28:17 +0800 Message-Id: <1614670097-28536-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Dxr_AR6T1ggTMTAA--.7754S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Wr17Wry3Jry7CF1DGrykXwb_yoW8Jr1DpF 4UCa4xKrW8GrnruF9ayw1kW34rJ3saqa4xKr90k3W3AFs0qr45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ID: sfid-20210302_022829_857307_ABC1E52D X-CRM114-Status: UNSURE ( 9.64 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org copy_to_user() returns the amount left to copy, it should return -EFAULT if copy to user failed. Signed-off-by: Tiezhu Yang Signed-off-by: Tiezhu Yang --- arch/riscv/kernel/signal.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index 65942b3..2238fc5 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -67,7 +67,7 @@ static long save_fp_state(struct pt_regs *regs, fstate_save(current, regs); err = __copy_to_user(state, ¤t->thread.fstate, sizeof(*state)); if (unlikely(err)) - return err; + return -EFAULT; /* We support no other extension state at this time. */ for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) { @@ -140,8 +140,12 @@ static long setup_sigcontext(struct rt_sigframe __user *frame, { struct sigcontext __user *sc = &frame->uc.uc_mcontext; long err; + /* sc_regs is structured the same as the start of pt_regs */ err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs)); + if (unlikely(err)) + return -EFAULT; + /* Save the floating-point state. */ if (has_fpu) err |= save_fp_state(regs, &sc->sc_fpregs);