Does sendfile() copy extended attributes?
I want to use sendfile() to completely copy a file so that the copy is an EXACT, INDISTINGUISHABLE duplicate of the original.
Hence, I need to know if sendfile() copies the extended attributes in addition to the file itself.
While I have your attention, does sendfile() also copy the inode attributes (i.e. secure delete, compressed, etc.)?
TIA.
Joseph D. Wagner
Quoted 8 lines · Joseph D. Wagner
I want to use
sendfile()to completely copy a file so that the copy is an EXACT, INDISTINGUISHABLE duplicate of the original.Hence, I need to know if
sendfile()copies the extended attributes in addition to the file itself.While I have your attention, does
sendfile()also copy the inode attributes (i.e. secure delete, compressed, etc.)?
sendfile acting as a sys_copy() is a 2.4 unsupported behavior. It doesn't work on 2.6.
With that proviso, even in 2.4 it just operates on the page data of an inode, it has no concept of any of the meta data.
Quoted 11 lines · Shaya Potter
Quoted 5 lines · Joseph D. Wagner
I want to use
sendfile()to completely copy a file so that the copy is an EXACT, INDISTINGUISHABLE duplicate of the original.Hence, I need to know if
sendfile()copies the extended attributes in addition to the file itself.While I have your attention, does
sendfile()also copy the inode attributes (i.e. secure delete, compressed, etc.)?sendfile acting as a
sys_copy()is a 2.4 unsupported behavior. It doesn't work on 2.6.
Have you tested this assertion lately? :)
AFAIK file-file sendfile(2) was fixed in 2.6.
Jeff
Quoted 13 lines · Jeff Garzik
Quoted 12 lines · Shaya Potter
Quoted 8 lines · Joseph D. Wagner
I want to use
sendfile()to completely copy a file so that the copy is an EXACT, INDISTINGUISHABLE duplicate of the original.Hence, I need to know if
sendfile()copies the extended attributes in addition to the file itself.While I have your attention, does
sendfile()also copy the inode attributes (i.e. secure delete, compressed, etc.)?
Quoted 7 lines
Quoted 2 lines
sendfile acting as a
sys_copy()is a 2.4 unsupported behavior. It doesn't work on 2.6.Have you tested this assertion lately? :)
AFAIK file-file sendfile(2) was fixed in 2.6.
didn't work on test6, haven't tried it since.
Linux zaphod 2.6.0-test6 #1 Sat Oct 4 22:35:19 EDT 2003 i686 GNU/Linux
spotter@zaphod:~$ touch a spotter@zaphod:~$ touch b spotter@zaphod:~$ ./a.out a b error from sendfile: Invalid argument
Quoted 23 lines · Shaya Potter
Quoted 12 lines · Jeff Garzik
Quoted 10 lines · Shaya Potter
Quoted 5 lines · Joseph D. Wagner
I want to use
sendfile()to completely copy a file so that the copy is an EXACT, INDISTINGUISHABLE duplicate of the original.Hence, I need to know if
sendfile()copies the extended attributes in addition to the file itself.While I have your attention, does
sendfile()also copy the inode attributes (i.e. secure delete, compressed, etc.)?Quoted 7 lines
Quoted 2 lines
sendfile acting as a
sys_copy()is a 2.4 unsupported behavior. It doesn't work on 2.6.Have you tested this assertion lately? :)
AFAIK file-file sendfile(2) was fixed in 2.6.
Quoted 7 lines
didn't work on test6, haven't tried it since.
Linux zaphod 2.6.0-test6 #1 Sat Oct 4 22:35:19 EDT 2003 i686 GNU/Linux
spotter@zaphod:~$ touch a spotter@zaphod:~$ touch b spotter@zaphod:~$ ./a.out a b error from sendfile: Invalid argument
try it on a non-zero file size, there are special requirements IIRC...
Quoted 29 lines · Jeff Garzik
Quoted 28 lines · Shaya Potter
Quoted 15 lines · Jeff Garzik
Quoted 13 lines · Shaya Potter
Quoted 8 lines · Joseph D. Wagner
I want to use
sendfile()to completely copy a file so that the copy is an EXACT, INDISTINGUISHABLE duplicate of the original.Hence, I need to know if
sendfile()copies the extended attributes in addition to the file itself.While I have your attention, does
sendfile()also copy the inode attributes (i.e. secure delete, compressed, etc.)?Quoted 7 lines
Quoted 2 lines
sendfile acting as a
sys_copy()is a 2.4 unsupported behavior. It doesn't work on 2.6.Have you tested this assertion lately? :)
AFAIK file-file sendfile(2) was fixed in 2.6.
didn't work on test6, haven't tried it since.
Quoted 8 lines
Quoted 5 lines
Linux zaphod 2.6.0-test6 #1 Sat Oct 4 22:35:19 EDT 2003 i686 GNU/Linux
spotter@zaphod:~$ touch a spotter@zaphod:~$ touch b spotter@zaphod:~$ ./a.out a b error from sendfile: Invalid argumenttry it on a non-zero file size, there are special requirements IIRC...
no difference
spotter@zaphod:~$ dd if=/dev/zero of=a count=1 1+0 records in 1+0 records out 512 bytes transferred in 0.001311 seconds (390543 bytes/sec) spotter@zaphod:~$ ls -l a -rw-r--r-- 1 spotter spotter 512 Dec 15 00:58 a spotter@zaphod:~$ ./a.out a b error from sendfile: Invalid argument spotter@zaphod:~$ dd if=/dev/zero of=b count=1 1+0 records in 1+0 records out 512 bytes transferred in 0.000256 seconds (1999963 bytes/sec) spotter@zaphod:~$ ./a.out a b error from sendfile: Invalid argument
Quoted 3 lines
I want to use
sendfile()to completely copy a file so that the copy is anEXACT, INDISTINGUISHABLE duplicate of the original.
Just so you know, that will never be possible using the file subsystem. You'd have to go in under that and write your own disk blocks.
Two ways one could distinguish the copy from the original that you can't do anything about via filesystem interfaces, by design: inode number, ctime.
Bryan Henderson IBM Almaden Research Center
San Jose CA Filesystems
Quoted 3 lines
Two ways one could distinguish the copy from the original that you can't do anything about via filesystem interfaces, by design: inode number, ctime.
For my purposes, that's close enough. I just wanted to make sure that everything else -- like owner, group, permissions, extended attributes, etc. -- is the same.
Joseph D. Wagner
Quoted 3 lines · Joseph D. Wagner
For my purposes, that's close enough. I just wanted to make sure that everything else -- like owner, group, permissions, extended attributes, etc. -- is the same.
There's no way to do it without copying all the properties you want copied explicitly, or calling a program which does that.
-- Jamie
Quoted 7 lines
Quoted 3 lines · Joseph D. Wagner
For my purposes, that's close enough. I just wanted to make sure that everything else -- like owner, group, permissions, extended attributes, etc. -- is the same.
There's no way to do it without copying all the properties you want copied explicitly, or calling a program which does that.
Or writing a program which does that, which is exactly what I'm doing. I'm just trying to make sure all my bases are covered.
Joseph D. Wagner
Quoted 9 lines · Joseph D. Wagner
Quoted 6 lines
Quoted 3 lines
For my purposes, that's close enough. I just wanted to make sure that everything else -- like owner, group, permissions, extended attributes, etc. -- is the same.
There's no way to do it without copying all the properties you want copied explicitly, or calling a program which does that.
Or writing a program which does that, which is exactly what I'm doing. I'm just trying to make sure all my bases are covered.
just out of curiosity:
why not using rsync(1) or cp -a ??
greetings max
Quoted 2 lines
just out of curiosity:
why not using rsync(1) or cp -a ??
Because that violates one of the Immutable Laws of Security -- "If you're running someone else's program, it's not your program anymore."
If my program executes another program like cp/rsync in your example, it would be vulnerable to a privilege elevation when run as root. A hacker could replace cp/rsync, change the PATH, or a dozen other tricks to get it to execute his version of cp/rsync.
Now if there's a function call that will copy a file -- other than the sendfile function which is what this thread has been all about -- I'm all ears. However, I am not going to execute another program.
Joseph D. Wagner
Quoted 2 lines · Joseph D. Wagner
Because that violates one of the Immutable Laws of Security -- "If you're running someone else's program, it's not your program anymore."
That is equally the case if you're running someone else's function.
Quoted 4 lines
If my program executes another program like cp/rsync in your example, it would be vulnerable to a privilege elevation when run as root. A hacker could replace cp/rsync, change the PATH, or a dozen other tricks to get it to execute his version of cp/rsync.
A hacker could also change libc.so and thereby change the copy function.
Quoted 3 lines
Now if there's a function call that will copy a file -- other than the sendfile function which is what this thread has been all about -- I'm all ears. However, I am not going to execute another program.
You are imagining a black box function which is specified to copy a file and its attributes. How can you know that function does not work by calling an external program?
-- Jamie
Quoted 4 lines
Quoted 2 lines
Because that violates one of the Immutable Laws of Security -- "If you're running someone else's program, it's not your program anymore."
That is equally the case if you're running someone else's function.
Sendfile() is a KERNEL function. If a hacker has compromised the kernel, what's the point of exploiting a PRIVILEGE ELEVATION vulnerability in a program? You don't get any higher privileges than the kernel itself.
Quoted 1 line
A hacker could also change libc.so and thereby change the copy function.
Not without ALREADY compromising the root account. Remember, the vulnerability I'm addressing is PRIVILEGE ELEVATION. You can't elevate privileges any higher than root.
Quoted 3 lines
You are imagining a black box function which is specified to copy a file and its attributes. How can you know that function does not work by calling an external program?
I didn't say it doesn't work. I just said that executing an external program is too much of a security risk.
Joseph D. Wagner
Quoted 6 lines · Joseph D. Wagner
Quoted 2 lines
Quoted 2 lines
Because that violates one of the Immutable Laws of Security -- "If you're running someone else's program, it's not your program anymore."
Not without ALREADY compromising the root account. Remember, the vulnerability I'm addressing is PRIVILEGE ELEVATION. You can't elevate privileges any higher than root.
Changing /bin/cp also requires a root compromise.
Quoted 6 lines
Quoted 3 lines
You are imagining a black box function which is specified to copy a file and its attributes. How can you know that function does not work by calling an external program?
I didn't say it doesn't work. I just said that executing an external program is too much of a security risk.
I think you read what I wrote the wrong way. Let me rephrase it:
How can you know that function does not call an external program to perform its action?
There actually are a few functions in the C library which work by calling external programs - grantpt is one I think - and it's not mentioned in the manual page (because it's an implementation detail).
Actually I agree with you that calling external programs is a big risk. It should be done carefully in security conscious code. However you are deluded to imagine that calling functions in the C library is automatically safe from the those risks. That must be done carefully as well.
-- Jamie
Quoted 3 lines
I think you read what I wrote the wrong way. Let me rephrase it:
How can you know that function does not call an external program to perform its action?
Again, sendfile() is a KERNEL function.
Quoted 9 lines
There actually are a few functions in the C library which work by calling external programs - grantpt is one I think - and it's not mentioned in the manual page (because it's an implementation detail).
Actually I agree with you that calling external programs is a big risk. It should be done carefully in security conscious code. However you are deluded to imagine that calling functions in the C library is automatically safe from the those risks. That must be done carefully as well.
Thanks for the heads up. But a library function is at least SAFER -- not totally SAFE but SAFER than an external program -- right?
I view security as a process, not an end result. Minimizing the risk, not eliminating the risk altogether, is my goal; hence, the question about a library function call being safer than an external program.
Joseph D. Wagner
Quoted 5 lines · Joseph D. Wagner
Quoted 3 lines
I think you read what I wrote the wrong way. Let me rephrase it:
How can you know that function does not call an external program to perform its action?Again,
sendfile()is a KERNEL function.
unless you use the syscall macros to do the syscall interrupt yourself, you are calling the libc wrapper for the system call, not the system call itself.
Quoted 10 lines · Shaya Potter
Quoted 5 lines · Joseph D. Wagner
Quoted 3 lines
I think you read what I wrote the wrong way. Let me rephrase it:
How can you know that function does not call an external program to perform its action?Again,
sendfile()is a KERNEL function.unless you use the syscall macros to do the syscall interrupt yourself, you are calling the libc wrapper for the system call, not the system call itself.
Right.
And even if you did use the syscall macros, if an attacker has root it's just as easy for them to intercept the system call as it is to modify libc or /bin/cp.
That _are_ very good reasons to be wary of calling external programs, but "because an attacker may have changed the executable" isn't not the most important.
-- Jamie