From patchwork Mon Oct 15 15:32:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Long X-Patchwork-Id: 148869 Delivered-To: patches@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp3934061lji; Mon, 15 Oct 2018 08:32:41 -0700 (PDT) X-Received: by 2002:ad4:4391:: with SMTP id s17mr17594347qvr.101.1539617561748; Mon, 15 Oct 2018 08:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539617561; cv=none; d=google.com; s=arc-20160816; b=KH3wPUoViXCkEMQG1+qWHmCptohl/mFJJgNadF2Igd4rvLhHN+3DTn+4h6ASOfrUYJ jYA43PW0Z4HkZeZ178YP5J1noP5Zu8GStJN3R4rvntbRxmrGhCrlgSkoOInOPYkr/oA1 hq1MLftB0M7cpQc0PSr3HBAtEAawJCS5KrxbsPYfOxp9UyMkHdWPx/HQn/pKK6NuqXTI Xc3mfDsRyam5Mgo376pxV/xs3SRyyyVE3IjxwqqJhYZBocsQpJmb3Oe54AdxRCY+eS+G dRmGKuhflv7fPD2shE0AF/HLKFyfTChjphlv9O9dA6EWWXX/AeRduIgTpdV/qqozVC78 HCrQ== 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=H7Y7LEmxjOP5HU3UFuuzTdNEsm0Ewkd8zNhrxh1KSL4=; b=uPAZ/hkry1pwGdK9tNwrDkunygluDjL2TJnbAxW8bPtbQjQWaWbX+Y3Hkxik1AIWyL j5fHHe9TZKczNZKXxy0UuiNzY7sTe8FEMxlXtuth1GWLf7ZJqNp24RXi8rTv0p+NH0Hw gYCAtmpDkV8KZemcUXvrDZOhbrxO75AyBOgG1sbQ/z9zyMv7liBna4ZvyfLDKjI19tS2 ETl2o3CakawFRHyXhx6dwcUT4jgru3bHk4NTgOVoZm92+lr2yUS6fmh9GdZlCZTPsADk XKv19FHhKeayaTRAI3+qqWpikNbrl5s/aWv8Lsph/4/nQ+SiuZczQDhpwNigO0qj8Fu3 +CHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YGzBw2eq; 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 d5-v6sor5732815qkg.19.2018.10.15.08.32.41 for (Google Transport Security); Mon, 15 Oct 2018 08:32: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=YGzBw2eq; 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=H7Y7LEmxjOP5HU3UFuuzTdNEsm0Ewkd8zNhrxh1KSL4=; b=YGzBw2eqf59EdP/hi9FuzcLQRamJ4LohrHE1YWiuMx0hNwRtkZmppQyxIsvLrk9UGt 7jCGpr+9oy61l1rnxEIH9xAt0mEGrM1Co2JoVBbGIwNOT3DHZr+VYCYa6/x7rgHQJDLM QwIhvOBQ1VQZRgDbklYh2s/Lhr5dBnP3DRPgU= 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=H7Y7LEmxjOP5HU3UFuuzTdNEsm0Ewkd8zNhrxh1KSL4=; b=IerMF+0HTPMsjBHJam5Q7dGDYzhcTRpMCFb2JK+4xUEKuxPSV77QUrIOze/MIyy5fG g5rUVzyTQsr+Se+G4B/jdE8rJ4eOV9cDlCF7fvkQDEDWBcQ2txpBbTDW7QydwHNSZf7D EdIWR5QnDubCbU3L4HydsYppX0Vc1rybnf/PwfKveZ8HYpYLfrZkqdMcMRa68sjw0w0F wzhQWf7bnpygadG+3FdXxzQvbUhiIXFp2ZDTyCg6O6sfKkxboTfP4aO5Wb+0LIHUIjE1 Z5KMuRZwDKk4G058eD/EdZ8jjhu8gKbA8OiUCIqgyZLswuj2k+GlaKMCgt46qvcCbkps jcaw== X-Gm-Message-State: ABuFfogugrM4NmrcDarZesa4uJyDt381hMeaQZNb1NtYkWQwUiGFXg2W Q27BVD6vhCE5FQknkIRhGd5mm9ng X-Google-Smtp-Source: ACcGV62G51eQB9J4ws0zDbXZ2PBPY/KTWK2kF+qplb5DDJrR3lm7CHWACnF9DR3DxxJwh0iW6na+3w== X-Received: by 2002:a37:a0c2:: with SMTP id j185-v6mr16168013qke.74.1539617561358; Mon, 15 Oct 2018 08:32:41 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([72.71.243.63]) by smtp.googlemail.com with ESMTPSA id g82-v6sm10087768qkh.24.2018.10.15.08.32.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Oct 2018 08:32:40 -0700 (PDT) From: David Long To: , Russell King - ARM Linux , Florian Fainelli , Tony Lindgren , Marc Zyngier , Mark Rutland Cc: Greg KH , Mark Brown Subject: [PATCH 4.14 19/24] ARM: signal: copy registers using __copy_from_user() Date: Mon, 15 Oct 2018 11:32:13 -0400 Message-Id: <1539617538-22328-20-git-send-email-dave.long@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1539617538-22328-1-git-send-email-dave.long@linaro.org> References: <1539617538-22328-1-git-send-email-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.5.0 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index b67ae12..80da0cd 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -184,6 +184,7 @@ struct rt_sigframe { static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf) { + struct sigcontext context; char __user *aux; sigset_t set; int err; @@ -192,23 +193,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);