From patchwork Wed Oct 31 14:04:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 149832 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6836375ljp; Wed, 31 Oct 2018 07:05:00 -0700 (PDT) X-Received: by 2002:a1f:9bc7:: with SMTP id d190mr1352431vke.5.1540994700221; Wed, 31 Oct 2018 07:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540994700; cv=none; d=google.com; s=arc-20160816; b=xyYnulfjdD1cBVZgZcrfwKbN3uko4vl+HFtgsbiwZAekkJqNWd0Q8VXZC3Kr3XuLcM PjRDafjCXxXMTqTYkRey/tp8iCzxJ3s0nN6qFegPM5ZIy6bzFSvoTwFXYQUzNWUkDl9M ILJiMoDiVYo2KDKpD3VsqNYD5kyXm07IdFlG5Go0b2iehUwnGkmu2rOJeHbnibPovT4T KNGomg6w/GQTgobv/m5Cb7NT3IlVNEdzL6r6xP4dyJ28O3A+LtDBUmM4FfOdEcH8TKNQ BvpWLmcpeEmPXcNNrxyJV8AkUwPkJw7ReSH3eIQQx+dyMIoGAPnaxcb3fJ102s1P8RKd MSuw== 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=GzVmVj9k1/WgUWxuQmTghcnK3MXG1neXRIirdHtWc6SwnSjP/bhdQJStvB9dpeGX9y 9bpyN4/521+MgXJasoTDxzO01bW4QrBHP81YqoGLfupY0hwLELjTV6Thz7/NQtsI2ltI WNcxPLmj9dGGH6rX72c2hiz9ZcKUrFgeH1zttvEbmh46YKV8V1/sFgzfK5s4ev1zCtKj 2r2/2q/66rQlzf/hzfnQL+2RJHmF+KOLK9sSBauRtIoj4tdk+C6dSTfrujX/a9Gw2n1P JRc27jluNIJRm5/yH58wG4dtGWPN/Mm08uyyMJ9jVSl0bEkZd4+4BEq4zd97kqb+G5XT zZtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DtDDWveW; 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 b64sor1841426vsb.118.2018.10.31.07.05.00 for (Google Transport Security); Wed, 31 Oct 2018 07:05:00 -0700 (PDT) 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=DtDDWveW; 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=DtDDWveWgpuBfa6qJmT18PDqLti6FdQuxLDwm1idV7usJS+yUPTpgBmPGDqWLfrBhF 0YmoJXIkcYwPhr9MnmqkFeCo9YjaFCUTDeOXr1LlXSUgB3ruaytzrhYxAR9Z4NH5Smi2 iL8mtQ/Da6M/AgEWcoAmuH6GdYT2PHu3kMAzE= 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=eSgdlp/urLMC2yaFBY5DM21+LXeaH4B98xPSx8zgB/v4yTZTximH5wiO2L7Ywnd/q8 RR3W0XlwlfyHtnqG7fxsIFg/altyB5FWihRqYEvB5XJ+3NPTHbyqEhjMlY71IjirFaw7 hqJATZ+kT1x2stBLHircTrTmi+vtQWTtgLSf6Z7ZoQql/KM6y4MRqgR/XWvf72lKFmW5 rE4XbbzX7jRwM0rXouiyGtf/F1rZqgyYBhKLHjWpmd0JHxBu2ns0RXokPqq4aCaF4OqF ifyulXG82AOU3tbD0eX8i+d+5b90vop1kpf2ycO1X4p4hD6mYy2FmZUmpiUJ/2V8B3AH RKNg== X-Gm-Message-State: AGRZ1gJVXKbvyZ+5oU46N1SBTbCgUnlFENt8rMVriYKRUZrSGEQ7qzBl K23/Dsm1U7IlymiTc1jaXgrBZzbT X-Google-Smtp-Source: AJdET5ftirgmWeTPiJDmSGosSeIJ7lkQUnleDm8eOJf9SVT9wMBYEAsm8kFYb8U9TMheMqa70suLWw== X-Received: by 2002:a67:33d1:: with SMTP id z200mr1345315vsz.40.1540994699538; Wed, 31 Oct 2018 07:04:59 -0700 (PDT) Return-Path: Received: from dave-Dell-System-XPS-L502X.hsd1.nh.comcast.net ([2603:3005:3403:7100:2c71:8680:34e1:a6aa]) by smtp.googlemail.com with ESMTPSA id 6sm6795632vsy.25.2018.10.31.07.04.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 07:04:58 -0700 (PDT) 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.4 13/18] ARM: signal: copy registers using __copy_from_user() Date: Wed, 31 Oct 2018 10:04:31 -0400 Message-Id: <20181031140436.2964-14-dave.long@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031140436.2964-1-dave.long@linaro.org> References: <20181031140436.2964-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);