From patchwork Wed Oct 31 13:57:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 149813 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6826731ljp; Wed, 31 Oct 2018 06:57:41 -0700 (PDT) X-Received: by 2002:a67:d119:: with SMTP id u25mr941056vsi.63.1540994261210; Wed, 31 Oct 2018 06:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540994261; cv=none; d=google.com; s=arc-20160816; b=ZOVr5nbemnEVv2eG3tuNhv2xaORdFCN+m/dKmnHioxRopU7CiK6BHs1oLec0rnalfH lSOgFf3UgJ+wf6t4Hy19FbTK8GbmMyIC4pj7Gt9gYyCtNV+bRFyTvQRX44lzBu2YKM8Y zPN9C/TE/Ijcn4lvTin2zc+rSX9HDxrc+x48V+HNtVtT0ucYU2wYo0arl4761wdMtvQR w+pFtlGgw4exT+U9tgWGrXNHjROTMmcB2Zq4dXG8LqIhJ1CdsIq4PJTnrNSNVCvSAxE4 XU1KISNPDT8uMa9gQ1LdMv64vk84y7Z9dFl14WpyGSDaWnsDhyw+sN6GSbOORQCKSKfi aADQ== 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=RwMgh5xJgsGKEV7GAiANthWqlvxR6etgSXvLTuI4xfBxhZRdMw1k7Csekhp7BfU+0b Jb2qrLwe9IasUW8kLz1a8URc0SMMJpWYc7qRYK1mFyOaBH+XKmu4KeakwibXR0rs7IYy BgclNH1pVbR1fW39IxmLMwF2Q8BELEetz+2ST62P/7QMurLwmZ22L9oJNRyYG0a9MqF5 FFWquEEaSZJ0+dsmQge0b0haVS8PykIiFl/jQIdp6D0N4v7R4WvjPLDuN89/DS9stX1u 52PhfszMqjZVBGyA2nw9nDoRnBhZIYI9ob2QJXmCxMsryehnqtQtSGJqthGGwA9eWjEh Kl2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EDyxLGgX; 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 m132sor5580404vkh.36.2018.10.31.06.57.41 for (Google Transport Security); Wed, 31 Oct 2018 06:57:41 -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=EDyxLGgX; 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=EDyxLGgXOX3Rsxu6bq1GlWuXIbbqjUVmKvbqXCJEptfvKe5YypneHHZqMOIL3QzIAb 81MRrq53AbOHj50dLxhF+QT6M28qinIjBE0mGhZQFylw+zimMfmO7KlS8ktEXQoJ7tqn jttaR2MQL/rFsfAAmSdADq14SOHIR1k2G21SE= 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=EZ06TaYPFFHgZ2h7cuzhYAJSIOUU8/oZIs55RUKCGhK/rN/JUjImpTNnVvkig/i1aE 31oBO3QEoDPgs81LeAjjX+VCKyaddxLC0Wfit/BacHW7ioLNT8OxPzBJOdzqQMJElKrn JoAnShhDgsuiftzDRY+aVQv42oXTKIe3uMXAiv9SfcwUnIcNaP/Ip5aTLynOkaxePepq xQnYzBVdzrJmlUw8IDAjKPOqz6CqjVr1jOBEOZ4Oe8ykeac5jGWwJ9D5+0HCWvluWO/k CkOa3z25rcMlMJBN6KVJRSziWymOrnvry9xvy1Ef8RjAWaqOuO4uMYPl73UbBtHr1WLI xDvg== X-Gm-Message-State: AGRZ1gJ8LlemGbibJCtInycf31mO6WGHbglbeEmvv7cJi9u+VTbB7YZ8 6hIXy9xmec5tVOoGyef8Czlcv4QA6zfMYQ== X-Google-Smtp-Source: AJdET5eOsI5FrMLg6Qo1T6BoEACQn7qFUEGegMj8XGMsjt4MeK3s/Sz9U39/uGlrV0ozsEPbz0Y5gQ== X-Received: by 2002:a1f:c20d:: with SMTP id s13mr1352235vkf.9.1540994260622; Wed, 31 Oct 2018 06:57:40 -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 s85-v6sm2275624vse.29.2018.10.31.06.57.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 06:57:40 -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.9 19/24] ARM: signal: copy registers using __copy_from_user() Date: Wed, 31 Oct 2018 09:57:08 -0400 Message-Id: <20181031135713.2873-20-dave.long@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031135713.2873-1-dave.long@linaro.org> References: <20181031135713.2873-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);