Skip to contentSkip to conversation

Gateway instructions

hppa-linux Christopher Neufeld 3 participants 3 messages Mar 18, 1999

lore
Share & tools
lore
#0 lore raw

Hello folks,

I'm wondering if anybody's got a handle on how gateway instructions
are supposed to work. The instruction is designed to allow jumps into the kernel, with privilege promotion, without invoking the cost of an interrupt, by branching into a page and then taking on the privilege level of the page. The only safety check seems to be in the "B" bit, which would appear to prohibit the target of such a jump being, itself, another jump.
How does this work, now? Is the target of the gateway instruction
intended to be simply a vector table of other jumps, preceded by some non-branch instruction which forms the taget of the gateway? After all, if I am permitted to choose my entry point into a kernel function, I can do bad things, at the very least crash the kernel, but also probably subvert it quite easily. Access control seems to be limited to the page, not forbidding jumps into other parts of the code within the same page. And what is the "B" bit in the processor status supposed to do in all this?
Is there a misprint in the book (or a misunderstanding on my part)? If
the "B" bit produces an exception when the target of the gateway is _not_ another jump, then I can see how this can be easily constructed into a vector table into kernel functions without compromising security.

Signature · 3 lines
 Christopher Neufeld                   [email protected]
 Home page:  http://caliban.physics.utoronto.ca/neufeld/Intro.html
 "Don't edit reality for the sake of simplicity"
#1 lore raw
Quoted 3 lines · Christopher Neufeld

How does this work, now? Is the target of the gateway instruction
intended to be simply a vector table of other jumps, preceded by some non-branch instruction which forms the taget of the gateway?

I suspected so, but was confounded by the same issues you bring up....

OpenBSD has this:
#define SYSCALLGATE 0xC0000000 /* syscall gateway page
*/
but I can't find it used anywhere else in the hppa-specific code, or indeed the rest of the sys/ tree.

Here's how I think it works:
The GATE completer takes its privilege from the TLB entry for the page _containing_ the BRANCH-with-GATE (see 4-5 in the PARISC 2.0 book). So what we do is have a page (at 0xC0000000, probably) that has appropriately high privilege level in the TLB, and yet is executable by the user-space process. I think that means that the TLB access rights field is [100,11,11]:
- execute: promote to privilege 0
- minimum privilege 3
- maximum privilege 3 (or do we care?)

The page contains:
???
B,GATE to syscall 0
???
B,GATE to syscall 1
???
B,GATE to syscall 2
etc.

I don't know what goes in ???, but clearly something is required so that we don't get nailed by PSW[B]. Maybe a NOP, but probably something more useful is required (set up space and other registers?). The access ID for that page should probably be 0, to make it universally accessible.

Questions:
- how many privilege levels do we care about?
- is it sufficient to mark kernel data as [001,00,00] with an access ID of 0 so that all processes can get at it (when they've become beprivileged enough!) ? (With variants for code [100,00,00] and read-only [000,00,00], of course.)
- what should go in ``???''? Just something that sets PSW[C]?
- am I totally on crack?

Mike

Signature · 1 line
345127.74 293957.05
#2 lore raw
Quoted 7 lines

Here's how I think it works:
The GATE completer takes its privilege from the TLB entry for the page _containing_ the BRANCH-with-GATE (see 4-5 in the PARISC 2.0 book). So what we do is have a page (at 0xC0000000, probably) that has appropriately high privilege level in the TLB, and yet is executable by the user-space process. I think that means that the TLB access rights field is [100,11,11]:

Oh man its a vax 8)

Yeah that would be fairly believable. VMS actually does this sort of stuff with the vax architecture equivalent for libraries - think setuid mmap 8)