Re: [PATCH] new syscall: flink

H. Peter Anvin (hpa@zytor.com)
6 Apr 2003 19:33:46 -0700


Followup to: <1049663559.1602.46.camel@dhcp22.swansea.linux.org.uk>
By author: Alan Cox <alan@lxorguk.ukuu.org.uk>
In newsgroup: linux.dev.kernel
>
> It is actually rather more complicated. Suppose I give you a pipe
> pair handle. You can flink what was a private object and has no
> meaning as a name.
>
> Suppose I give you a socket what does the call man ?
>
> Suppose I give you a handle to an anonymous mapping ?
>

-EXDEV

> Suppose I give you a handle to data, how do you know what disk
> it belongs to ?

f_ino->i_sb should give you that information.

> Suppose I give you an O_RDONLY handle to a file which you then
> flink and gain write access too ?

This, I believe, is the real issue. However, we already have that
problem:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <limits.h>

int main(int argc, char *argv[])
{
int rfd, wfd;
char filebuf[PATH_MAX];

rfd = open("testfile", O_RDONLY|O_CREAT, 0666);
/* Now rfd is a read-only file descriptor */

sprintf(filebuf, "/proc/self/fd/%d", rfd);
wfd = open(filebuf, O_RDWR);
/* Now wfd is a read-write file descriptor */

write(wfd, "Tjo fidelittan hatt!\n", 21);

return 0;
}

-hpa

-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/