userspace function pointers in the kernel
Quoted 11 lines
Next, even if we *weren't* trapping we would still be doing the wrong thing, because $$sh_func_adrs is actually supposed to give us the address of the function's code, and it isn't going to do this since the function lives in a different space.
In the case of
sigaction()I think we actually want to compare the plabel value (rather than the code address) againsrSIG_IGNandSIG_DFL. However there may be other cases where this will break.Yes this is yet another side effect of the broken PA-RISC run time architecture.
I'm deeply troubled to learn that Linux is using $$sh_func_adrs, as I will readily agree with you that it's seriously broken.
It was introduced as a way to compare function pointers reliably, but in fact accomplishes exactly the opposite. The problem is that our dynamic loader cannot guarantee that two function pointers that both refer to the same procedure will compare equal. Rather than fix the dynamic loader, we chose to modify the compilers to compare two function pointers by digging down into the function descriptor itself to see if they really refer to the same function. Unfortunately, not all data items typed as function pointers are really valid pointers, and they can't be dereferenced safely. Thus, the millicode routine uses the probe instruction to verify that the address can be dereferenced without causing a memory fault.
Of course, this isn't 100% reliable on HP-UX, either, since a probe failure doesn't mean that the address isn't mapped. It should also be a "probe,r" instead of "probe,w".
For Linux, I strongly recommend that the dynamic loader guarantee that there is a 1-1 mapping between function and function pointer. If you do this, you won't need this silly special case when comparing function pointers.
Quoted 1 line
What do the IA-64 people do about this problem?
On IA-64, the dynamic loader will maintain a 1-1 mapping.
-cary
Quoted 3 lines · Cary Coutant
Quoted 2 lines · I wrote:
Yes this is yet another side effect of the broken PA-RISC run time architecture.
Hm. As it turns out it is not the kernel that changed but rather the linker. We had previously been generating dynamic procedure descriptors for PLABEL32 relocations only in shared libraries, but switched to generating PLT entries for all functions (even in non-PIC objects, which is a bug) and then pointing the PLABEL32 relocations at these slots. Hence I'm forwarding this to Alan.
Of course we would have had the same problem if a shared library had tried to pass the address of a global function to signal(2), so I guess it's a good thing we caught it now :-)
Quoted 7 lines
I'm deeply troubled to learn that Linux is using $$sh_func_adrs, as I will readily agree with you that it's seriously broken.
For Linux, I strongly recommend that the dynamic loader guarantee that there is a 1-1 mapping between function and function pointer. If you do this, you won't need this silly special case when comparing function pointers.
I agree that this is a valid goal. Unfortunately I believe we are falling short of it at the moment and we'll have to make some fairly large changes to the toolchain. If you don't mind I've got a few questions about how this is done:
It looks like the IA-64 runtime achieves this by generating official procedure descriptors for every defined function in an object and placing them in the .opd section, then using these descriptors whenever the address of a function is taken. Presumably external functions are compared using their .IA_64.pltoff entries? I'm not clear on how that works and don't have an IA-64 handy to experiment.
I'm also confused about how this interacts with dynamic linking in another case - from what I've seen the descriptors in .opd are never relocated, so if a function ends up being bound to another dynamic object (in the case of weak symbols in shared libraries this can happen, and we've had to make some adjustments to our linker and assembler to handle this case since GNU libc relies on this behaviour in some fundamental ways), it would appear that the .opd entries become bogus and the pltoff entry (or whatever) should be used instead. How does the IA-64 runtime handle this case?
Also I've noticed that GNU libc doesn't actually use the .opd or .pltoff entries to resolve dynamic FPTR64 relocations but rather builds FPTRs dynamically when it encounters them. So the 1-1 mapping isn't really upheld at all in some cases.
But then HP/UX probably does something else entirely :-)
Signature · 2 lines
[email protected], http://www.linuxcare.com/ Linuxcare. Support for the revolution.
Quoted 9 lines · David Huggins-Daines
Quoted 4 lines · Cary Coutant
For Linux, I strongly recommend that the dynamic loader guarantee that there is a 1-1 mapping between function and function pointer. If you do this, you won't need this silly special case when comparing function pointers.
I agree that this is a valid goal. Unfortunately I believe we are falling short of it at the moment and we'll have to make some fairly large changes to the toolchain.
David, I think this is the reason we do actually need your dynamic fptr code, or at least something like it that can sort through plt entries. Currently, plabels go through the plt whenever dynamic sections are involved. However, there is a problem in that we are duplicating plt entries between the application and shared libs, and I can't think of a way the linker can avoid this given that we have to deal with weak symbols.
Alan Modra
Signature · 1 line
Linuxcare. Support for the Revolution.