From patchwork Wed Nov 7 16:43:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 150435 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5387532ljp; Wed, 7 Nov 2018 08:44:29 -0800 (PST) X-Received: by 2002:ac8:8e1:: with SMTP id y30mr954718qth.3.1541609069036; Wed, 07 Nov 2018 08:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541609069; cv=none; d=google.com; s=arc-20160816; b=iCCr7nDOVHhpLvF/KlcOZBdnDa5S8yHSS6aBSEtmEWmb+u/CgnfKSnWLBaZmPXhk6o RLQilUsqxs30tOss/eKOrG6ciYnp7vFQZKRzMPP2D4TFGX2SKP6Sa/qLLeYHzMm/6D3z Xmeu/0Pnts60UEUKVdspSL88K/+2to5ghlfanRV1jSGq2M7DmFl10BFGyZy3Vo2RjEkk H7ZOCy9kfjXWc5zAmaaug/vwkcPKxmIzFDqPieN9NVvjLwGFn/iQY0zyxUXiPDm3HeDo C9nnP4lr25nyU3p+7QoDueaxiOfpgotb8zkP/6f7Yii0hyiKz/I0FbNd+l7BEbxcwNvT Hx2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WU9LGXkuIzC4CcOmIihXYGuiNacUrn4d35aRch3bjb8=; b=uj6k5pgQlG86xF+GcuuWZ3cs+nMSc8uxQpthce5+kUKWboiES7n7D5tUJw55DGZxiv JTBt4HmVXe3TWukcKibWr69kP9omGsP7mEpN4rduHTJdjtE6oyChiQin5p+/FWUGgEAr CNvZvghKoM+gk+1myn5QyntNR04ZLFD+73aIEM2BO8/at1/voA0Am2ZNXEynhegHTMpM 4f3LWUHcg0jsizZLNNkjNCXsJdQtecTCRd7KmDcy9pfCXNw7noPuzcokbdWObdJXAApT LY9R+EhcElywrr1vp8IRdfIPpqL/jgJtUhFcmdviFi+VZ9xZDfWSS4YCHvAUn7LjxqYA 1Y2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZobLEn5x; spf=pass (google.com: domain of dave.long@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=dave.long@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r7-v6sor1290134qtp.59.2018.11.07.08.44.28 for (Google Transport Security); Wed, 07 Nov 2018 08:44:29 -0800 (PST) Received-SPF: pass (google.com: domain of dave.long@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZobLEn5x; spf=pass (google.com: domain of dave.long@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=dave.long@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WU9LGXkuIzC4CcOmIihXYGuiNacUrn4d35aRch3bjb8=; b=ZobLEn5xpShr6Z/LLJVrLZC3J04izG0pJG1XcuKJCgDL7r7I2xNjjeWZVaH+7elvAF KcrE1Ix2SmnMhuq4OQFyPGMFnfyk+nQoAPVCk5NRccWHAyE6viwgqdQlCXcKEObwjMqb vgf2DlOk8FDL8vvLaKazvO5R00eY5E4RrNhcg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WU9LGXkuIzC4CcOmIihXYGuiNacUrn4d35aRch3bjb8=; b=NXw1U6H77sfmq51BSWqxwdaCpwXoR+qE0sApKWilgcMjJluspktYE4+FdmSEa2aSl5 JjtZ3KfeYZfIAK+49na0pAmj74+OKCeTJD/up0M+5DqfrIfk8dYPYslrE7NKLRlWnTAC hY9DHG929pbqnacUa4pancb8Ka5ez3c1gUARi/2VXLz1Xup7AMtHwQpFVPbEZszbpPds A4KXevpAjZl870//2l3tqcbfC3RqgltTzcgVdTO48AW9UsEpw0sAb0EwtkyrpoguTFCD 7YQGQT5evRK1rm3xoLgRMl8+6HOfVeRioXIo8sgzMGezRJEOlbT/Gw6m6Er+FgryYKUW GnGg== X-Gm-Message-State: AGRZ1gJwRynRbPdgINI05CLpDkKAsr3ibt5+GQHeyPrVW8kfgVHMNH3e WwS8MNqHqZ9sF2vEZj8eIhgpfjjw X-Google-Smtp-Source: AJdET5e8nO4E6e20tAh5eFvrNSDPV8029uITrK16Aagcn7pDxg98jzyTwopL1v/K3W4t/LOIr+sm2w== X-Received: by 2002:ac8:839:: with SMTP id u54mr905309qth.313.1541609068521; Wed, 07 Nov 2018 08:44:28 -0800 (PST) Return-Path: Received: from localhost.localdomain (pool-72-71-243-63.cncdnh.fast00.myfairpoint.net. [72.71.243.63]) by smtp.googlemail.com with ESMTPSA id 96-v6sm681817qtc.56.2018.11.07.08.44.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 08:44:28 -0800 (PST) From: David Long To: stable@vger.kernel.org, Russell King - ARM Linux , Florian Fainelli , Tony Lindgren , Marc Zyngier , Mark Rutland Cc: Greg KH , Mark Brown Subject: [PATCH 4.9 V2 20/24] ARM: vfp: use __copy_from_user() when restoring VFP state Date: Wed, 7 Nov 2018 11:43:58 -0500 Message-Id: <20181107164402.9380-21-dave.long@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181107164402.9380-1-dave.long@linaro.org> References: <20181107164402.9380-1-dave.long@linaro.org> From: Russell King Commit 42019fc50dfadb219f9e6ddf4c354f3837057d80 upstream. __get_user_error() is used as a fast accessor to make copying structure members in the signal handling path as efficient as possible. However, with software PAN and the recent Spectre variant 1, the efficiency is reduced as these are no longer fast accessors. In the case of software PAN, it has to switch the domain register around each access, and with Spectre variant 1, it would have to repeat the access_ok() check for each access. Use __copy_from_user() rather than __get_user_err() for individual members when restoring VFP state. Acked-by: Mark Rutland Signed-off-by: Russell King Signed-off-by: David A. Long --- arch/arm/include/asm/thread_info.h | 4 ++-- arch/arm/kernel/signal.c | 17 ++++++++--------- arch/arm/vfp/vfpmodule.c | 17 +++++++---------- 3 files changed, 17 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h index 776757d1604a..57d2ad9c75ca 100644 --- a/arch/arm/include/asm/thread_info.h +++ b/arch/arm/include/asm/thread_info.h @@ -126,8 +126,8 @@ struct user_vfp_exc; extern int vfp_preserve_user_clear_hwstate(struct user_vfp __user *, struct user_vfp_exc __user *); -extern int vfp_restore_user_hwstate(struct user_vfp __user *, - struct user_vfp_exc __user *); +extern int vfp_restore_user_hwstate(struct user_vfp *, + struct user_vfp_exc *); #endif /* diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index a592bc0287f8..6bee5c9b1133 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -107,21 +107,20 @@ static int preserve_vfp_context(struct vfp_sigframe __user *frame) return vfp_preserve_user_clear_hwstate(&frame->ufp, &frame->ufp_exc); } -static int restore_vfp_context(struct vfp_sigframe __user *frame) +static int restore_vfp_context(struct vfp_sigframe __user *auxp) { - unsigned long magic; - unsigned long size; - int err = 0; + struct vfp_sigframe frame; + int err; - __get_user_error(magic, &frame->magic, err); - __get_user_error(size, &frame->size, err); + err = __copy_from_user(&frame, (char __user *) auxp, sizeof(frame)); if (err) - return -EFAULT; - if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE) + return err; + + if (frame.magic != VFP_MAGIC || frame.size != VFP_STORAGE_SIZE) return -EINVAL; - return vfp_restore_user_hwstate(&frame->ufp, &frame->ufp_exc); + return vfp_restore_user_hwstate(&frame.ufp, &frame.ufp_exc); } #endif diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 5629d7580973..8e5e97989fda 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -597,13 +597,11 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp, } /* Sanitise and restore the current VFP state from the provided structures. */ -int vfp_restore_user_hwstate(struct user_vfp __user *ufp, - struct user_vfp_exc __user *ufp_exc) +int vfp_restore_user_hwstate(struct user_vfp *ufp, struct user_vfp_exc *ufp_exc) { struct thread_info *thread = current_thread_info(); struct vfp_hard_struct *hwstate = &thread->vfpstate.hard; unsigned long fpexc; - int err = 0; /* Disable VFP to avoid corrupting the new thread state. */ vfp_flush_hwstate(thread); @@ -612,17 +610,16 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp, * Copy the floating point registers. There can be unused * registers see asm/hwcap.h for details. */ - err |= __copy_from_user(&hwstate->fpregs, &ufp->fpregs, - sizeof(hwstate->fpregs)); + memcpy(&hwstate->fpregs, &ufp->fpregs, sizeof(hwstate->fpregs)); /* * Copy the status and control register. */ - __get_user_error(hwstate->fpscr, &ufp->fpscr, err); + hwstate->fpscr = ufp->fpscr; /* * Sanitise and restore the exception registers. */ - __get_user_error(fpexc, &ufp_exc->fpexc, err); + fpexc = ufp_exc->fpexc; /* Ensure the VFP is enabled. */ fpexc |= FPEXC_EN; @@ -631,10 +628,10 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp, fpexc &= ~(FPEXC_EX | FPEXC_FP2V); hwstate->fpexc = fpexc; - __get_user_error(hwstate->fpinst, &ufp_exc->fpinst, err); - __get_user_error(hwstate->fpinst2, &ufp_exc->fpinst2, err); + hwstate->fpinst = ufp_exc->fpinst; + hwstate->fpinst2 = ufp_exc->fpinst2; - return err ? -EFAULT : 0; + return 0; } /*