Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp299535pxb; Fri, 5 Mar 2021 23:54:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2B40wLmVoOe9wi4NWxNuUniCJ2uVVFuiewVlpcV3SvzZ8jiEXN4JeqKEZRTZDson333zh X-Received: by 2002:aa7:c3c1:: with SMTP id l1mr13149703edr.208.1615017275066; Fri, 05 Mar 2021 23:54:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615017275; cv=none; d=google.com; s=arc-20160816; b=T2eyl4mqX8HdiHl7VrUobgX9oZlLDhKksx/R5n5CksYMCxU6OwNk/8MaSrqlu3Vkxu Q5fweIHViP5FLv8LHF8e3v+gGiYKSMbhT4o+jDM5+D3iIz0vSLE4mCfmQhXD34maWa2A ZiMeAKSn6bskxZ4qXXrfWJAzRavdhWxqHJ4m44nHaXxsRgUlCogCloPmKWpL0Ny+eHKU v1cRu34HkZrNi0NVaN+hgr+pJOjB2zLoOkfjHIaPPkvFu7EvdiRQIWKimIia7oAfRGvy oJrVOjD8kBz1P9w8YaXRVig2AAqSfNgfzcyVCDTBVHnaaO8LK0hdEQ2tsRQdCH8cYh2b vv1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=nAynTXbFAkNplw7BCDC3hyBApGxI8QfXe82pB5sWXLE=; b=vZiUjN5NvooS13BGzvCmJ9i/hdYdHi6WVToD2IZz7mmHVTaNvJRZpnSE08AZGBH7Po 6SFjAQck0E12DUQ4ay963K2HNS/PSlxKE3p63De1oKwUXnbO2Hi+Iz99lJgflckl7H+O HdEx+EbR2PmWvCBuiHQT7inDmX3fcqcvG2mHrp/zqMRkN1t2kj3UtBtMTtpwVMjnjyfc qlnNmsBXaddV4OqyNRZyXh7qratA2bucVO4RknFK1IXGymDaaQD45/yzrjhf0y6YaTgL 7LpzanRJTzhlIvixWm4Zwt8Xo6ld5HlSjQlosJA3iXm26OWanOokC4ofwPEPTv143FNC 8dNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l12si3214968edn.84.2021.03.05.23.54.12; Fri, 05 Mar 2021 23:54:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229782AbhCFHwv (ORCPT + 99 others); Sat, 6 Mar 2021 02:52:51 -0500 Received: from mail.loongson.cn ([114.242.206.163]:49602 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229637AbhCFHwn (ORCPT ); Sat, 6 Mar 2021 02:52:43 -0500 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxf_O+NENgpj0VAA--.26764S2; Sat, 06 Mar 2021 15:52:30 +0800 (CST) From: Tiezhu Yang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] riscv: Return -EFAULT if copy_{to,from}_user() failed in signal.c Date: Sat, 6 Mar 2021 15:52:29 +0800 Message-Id: <1615017149-24843-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Dxf_O+NENgpj0VAA--.26764S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tr13ZF18Ww4fGw17KFWfKrg_yoW8Zw1xpF 45Ca43Kr4xGFn7uas3Jw18WF95Ar93tFyIkr90k3WSyFs8trs8t34kJa4jqF4rJryrCw4v ka98trWYkw4rWr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkFb7Iv0xC_KF4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVW8JVWxJw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc2xSY4AK67AK6r4xMxAIw28I cxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2 IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI 42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42 IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E 87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jcYFXUUUUU= X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org copy_{to,from}_user() returns the amount left to copy, it should return -EFAULT error code if copy {to,from} user failed, just like the return value is an error code when {put,get}_user() failed, this is to make the return value consistent, no function change. Signed-off-by: Tiezhu Yang --- arch/riscv/kernel/signal.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c index 65942b3..c76d877 100644 --- a/arch/riscv/kernel/signal.c +++ b/arch/riscv/kernel/signal.c @@ -39,7 +39,7 @@ static long restore_fp_state(struct pt_regs *regs, err = __copy_from_user(¤t->thread.fstate, state, sizeof(*state)); if (unlikely(err)) - return err; + return -EFAULT; fstate_restore(current, regs); @@ -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++) { @@ -87,8 +87,12 @@ static long restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) { long err; + /* sc_regs is structured the same as the start of pt_regs */ err = __copy_from_user(regs, &sc->sc_regs, sizeof(sc->sc_regs)); + if (unlikely(err)) + return -EFAULT; + /* Restore the floating-point state. */ if (has_fpu) err |= restore_fp_state(regs, &sc->sc_fpregs); @@ -140,8 +144,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); -- 2.1.0