Bug 9132 - fcntl GET_OWN reports 0 for sockets instead of PID
Summary: fcntl GET_OWN reports 0 for sockets instead of PID
Status: REJECTED INVALID
Alias: None
Product: Networking
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Herbert Xu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-08 09:18 UTC by François-Frédéric Ozog
Modified: 2007-10-09 00:04 UTC (History)
0 users

See Also:
Kernel Version: 2.6.22
Subsystem:
Regression: ---
Bisected commit-id:


Attachments

Description François-Frédéric Ozog 2007-10-08 09:18:01 UTC
Most recent kernel where this bug did not occur: 2.6.22
Distribution: Kubuntu
Hardware Environment: VMWare workstation 6
Software Environment: 
Problem Description: calling fcntl with F_GETOWN on a socket gives allways zero instead of the PID of the socket. The fcntl code is right but the data is zero in the struct file element. It sounds like pid is not set when the socket is attached to the fd in sock_attach_fd() of net/socket.c.

I would add something like this:

file->f_owner.pid=find_get_pid(task->pid);
file->f_owner.pid_type=PIDTYPE_PID;

in sock_attach_fd() of net/socket.c

Steps to reproduce:

s=socket(...);
pid=fcntl(s, F_GETOWN);
Comment 1 Anonymous Emailer 2007-10-08 10:12:03 UTC
Reply-To: akpm@linux-foundation.org


(please respond via emailed reply-to-all, not vie the bugzilla web interface)

On Mon,  8 Oct 2007 09:18:02 -0700 (PDT) bugme-daemon@bugzilla.kernel.org wrote:

> http://bugzilla.kernel.org/show_bug.cgi?id=9132
> 
>            Summary: fcntl GET_OWN reports 0 for sockets instead of PID
>            Product: Networking
>            Version: 2.5
>      KernelVersion: 2.6.22
>           Platform: All
>         OS/Version: Linux
>               Tree: Mainline
>             Status: NEW
>           Severity: normal
>           Priority: P1
>          Component: Other
>         AssignedTo: acme@ghostprotocols.net
>         ReportedBy: ff@ozog.com
> 
> 
> Most recent kernel where this bug did not occur: 2.6.22
> Distribution: Kubuntu
> Hardware Environment: VMWare workstation 6
> Software Environment: 
> Problem Description: calling fcntl with F_GETOWN on a socket gives allways
> zero
> instead of the PID of the socket. The fcntl code is right but the data is
> zero
> in the struct file element. It sounds like pid is not set when the socket is
> attached to the fd in sock_attach_fd() of net/socket.c.
> 
> I would add something like this:
> 
> file->f_owner.pid=find_get_pid(task->pid);
> file->f_owner.pid_type=PIDTYPE_PID;
> 
> in sock_attach_fd() of net/socket.c
> 
> Steps to reproduce:
> 
> s=socket(...);
> pid=fcntl(s, F_GETOWN);
> 

You state that the problem is present in 2.6.22 and also did not occur in
2.6.22.  I assume it has always been like this.
Comment 2 François-Frédéric Ozog 2007-10-08 11:27:21 UTC
You are correct, I have tested back to 2.6.18 and the bug is still here. So I don't know when the problem did NOT occur.

Fran
Comment 3 Herbert Xu 2007-10-08 20:10:52 UTC
If you don't set an owner then of course F_GETOWN will return zero which is the default.  It does exactly the same thing for normal file descriptors returned by open(2).
Comment 4 François-Frédéric Ozog 2007-10-09 00:04:06 UTC
Then it either means:
a) fcntl documentation should be updated to state that F_GETOWN command returns a non zero value if and only if it has been set by F_SETOWN.
b) the kernel should maintain the value when it creates the socket

I assume IPtables group phased out support for process matching rules because of the lack of support of b). From a security management (personal firewall...) stand point it would be good to keep the original pid and the "effective" pid (modified by F_SETOWN) of the creating process.

Note You need to log in before you can comment on or make changes to this bug.