News for hackers. Stuff that matters.
Re:Reading privileged memory with a side-channel by comex on Wednesday January 03, 2018 @05:52PM (#16066178)
Not just user memory reads. AMD CPUs won’t speculate loads from userland code directly to kernel memory, ignoring privilege checks (“Meltdown”). But they are still subject to the “Spectre” attack, which can disclose kernel memory by taking advantage of certain code patterns (which normally would be harmless) in kernel code.
Re:Reading privileged memory with a side-channel by tankenmate on Wednesday January 03, 2018 @06:52PM (#16066659)
But that means the root user or someone with root effective privs or CAP_* to load programs into a kernel interpreter or kernel JIT. If you've given someone permission to do this from a user process you've probably opened up to more mundane issues. I suspect this is why AMD says the issue is near zero, if you've given away the keys to the kernel you're already in trouble.

AMD's ASID blocks the issues for VM guests (and root users on VM guests).

Re:Reading privileged memory with a side-channel by comex on Wednesday January 03, 2018 @07:02PM (#16066712)
For variant 1, a kernel JIT is definitely helpful, which is why the Project Zero PoC used it, but it's not required.

For variant 2, Project Zero used the eBPF interpreter as a gadget, a fake branch destination, without having to actually create an eBPF program or use the normal userland-facing eBPF APIs at all. And they only chose it as the least "annoying" option (see quote below).

edit: I'm not sure how ASID support would mitigate either of those variants, though there may be something I'm not thinking of. (It would help with variant 3, but that's the variant AMD wasn't vulnerable to in the first place.)

quote:

> At this point, it would normally be necessary to locate gadgets in the host kernel code that can be used to actually leak data by reading from an attacker-controlled location, shifting and masking the result appropriately and then using the result of that as offset to an attacker-controlled address for a load. But piecing gadgets together and figuring out which ones work in a speculation context seems annoying. So instead, we decided to use the eBPF interpreter, which is built into the host kernel - while there is no legitimate way to invoke it from inside a VM, the presence of the code in the host kernel's text section is sufficient to make it usable for the attack, just like with ordinary ROP gadgets.

Re:Reading privileged memory with a side-channel by caf on Wednesday January 03, 2018 @07:43PM (#16066946)
To make it a bit clearer how this works: the Variant 2 exploit poisons the branch target buffer to cause the processor's speculative execution in kernel space to jump to an entirely attacker-controlled destination when it hits a branch that matches the information the attacker has placed into the BTB. The actual retired instructions don't go this way of course - the processor detects the misprediction and goes back to execute the real code path - but the speculatively executed path still leaves evidence behind in the caches.
Re:Reading privileged memory with a side-channel by tankenmate on Wednesday January 03, 2018 @08:02PM (#16067077)
But somehow you have to get that kernel address in the first place in order to alias it in the BTB. How do you get that without root?
Re:Reading privileged memory with a side-channel by caf on Wednesday January 03, 2018 @08:45PM (#16067306)
They test how a series of branches are predicted after returning from a hypercall, which lets them basically dump out the state of the BTB. From that, and knowledge of where the branches are in the hypervisor binary (the binaries themselves aren't really a secret, only the relocated load address is) they can figure out the load address of the hypervisor.

See the section "Reading host memory from a KVM guest / Locating the host kernel". It's terribly clever.

Re:Reading privileged memory with a side-channel by tankenmate on Thursday January 04, 2018 @04:47AM (#16069080)
But if you use AMD ASID it blocks this as memory mappings for VM guests are in a completely separate address space.

What I was wondering was for local OS user mode to local OS root / kernel mode access; i.e. user to kernel privilege escalation.

Re:Reading privileged memory with a side-channel by caf on Thursday January 04, 2018 @05:58AM (#16069361)
It isn't obvious at all how a separate address space would block that method.

What would block it is flushing the branch predictor state when switching privilege levels and/or address spaces.

Re:Reading privileged memory with a side-channel by loulan on Thursday January 04, 2018 @08:28AM (#16070167)
I've tried reading it and I still find all of this very confusing. Could you ELI5?
Re:Reading privileged memory with a side-channel by aidenn0 on Wednesday January 03, 2018 @08:25PM (#16067204)
You boot up your own copy of Ubuntu LTS-whatever and read the address of it as root.

KASLR is not enabled everywhere, and where it is, there are other attacks to defeat it, which are mentioned in the paper.

Re:Reading privileged memory with a side-channel by tankenmate on Wednesday January 03, 2018 @07:21PM (#16066825)
I'm not sure I see how to use the Spectre attack on AMD without running in kernel context. What am I missing?
Re:Reading privileged memory with a side-channel by tankenmate on Wednesday January 03, 2018 @07:57PM (#16067036)
I should clarify I mean user to root privilege escalation.

I totally understand how the breaking out of the javascript sandbox attack works and the fact that IPT won't help with that. With Linux's clone(), you could clone without CLONE_VM and use CLONE_NEWUSER|SYSVMSEM and then unmap everything except the Javascript interpreter / JIT and leave a shared memory map and communicate only via the shared memory map and SYSV semaphores for synchronisation. Obviously this wouldn't be available on other platforms.

Re:Reading privileged memory with a side-channel by comex on Wednesday January 03, 2018 @09:14PM (#16067439)
By "user to root privilege escalation", I'll assume you mean leaking kernel data without root, since this attack doesn't directly allow escalating privileges at all.

For variant 1, you would need to find some legitimate kernel code, accessible by syscall, that looks at least somewhat similar to the example in the Project Zero blog post:

    if (untrusted_offset_from_caller < arr1->length) {
        unsigned char value = arr1->data[untrusted_offset_from_caller];
        unsigned long index2 = ((value&1)*0x100)+0x200;
        if (index2 < arr2->length) {
            unsigned char value2 = arr2->data[index2];
        }
    }
In practice, you may not be able to find something nice like "((value&1)*0x100)+0x200", but even if it simply used 'value' as an index, you would be able to at least narrow it down to a range. Other code patterns may work too (and potentially be more powerful?), e.g. conditional branches based on 'value'.

For variant 2, see caf's answer to you in another thread.

Re:Reading privileged memory with a side-channel by user5994461 on Thursday January 04, 2018 @02:56AM (#16068698)
>>> By "user to root privilege escalation", I'll assume you mean leaking kernel data without root, since this attack doesn't directly allow escalating privileges at all.

The attack allows to read all the memory. Isn't there a way to scan for passwords or ssh keys and turn that into a privilege escalation?

Re:Reading privileged memory with a side-channel by comex on Thursday January 04, 2018 @03:25AM (#16068775)
Sure, SSH keys would probably work on a system with SSH enabled; I just wouldn't count that as "directly". (That would include most servers but exclude most Android devices; I have no idea whether there are other escalation methods for Android.)
Re:Reading privileged memory with a side-channel by user5994461 on Thursday January 04, 2018 @11:26PM (#16076527)
Direct or indirect is meaningless at this point. The exploit is proven, they just have to determine the "best" memory locations to read to make something "useful" out of it. Then it's bundled together as an exploit kit and it's Armageddon.
Re:Reading privileged memory with a side-channel by Sean1708 on Thursday January 04, 2018 @07:54AM (#16069953)
> For variant 1, a kernel JIT is definitely helpful, which is why the Project Zero PoC used it, but it's not required.

If I'm understanding the post correctly it says that JIT's not required for Intel CPUs, but is required for AMD.

Re:Reading privileged memory with a side-channel by comex on Thursday January 04, 2018 @07:41PM (#16075510)
Their particular exploit for variant 1, which uses eBPF, only worked on AMD with the eBPF JIT, i.e. it did not work with the eBPF interpreter. But there are many other potential avenues to exploit that variant which have nothing to do with BPF. The result does suggest that it may generally be harder to trigger variant 1 on AMD processors (because they doesn't speculate as much?), but harder ≠ impossible.
Re:Reading privileged memory with a side-channel by Sean1708 on Friday January 05, 2018 @12:12PM (#16079865)
Ah ok, thanks for clarifying.
Re:Reading privileged memory with a side-channel by Pyxl101 on Wednesday January 03, 2018 @09:13PM (#16067435)
Do you need root or comparable privileges to take advantage of BPF? I did not think that was the case. My understanding was that BPF code executes within the kernel.

BPF is employed by the `bpf()` syscall for socket packet filtering, as well as by `seccomp` itself for its syscall filtering. Is this threat vector not available to untrusted processes?

Re:Reading privileged memory with a side-channel by language on Wednesday January 03, 2018 @10:08PM (#16067714)
iirc I think that the BPF JIT is disabled by default? Your kernel might be compiled with `CONFIG_BPF_JIT`, but I think the sysctl knob (`bpf_jit_enable`) is set to 0 by default. Also there's a sysctl for unprivileged BPF called `unprivileged_bpf_disabled`. On my system it seems to default to 0.

https://elixir.free-electrons.com/linux/v4.15-rc6/source/ker...