如何确定 ARM 处理器是否在通常的锁定“世界"中运行?还是在Secore“世界"中? [英] How to determine if ARM processor running in a usual locked-down "world" or in Secore "world"?

查看:15
本文介绍了如何确定 ARM 处理器是否在通常的锁定“世界"中运行?还是在Secore“世界"中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,virt-what 显示您是否在硬件虚拟化沙盒"中运行.

For example, virt-what shows if you are running inside hardware virtualization "sandbox".

如何检测你是否在 ARM "TrustZone" 沙箱中运行?

How to detect if you are running in ARM "TrustZone" sandbox?

推荐答案

TrustZone 可能与您的想法不同.有一个连续的模式.从受信任函数的简单 API"到在每个世界运行的双操作系统".

TrustZone maybe different than what you think. There is a continuum of modes. From 'a simple API of trusted functions' to 'dual OSs' running in each world.

如果为这个问题提供更多背景信息,那将会很有帮助.这是为了以编程方式确定还是出于逆向工程考虑?对于当前的 Linux 用户空间,答案是.

If there was more context given to the question, it would be helpful. Is this for programatically determining or for reverse engineering considerations? For the current Linux user-space, the answer is no.

  • 当前没有用户空间实用程序.
  • 基于时间的分析.
  • 基于代码的分析.
  • CPU 排除和SCR.
  • ID_PRF1 位 [7:4].
  • No current user space utility.
  • Time based analysis.
  • Code based analysis.
  • CPU exclusion and SCR.
  • ID_PRF1 bits [7:4].

virt-what 不是傻子- 发现您是否在管理程序下运行的证明方法.它是为linux 用户空间 编写的程序.大多数情况下,这些是检查的 shell 脚本/proc/cpuinfo 等.procfs 是一个伪文件系统,它在内核上下文中运行代码并向用户空间报告.主线 ARM linux 中没有检测到TrustZone.根据设计,ARM 使其难以被发现.设计意图是让正常世界中的代码不加修改地运行.

virt-what is not a fool-proof way of discovering if you are running under a hyper-visor. It is a program written for linux user-space. Mostly, these are shell scripts which examine /proc/cpuinfo, etc. procfs is a pseudo-file system which runs code in the kernel context and reports to user space. There is no such detection of TrustZone in the main line ARM linux. By design, ARM has made it difficult to detect. An design intent is to have code in the normal world run unmodified.

为了与安全世界对话,普通世界需要SMC指令.如果您的用户空间可以访问内核代码或 vmlinux 映像,您可以尝试分析 SMC 指令.但是,此代码可能存在于图像中,但从未激活.至少这说明了 Linux 内核是否支持 TrustZone.您可以编写一个内核模块来捕获 SMC 指令的任何执行,但可能有更好的解决方案.

In order to talk to the secure world, the normal world needs SMC instructions. If your user space has access to kernel code or the vmlinux image, you can try to analyze the code sections for an SMC instruction. However, this code maybe present in the image, but never active. At least this says whether the Linux kernel has some support for TrustZone. You could write a kernel module which would trap any execution of an SMC instruction, but there are probably better solutions.

如果操作系统在安全世界 中运行,一些时间分析会显示如果频率缩放 未激活,一些 CPU 周期已被窃取.我认为这不是原始问题精神的答案.这依赖于知道 安全世界 是一个成熟的操作系统,带有一个计时器(或至少是可抢占式中断).

If an OS is running in the secure world, some time analysis would show that some CPU cycles have been stolen if frequency scaling is not active. I think this is not an answer in the spirit of the original question. This relies on knowing that the secure world is a full-blown OS with a timer (or at least pre-emptible interrupts).

SCR(安全配置寄存器)在普通世界中不可用.来自 ARM Cortex-A5 MPcore 手册 (pg4-46),

The SCR (Secure configuration register) is not available in the normal world. From the ARM Cortex-A5 MPcore manual (pg4-46),

使用限制 SCR 是:
• 只能在特权模式下访问
• 只能在安全状态下访问.
尝试从安全特权以外的任何状态访问 SCR导致未定义的指令异常.

Usage constraints The SCR is:
• only accessible in privileged modes
• only accessible in Secure state.
An attempt to access the SCR from any state other than secure privileged results in an Undefined instruction exception.

ID_PRF1 位 [7:4].

在某些Cortex-A系列上,指令,

ID_PRF1 bits [7:4].

On some Cortex-A series, the instruction,

mrc p15, 0, r0, c0, c1, 1

将获得一个值,其中位 [7:4] 指示 CPU 是否支持 Security Extensions,也称为 TrustZone.非零值表示支持.许多早期的 CPU 可能不支持这个 CP15 寄存器.所以,它很像 SCR 并处理 undefined 指令.此外,它不会告诉您代码在 TrustZone 模式下是活动.

will get a value where bits [7:4] indicate whether the CPU supports Security Extensions, also known as TrustZone. A non-zero value indicates it is supported. Many early CPUs may not support this CP15 register . So, it is much like the SCR and handling the undefined instruction. Also, it doesn't tell you that code is active in the TrustZone mode.

您可以编写一个内核模块来尝试这条指令并处理未定义的异常.这将检测 normalsecure 世界.但是,您必须排除根本没有 TrustZone 的 CPU.

It is possible that you could write a kernel module which would try this instruction and handle the undefined exception. This would detect a normal versus secure world. However, you would have to exclude CPUs which don't have TrustZone at all.

如果设备不是 ARMv6 或更高版本,那么 TrustZone 是不可能的.大量 Cortex-A 设备在 CPU 中具有 TrustZone,但它不处于活动状态.

If the device is not an ARMv6 or better, then TrustZone is impossible. A great deal of Cortex-A devices have TrustZone in the CPU, but it is not active.

结合 SMC 测试和 CPU id 仍然不够.一些引导加载程序安全世界中运行,然后过渡到正常世界.所以 secure 只在启动时有效.

The combined SMC test and a CPU id, is still not sufficient. Some boot loaders run in the secure world and then transition to the normal world. So secure is only active during boot.

理论上是可以知道的,尤其是对系统有更多了解的情况下.可能有很多迹象,例如来自 GIC 的虚假中断等.但是,我认为截至 2014 年 1 月不存在任何 用户空间 linux 工具.这是病毒/rootkit 编写者和恶意软件检测软件之间的典型升级战争.TZ Rootkits

Theoretically, it is possible to know, especially with more knowledge of the system. There maybe many signs, such as spurious interrupts from the GIC, etc. However, I don't believe that any user space linux tool exists as of Jan 2014. This is a typical war of escalation between virus/rootkit writers and malware detection software.TZ Rootkits

这篇关于如何确定 ARM 处理器是否在通常的锁定“世界"中运行?还是在Secore“世界"中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆