Skip to contentSkip to conversation

Weird __put_user_asm behavior

DISCUSSION [email protected] 1 participant 1 message Dec 26, 2001

lore
Share & tools
lore
#0 lore raw

Frank Cornelis <[email protected]> on 12/26/2001 04:12:55 PM

To: vda <[email protected]>
cc: [email protected] (bcc: Amol Lad/HSS)

Subject: Re: Weird __put_user_asm behavior

Hi,

Quoted 10 lines
Quoted 9 lines

So here it goes: when I patch the macro in include/asm-i386/uaccess.h named __put_user_asm using the patch below I cannot 'strace ls' anymore. The ld.so runtime linker just stops when preparing the program displaying a nice message; the same message as '/lib/ld-linux.so.2' generates when ran without any parameters.
The kernel messages of __put_user_asm go to: 0xbffffb44; then the program stops on the ld.so message.
But, 'strace'-ing of a static compiled program does the job as expected. What am I doing wrong?

Quoted 9 lines

include/asm-i386/uaccess.h Mon Dec 24 12:43:22 2001 line 199

Quoted 9 lines
include/asm-i386/uaccess.h Mon Dec 24 12:43:22 2001 renamed from include/asm-i386/uaccess.h Sat Dec 22 09:35:17 2001 +3 -0
@@ -194,6 +194,10 @@
  * aliasing issues.
  */
 #define __put_user_asm(x, addr, err, itype, rtype, ltype)    \
+do {                                     \
+     if (current->ptrace & PT_PTRACED) {                \
+          printk(KERN_DEBUG "__put_user_asm: %#x\n", (unsigned

long)(addr)); \

Quoted 6 lines

include/asm-i386/uaccess.h Mon Dec 24 12:43:22 2001 line 201

Quoted 2 lines
include/asm-i386/uaccess.h Mon Dec 24 12:43:22 2001 renamed from include/asm-i386/uaccess.h Sat Dec 22 09:35:17 2001 +1 -0
+     }                                   \
      __asm__ __volatile__(                         \

This must be clobbering some registers and some users of __put_user_asm might not expect that... did you try saving/restoring all regs around this 'if'?

I tried to save/restore the eax register before/after the printk function call because this register is the only register on an i386 that a function may alter without preserving its previous contents (even when the function returns void).

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

This concept is wrong. Function is free to use/modify any register it

likes. Its not only eax.
Don't expect the value of a register (ebx/ecx etc) to remain same across AFTER a function call.

What is weird is that an __asm__ __volatile__("nop") within the if-statement works so it's not the if-statement itself that is causing the problem, also works is a "push %eax\n\tpop %eax" so again it's not the stack that is causing the problem.
But, when I try to access the (addr) parameter then execve shows the ld.so message again. This is very odd because all it does is (in most cases because GCC optimizes a lot) pushing a general register containing (addr) onto the stack then call the function (I also tried a void func) and after the call restore esp.
So, any more advice on this?

Thanks in advance,
Frank.

PS: Yes, I'm a thesis student and I really need this :).

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/