Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp949022pxb; Wed, 3 Mar 2021 22:11:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxNbWkjfyUgA33O40uf6Om0K3HPlyyUyhuxEsaSEoIymVKiB5bgRHqtJn0xyH2onWKjHmP X-Received: by 2002:a17:906:e84:: with SMTP id p4mr2471996ejf.30.1614838271634; Wed, 03 Mar 2021 22:11:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614838271; cv=none; d=google.com; s=arc-20160816; b=f0DINegbf0EKDX0Tm0xENRD3kFvyZ8Tpbf/f4Z2zk5D4npkdTDcfHZ2hmvQqq/B8Yb Y/nkbsGn9xUFEeIkTo9wn8vnDgBQ97SZEJ0EgqaM43CEQscwsr2XOHDdaLc4WMiwVS+m K1HAKsfh4zOWPzobrwC6bZNRsAOthwEmFrGabnabkIKx2Wy9xbddT4uJaXcEvUUZIZgf 1YuYIwgIh5Of6hfSn/BuvYcZm/wEOgo86jdzUCTyJbpdRbuslmSJ6JvcBQ9v8aRj55TC BRva7WFooCNy3Fh29xgBQMAobeVt7ZAd6zxIovzvlZoTZoK3jpwsPmCGmCBFt6K6k4dS eLhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject; bh=kkTJ+FNw3uRtA0eIlJwgy0I6aBGcXCXFzAeVy1QZ4zY=; b=V3AV80FToNY/3PL292wW+ySuSqISe3mj+X2PbkvXKA1HsIONbe8w/Edj2M5aW2Wo/l eZN5BePTfkewYJWFodlKbtjYo6lC6sLjGL5Zn81zcQsMfH0TMyPiPf0rUlI8At97lk3g pA9lX1wRaTsUZoS6nTrn83GNX6LO8/gv31ebWWnEZzfaTsQu5M02SjUL309ORZnBE4ro kABozqErtzXNOGnctek6qCDVLKTjN5PdPiP9k275TbzTV5k6Tn91zmSfPKcp0kU+178n 7W0ONtoLlgNLe/nD66/ydQThOo34Ki8vPJHDm3l5MViZBE+kOFKkTR8aAiTJb1sePeEq YUqQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u27si13721391ejj.726.2021.03.03.22.10.23; Wed, 03 Mar 2021 22:11:11 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442011AbhCBKxN (ORCPT + 99 others); Tue, 2 Mar 2021 05:53:13 -0500 Received: from imap3.hz.codethink.co.uk ([176.9.8.87]:48974 "EHLO imap3.hz.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1578024AbhCBKfI (ORCPT ); Tue, 2 Mar 2021 05:35:08 -0500 Received: from cpc79921-stkp12-2-0-cust288.10-2.cable.virginm.net ([86.16.139.33] helo=[192.168.0.18]) by imap3.hz.codethink.co.uk with esmtpsa (Exim 4.92 #3 (Debian)) id 1lH1qB-0006FQ-M0; Tue, 02 Mar 2021 10:01:19 +0000 Subject: Re: [PATCH] riscv: Return -EFAULT if copy_to_user() failed in signal.c To: Tiezhu Yang , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <1614670097-28536-1-git-send-email-yangtiezhu@loongson.cn> From: Ben Dooks Organization: Codethink Limited. Message-ID: Date: Tue, 2 Mar 2021 10:01:18 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <1614670097-28536-1-git-send-email-yangtiezhu@loongson.cn> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/03/2021 07:28, Tiezhu Yang wrote: > copy_to_user() returns the amount left to copy, it should return -EFAULT > if copy to user failed. This looks technically correct, but the caller (only one) will check for non-zero and will covert that to -EFAULT in setup_rt_frame(). I expect if this change is done, it also needs to be done for the callers too and there's a few others than assume !=0 is an error. I think it would be easier to define save_fp_state() to return non-zero on error and note it does not return an error code. It may be worth exiting the functio nif the first __copy_to_user fails? Note: setup_rt_frame -> setup_sigcontext -> save_fp_frame > > 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); > -- Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html