Bug 115444 - <asm/unistd.h> defined dangerous syscallN macro
Summary: <asm/unistd.h> defined dangerous syscallN macro
Status: RESOLVED WONTFIX
Alias: None
Product: SUSE LINUX 10.0
Classification: openSUSE
Component: Kernel (show other bugs)
Version: Beta 4 Plus
Hardware: Other All
: P5 - None : Normal
Target Milestone: ---
Assignee: Andreas Kleen
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-06 16:23 UTC by Michael Matz
Modified: 2005-09-07 14:27 UTC (History)
0 users

See Also:
Found By: Other
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Matz 2005-09-06 16:23:06 UTC
This is turned up in bug 114933 .  The problem is, that on i386 the syscallN  
macro is defined like so:  
  long __res; \  
  __asm__ volatile ("int $0x80" \  
        : "=a" (__res) \  
        : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \  
          "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \  
  
If one of the arguments (in the _llseek syscall it's the arg4) is a pointer  
which the syscall is expected to write to (to the memory pointed to by this  
ptr), then this side-effect is not captured in the asm.  
  
If anyone uses this macro to define it's own version of the syscall  
(sometimes necessary when not using glibc) and it's inlined, then GCC  
doesn't know that this asm write to "*dest", when called like so for instance:  
  out = 1;  
  llseek (fd, bla, blubb, &out, trara)  
  use (out); 
Here nobody tells GCC that "out" actually is written to (just a pointer to it  
is passed to the asm).  Hence GCC might (and in the above bug did) 
copy-propagate "1" into the second use of "out". 
 
The easiest solution would be to add a "memory" clobber to the definition 
of this syscall macro.  As this is a syscall, it shouldn't inhibit too many 
optimizations.
Comment 1 Olaf Kirch 2005-09-07 10:10:49 UTC
Please send a patch to Andrew Morton. I propose to fix this upstream 
and close this report as WONTFIX. I think applications trying to use 
kernel headers do so at their own risk. 
Comment 2 Michael Matz 2005-09-07 13:30:13 UTC
I'm feeling unsure about the procedure of sending kernel patches, so how 
about we make a deal, I write the patch, and someone tries to get it upstream? 
Comment 3 Michael Matz 2005-09-07 13:34:06 UTC
Oh, and regarding apps using kernel headers are on their own: I completely 
agree.  But sometimes it might be necessary (in this case it was, because 
klibc didn't provide the lseek64 interface, which is an ommission in klibc, 
but world never is perfect ;-) ) and then the provided means from the kernel 
header at least shouldn't make things more difficult than necessary. 
Comment 4 Hubert Mantel 2005-09-07 14:18:52 UTC
Andi, can you care about this (sending the bug upstream)? In case there are
additional questions I would be lost anyway :/
Comment 5 Andreas Kleen 2005-09-07 14:27:10 UTC
x86-64 already has a memory clobber here. I will submit an i386 patch 
and tell the other architecture maintainers.