From patchwork Thu Mar 1 12:53:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10251453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AACF260211 for ; Thu, 1 Mar 2018 13:42:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EF912465D for ; Thu, 1 Mar 2018 13:42:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D7CC2656B; Thu, 1 Mar 2018 13:42:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B6966285BA for ; Thu, 1 Mar 2018 13:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2ixrkpNtyV11q/6FgJxkXS6b4L2A1PYDTIitMpH75TQ=; b=Q5IprkPPgAgfFPhXj3lHFaOOBh XGmLcmXlFIWQ2cbTkQU3QCbifrj1DpQzYFFTlQVz1AeoevYdvlePi7oAGkPB+RWtc+rg64LLV1hRR yslgcdCHBLqB4fNY87MmLWNvi1q9udCAOgXy1Md2RWrnP0DnSrPUDb8bZv0Pm4NDkouZ4jtwjr5AZ 9tNEqRGGqIuoBsCqT5jpXMfLygCFKRyFdD+GFY3DJIcY9hQgCwwOg6Qk70CNzV6OWeUHUhC1jWoc7 cUjLRBy1b/KbnfEcKzShCNLJVStQ+Yc5m3cMR3A9WLMuSGaRKggwP7cQ1zXgoOBS7k1seqo9Mg8G5 wKPivn1w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erOS6-0003wn-5l; Thu, 01 Mar 2018 13:40:54 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erOHS-0001sV-Mv for linux-arm-kernel@bombadil.infradead.org; Thu, 01 Mar 2018 13:29:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=taE8mK2Ip25XXu3tH/TfrJ9TiKkrcCk7pgR93VQ9+cc=; b=2e2m6B0gBxyv7LPidQjHJtHbl WheBOnkKcwZT4OoKliT9YUSjHXL2KcvXssDkE11Bk/loqNjozymaKIMTwlK+2wZwtr09BEkctNdoo G/NnKOtWlJAOJmrkvL+MhlOpwYr9JmyUXWdkOS8cAJFhNwh3PT0/MRupCW0tSBBPVWM9FWvnARYFd nyUn0qmUuOibKA9WZYRvl3NEBZqCf21GYS1JmoF6ls9Mt8yB89KU8jLoiSHgPzKXgG4XEfj4h+7dO bTzwn7nmLHofCIq6sQ4BJZuhNunJPJl/+r59u+i+Mld6HQff3Z8A9vNCUpibe1I9R8pHzUSFaLgFU Uv4W9BMLg==; Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNla-0002DJ-Uh for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 12:57:00 +0000 Received: by mail-pf0-x242.google.com with SMTP id y186so2407585pfb.2 for ; Thu, 01 Mar 2018 04:56:48 -0800 (PST) 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=taE8mK2Ip25XXu3tH/TfrJ9TiKkrcCk7pgR93VQ9+cc=; b=kIYle+vWacd0WWpBliXR7l16/dddPTbZmm1Rx4E2dG+3u/1jdUn/IZLWWUyyfxr2hD El+MuyFgxNPXf9XL3tvpmw9pZfB8wEs/RFZfiW5fCoYQvuuwfbryin7ygf9dAdPebEQ9 9QiUKfqJO8e4TUcz4GfrVMSI1MaJ+kfg5X4ZM= 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=taE8mK2Ip25XXu3tH/TfrJ9TiKkrcCk7pgR93VQ9+cc=; b=OjnEy1mKj4ZER5E/AgGd0tU2gqVrnPULsGpv4EMePd0fRbG0dvaTLBmvqo0391hxfP jIuj919lb1wx+WIn48ZbqK1luj+QYnuNkpcwYbPjgppBMr0rltUGq2Gmvo2p6ctLjjb1 sa09etfG8KDFeDk3jTnd+3MkzMXs/mryXNHzV77e6+z4IdPb+AZf+bIev5BOcSRt7Xvz 3ml5LI3ZCadbL48FH/7RV5GqDQwZOA2kxOCAntnVNKNY1faZpcR7RE3lVKXP+yeIfY9L FJNeVLeV59PV+3il8VQ/DUYwt/6lbhOGZIPPajZXebFgm3SzE8K/eZSIR8T+gfH1VjGS 8xNg== X-Gm-Message-State: APf1xPDBviVxAlZ9785UYBCtueFJuVmr5RjHBQj1MOZlcanuxYwkTRcq nitQyyO1CIjf7LzRz3rJUOd8BQ== X-Google-Smtp-Source: AG47ELuv/FAMQWZcYlhzO6Tl8vm2lDOXrqruvSvHD/K8ItNBJDPZ+WHb46Z1AT35qz85SQeACgfeZg== X-Received: by 10.99.178.6 with SMTP id x6mr1526018pge.98.1519909006247; Thu, 01 Mar 2018 04:56:46 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.56.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:56:45 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/45] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Thu, 1 Mar 2018 20:53:49 +0800 Message-Id: <1519908862-11425-13-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_075659_675863_033D5A6D X-CRM114-Status: GOOD ( 14.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Shi MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Will Deacon commit 6314d90e6493 upstream. In a similar manner to array_index_mask_nospec, this patch introduces an assembly macro (mask_nospec64) which can be used to bound a value under speculation. This macro is then used to ensure that the indirect branch through the syscall table is bounded under speculation, with out-of-range addresses speculating as calls to sys_io_setup (0). Reviewed-by: Mark Rutland Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Alex Shi --- arch/arm64/include/asm/assembler.h | 11 +++++++++++ arch/arm64/kernel/entry.S | 2 ++ 2 files changed, 13 insertions(+) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index ab3a179..a109d30 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -94,6 +94,17 @@ .endm /* + * Sanitise a 64-bit bounded index wrt speculation, returning zero if out + * of bounds. + */ + .macro mask_nospec64, idx, limit, tmp + sub \tmp, \idx, \limit + bic \tmp, \tmp, \idx + and \idx, \idx, \tmp, asr #63 + csdb + .endm + +/* * NOP sequence */ .macro nops, num diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 48c41ff..0a27e12 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -233,6 +233,7 @@ alternative_else_nop_endif * x7 is reserved for the system call number in 32-bit mode. */ wsc_nr .req w25 // number of system calls +xsc_nr .req x25 // number of system calls (zero-extended) wscno .req w26 // syscall number xscno .req x26 // syscall number (zero-extended) stbl .req x27 // syscall table pointer @@ -754,6 +755,7 @@ el0_svc_naked: // compat entry point b.ne __sys_trace cmp wscno, wsc_nr // check upper syscall limit b.hs ni_sys + mask_nospec64 xscno, xsc_nr, x19 // enforce bounds for syscall number ldr x16, [stbl, xscno, lsl #3] // address in the syscall table blr x16 // call sys_* routine b ret_fast_syscall