From patchwork Wed Nov 7 16:43:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 150434 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5387517ljp; Wed, 7 Nov 2018 08:44:28 -0800 (PST) X-Received: by 2002:aed:3e39:: with SMTP id l54mr970489qtf.342.1541609068116; Wed, 07 Nov 2018 08:44:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541609068; cv=none; d=google.com; s=arc-20160816; b=oETTpjrmPNY4uAcpkb/QiBji0vSqggIUdWbYs66eCuIjDbv0ggPDOZVxareDLPSorw kr+v6KHj8v4ufgvi170t6fMbACJpFmjgBV+c48hcXt+e+xoAnmh9C9BYckPkjTeRiQXc OziVkVNhvrqJHrd0iDQDGN9bDARyFo7JcunnUNsqnOZJyxtQLWc4o4pwdK/FOOX4TSBG 7jK/tln/AiAAqpMhr66G7Q002XttxTIBn73L6lVt89tZq8zdT9UoKuQZl4kZ4gcB8Sxj JLX483vjxHi57d6Oc86GB+IokX2WaFIGbgYHSM5wSN4IVr8qiIqnkV/9uKzNqX0r3V3S eXig== 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=qa5Mci7cMAGvawpk5a6Wtf5f3dHfZJJnbCtGATwkUMw=; b=hv5mDx3B4bMrfs/PtgJMJlS+mO1OVyruMaZWfF5TLRutHJjUCTsE6+Y3SIO3CqmNuH C/DlVUM3KLlRtr60HIYBcr66QrUR8LEpHF8xxhvHcHosQj7pB9/uzXtnl5u/VihEFury jweVLrRftJdpnJkGzboeHMlx3nd8LckLMsH5bln75PJWaKUBlRGRVTWo7SV577AiDecg FHOzetHEuRvgNUWm4+SJ8sqDeN2p0/dueumzxtrYj8Dur/P8VU9y45pdDsyv9ZiWEljl I9+M+xFwtUP2gybKzq/azpFzNJ2VXZ8s/zLIWNoIlZwUCE9GKTlpbuZCqsppTSupV8z0 hXTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BjVn6png; 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 h28-v6sor1313943qtc.5.2018.11.07.08.44.27 for (Google Transport Security); Wed, 07 Nov 2018 08:44:28 -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=BjVn6png; 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=qa5Mci7cMAGvawpk5a6Wtf5f3dHfZJJnbCtGATwkUMw=; b=BjVn6pngKtfQQ2aNkc2Lxw+6GJUWO2VsiatHKFkG+6M23hVYC8q7YXZG9MXFsAEuAA 2ILoKgN0kB2Tt8b/OumH0VO7QiRqreclcASeijyEPBqNL2/cKQf0AD75TqU7o1Rqh3E0 hcBxwNJXYIt+zqjpa5c4wA7isClJl4LfH5RFg= 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=qa5Mci7cMAGvawpk5a6Wtf5f3dHfZJJnbCtGATwkUMw=; b=Wzitf8ur/4m4BsDAcokWqRuGmn/8Smd2jARQbXeoyaiRtVNRQo1bR7+6WN/5m8E9VB brlQ3gkEJTZWKXWNm+Ga5zZGWYLm0H6evXWXCTkCbSRKVFHhqmzRgIghWUAzgsmoSxn1 IyUvM85qORdNcQxi4MhCz7j68W4Z9e64A4FXKMw1B9XO6TrDIrAZBj7j0CXcEe+6V0SU fu89O2LFKYOUNvEKyduSQ/JfS/mYcE5yEnHLxA7TIEvGdMEB6EHpNvFjwO0cCp/Mi8BA P4pY8GAj0HwFYcV2U2gH5TgNNGE+PVqcC9l1PuxpGAx5MCVVNZKkQJtgzM0HPr9Ch1fS l5hg== X-Gm-Message-State: AGRZ1gL9xhpApjsFL6RNGH9kK+IG/QExX/SF8jc9bosQixnnXIfJqYhU 9UDj8l9UYlkGs46RMaKPF2icd9jr X-Google-Smtp-Source: AJdET5d7JsAE96ij/ocES2lrnlInknCKPGOSvyrFSu7Ns8TKftjfgdPvdPcByOXvVDurUb0mYAiviw== X-Received: by 2002:ac8:18fa:: with SMTP id o55mr985476qtk.256.1541609067511; Wed, 07 Nov 2018 08:44:27 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 08:44:27 -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 19/24] ARM: signal: copy registers using __copy_from_user() Date: Wed, 7 Nov 2018 11:43:57 -0500 Message-Id: <20181107164402.9380-20-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 c32cd419d6650e42b9cdebb83c672ec945e6bd7e 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. It becomes much more efficient to use __copy_from_user() instead, so let's use this for the ARM integer registers. Acked-by: Mark Rutland Signed-off-by: Russell King Signed-off-by: David A. Long --- arch/arm/kernel/signal.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) -- 2.17.1 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 7b8f2141427b..a592bc0287f8 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -141,6 +141,7 @@ struct rt_sigframe { static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf) { + struct sigcontext context; struct aux_sigframe __user *aux; sigset_t set; int err; @@ -149,23 +150,26 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf) if (err == 0) set_current_blocked(&set); - __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err); - __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err); - __get_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err); - __get_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err); - __get_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err); - __get_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err); - __get_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err); - __get_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err); - __get_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err); - __get_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err); - __get_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err); - __get_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err); - __get_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err); - __get_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err); - __get_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err); - __get_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err); - __get_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err); + err |= __copy_from_user(&context, &sf->uc.uc_mcontext, sizeof(context)); + if (err == 0) { + regs->ARM_r0 = context.arm_r0; + regs->ARM_r1 = context.arm_r1; + regs->ARM_r2 = context.arm_r2; + regs->ARM_r3 = context.arm_r3; + regs->ARM_r4 = context.arm_r4; + regs->ARM_r5 = context.arm_r5; + regs->ARM_r6 = context.arm_r6; + regs->ARM_r7 = context.arm_r7; + regs->ARM_r8 = context.arm_r8; + regs->ARM_r9 = context.arm_r9; + regs->ARM_r10 = context.arm_r10; + regs->ARM_fp = context.arm_fp; + regs->ARM_ip = context.arm_ip; + regs->ARM_sp = context.arm_sp; + regs->ARM_lr = context.arm_lr; + regs->ARM_pc = context.arm_pc; + regs->ARM_cpsr = context.arm_cpsr; + } err |= !valid_user_regs(regs);