From patchwork Fri Mar 9 09:06: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: 10270105 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 5F2EB60236 for ; Fri, 9 Mar 2018 09:11:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0ADE729D9C for ; Fri, 9 Mar 2018 09:11:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3D3329D9F; Fri, 9 Mar 2018 09:11:43 +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=ham 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 7704F29D9C for ; Fri, 9 Mar 2018 09:11:43 +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=0onu9Mp0OKzcRSyjK7zYuv48R0aioJfj5Nc3rYicPBE=; b=DdVJ40YC8zQyGtHQevhaKQTYvB TzKjmSvnaDHYHs8g028X9ug4O/XpZlpnJQYV05I6Pk8e2uZ1s4dvvTGRXkxxDdncdpHa96be92e1R 6XBDUjZT2w7zhHu4lWBJtU/Emn/0G5BJobayRxfKBaBsxsBJvCVcwDwI8DMBYd1jIs8l3CgihUcj8 AkReHfgVGkHgHqxCeG21e7+/H7W8Wx2xhxYOO6ydIBsVSgB0secwVSe3Y0RyoFMyjLvLm/TTYYXm5 5a6ZsKX/32sZTJ+JFVhjfuW2/Wcjt1jyHeyTy9hQjWK+Gz+plk1L4zOn1865PGqOnlfa/rskJsq71 Bgb8wGlw==; 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 1euE3s-0006Fj-8i; Fri, 09 Mar 2018 09:11:36 +0000 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euE1G-0003Vk-Sl for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 09:09:07 +0000 Received: by mail-pf0-x244.google.com with SMTP id u5so1050673pfh.6 for ; Fri, 09 Mar 2018 01:08:44 -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=UAXdEroZcMWW66K27+4g89APIvh+ZW1PxElP6NpbyvI=; b=Pl5npazpbPrc07GOAn0B8ZZTE2lnhc5vxJhJJd48ISefjsl5YKjKe1yhzBXLm6akMT gGl0QHmSmo/yCYiwGDaUp0C5P4ukSlCUwowFzLF4ANalAuiQbFJ9OVp4eD6GMFke6kGU ZFVSdVLl8oNUqZTcsaNBxKyUhGA1o5IdgNPOA= 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=UAXdEroZcMWW66K27+4g89APIvh+ZW1PxElP6NpbyvI=; b=kc+fmssJkhbefxtxkqyZcu3gpt54sj/eyPhOHQDhmZnuhLbWi9JROWIHs2tsjpr/MZ 7CJwYC8hk9DGINPTvdukS2L1gA/edflJTZ91mxxoThdEwTBz3leeqUKZ7PjgjvCbkSOq bin2tZ35dkerfTa6rrFSPzLzx9bEHrEvLkmA7c6nNubhhM5Sf0HdWe0iogKNAmSk8332 rXW/vnj1/deVA81xshNnHGiDlnJ3abvJgMK7qWaOmmNlOagi1KMpJJfwyqezbhUdJzkR rpC7PyIWW1nSdfPArqKHBszl7CsbtSASQBz/9lqWKlaCbahLBZvu3GnZdt9J8/J0n12G KRKw== X-Gm-Message-State: APf1xPDA63LZfh0QF53IkYoM+fj80cmQtpcmsr/7hX7IESRneg6WhKzV TDWN5WQAZD97eLjudo0hnx8LMg== X-Google-Smtp-Source: AG47ELvq2aa1N+Ojl0IsX39JTkm25gyWNG/64Y+VdLeWjsnG8WNBpoXy5ws1Y+zEQ/bb4E8mQ0n9fA== X-Received: by 10.101.82.70 with SMTP id q6mr23310337pgp.67.1520586524276; Fri, 09 Mar 2018 01:08:44 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id c7sm1961752pfg.36.2018.03.09.01.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 01:08:43 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , broonie@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 06/39] arm64: entry: Ensure branch through syscall table is bounded under speculation Date: Fri, 9 Mar 2018 17:06:49 +0800 Message-Id: <20180309090722.26279-7-alex.shi@linaro.org> X-Mailer: git-send-email 2.16.2.440.gc6284da In-Reply-To: <20180309090722.26279-1-alex.shi@linaro.org> References: <20180309090722.26279-1-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_010855_940251_FAB2F317 X-CRM114-Status: GOOD ( 13.61 ) 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 | 1 + 2 files changed, 12 insertions(+) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 229b37ddf52c..81a5f416a27a 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -101,6 +101,17 @@ hint #20 .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 */ diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 274898465a3f..166cd6626ca7 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -694,6 +694,7 @@ el0_svc_naked: // compat entry point b.ne __sys_trace cmp scno, sc_nr // check upper syscall limit b.hs ni_sys + mask_nospec64 scno, sc_nr, x19 // enforce bounds for syscall number ldr x16, [stbl, scno, lsl #3] // address in the syscall table blr x16 // call sys_* routine b ret_fast_syscall