Bug 2247682 - Wrong description of 'SO_PEERCRED' in unix(7) page
Summary: Wrong description of 'SO_PEERCRED' in unix(7) page
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: man-pages
Version: 39
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Nikola Forró
QA Contact: Fedora Extras Quality Assurance
URL: https://man7.org/linux/man-pages/man7...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-11-02 18:38 UTC by Alexey Tikhonov
Modified: 2023-12-23 04:24 UTC (History)
5 users (show)

Fixed In Version: man-pages-6.05-5.fc39
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-12-23 04:24:12 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
Reproducer: server side (1.70 KB, text/plain)
2023-11-17 12:34 UTC, Alexey Tikhonov
no flags Details
Reproducer: client side (1.30 KB, text/plain)
2023-11-17 12:35 UTC, Alexey Tikhonov
no flags Details

Description Alexey Tikhonov 2023-11-02 18:38:44 UTC
`man 7 unix` states:
```
       SO_PEERCRED
              This read-only socket option returns the credentials of
              the peer process connected to this socket.  The returned
              credentials are those that were in effect at the time of
              the call to connect(2) or socketpair(2).
```

This doesn't match real behavior in following situation (just an example):
 - process starts with uid=0, gid=0
 - process creates UNIX socket, binds it, listens on it
 - process changes to uid=uid1, git=gid1 (using `setresuid()`, `setresgid()`)
 - another process connects to listening socket and requests peer's credentials using `getsockopt(... SOL_SOCKET, SO_PEERCRED ...)`




Reproducible: Always

Actual Results:  
Actual result:
SO_PEERCRED reports (0, 0)

Expected Results:  
Expectation according to the man page:
SO_PEERCRED reports (uid1, gid1), because peer process was running under (uid1, gid1) "at the time of the call to connect(2)"


Take a note, I think actual behavior makes sense, and it's a man page what needs update.

Comment 1 Florian Weimer 2023-11-17 10:54:16 UTC
Could you show us your reproducer? Does it involve SOCK_STREAM or SOCK_DGRAM sockets?

Comment 2 Alexey Tikhonov 2023-11-17 12:11:21 UTC
(In reply to Florian Weimer from comment #1)
> Does it involve SOCK_STREAM or SOCK_DGRAM sockets?

`socket(AF_UNIX, SOCK_STREAM, 0)`

Comment 3 Florian Weimer 2023-11-17 12:24:41 UTC
Complete reproducer, please.

Comment 6 Alexey Tikhonov 2023-11-17 12:39:24 UTC
(In reply to Florian Weimer from comment #3)
> Complete reproducer, please.

Sure, I was just extracting minimal example from the code - attached now.

Console output - client side:
```
$ ls -la socket 
srw-rw-rw-. 1 root root 0 Nov 17 13:30 socket

$ ./client
fd = 3
Peer's pid = 1226941, uid = 0, gid = 0

$ cat /proc/1226941/status | grep Uid
Uid:	1000	1000	1000	1000

$ cat /proc/1226941/status | grep Gid
Gid:	1000	1000	1000	1000
```

Console output - server side:
```
# ./server
Peer's pid = 1227027, uid = 1000, gid = 1000
```

Comment 7 Florian Weimer 2023-11-17 13:44:41 UTC
Could we make the reproducer public?

As far as I can tell, the relevant socket is created after the UID change, during the accept system call. So I think the wording in the manual page is correct?

Comment 8 Alexey Tikhonov 2023-11-17 14:15:03 UTC
(In reply to Florian Weimer from comment #7)
> Could we make the reproducer public?

Sure.


> As far as I can tell, the relevant socket is created after the UID change,

Right: after process with listening socket changes uid/gid to 1000.


> during the accept system call.

`connect()` on client side and `accept()` on server side.


> So I think the wording in the manual page is correct?

Why?
```
The returned credentials are those  that were in effect at the time of the call to connect(2) or socketpair(2).
```

At the time of `connect()` peer runs under (1000, 1000), but SO_PEERCRED returns (0, 0)

Comment 9 Florian Weimer 2023-11-17 14:23:27 UTC
Huh, you right. So yes, the manual page should be clarified. Thanks.

Comment 10 Lukas Javorsky 2023-11-27 09:22:02 UTC
Hi, thanks for the report,

I've been looking at the comments, but as I'm not a heavy user of the sockets, I don't want to mess up the man-page entry.

Do you have some recommendations for the change, that would describe the actual behavior, so I can change it and also propose it to upstream as we focus on upstream first?

Thank you so much for the help

Comment 11 Alexey Tikhonov 2023-11-29 08:20:00 UTC
(In reply to Lukas Javorsky from comment #10)
> Hi, thanks for the report,
> 
> I've been looking at the comments, but as I'm not a heavy user of the
> sockets, I don't want to mess up the man-page entry.
> 
> Do you have some recommendations for the change, that would describe the
> actual behavior, so I can change it and also propose it to upstream as we
> focus on upstream first?

To be honest, I'm not even completely sure what is wrong: a man page or 'SO_PEERCRED' actual behavior (but tend to think that the former).

Is it possible to open an upstream ticket?

Comment 12 Lukas Javorsky 2023-11-29 11:07:57 UTC
Yes, it's possible to create an issue, you can follow these steps: https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING#n212

If you don't want to do it, I can do it for you just let me know.

Comment 16 Fedora Update System 2023-12-21 17:18:17 UTC
FEDORA-2023-f52730a91d has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-f52730a91d

Comment 17 Fedora Update System 2023-12-22 02:52:30 UTC
FEDORA-2023-f52730a91d has been pushed to the Fedora 39 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-f52730a91d`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-f52730a91d

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 18 Fedora Update System 2023-12-23 04:24:12 UTC
FEDORA-2023-f52730a91d has been pushed to the Fedora 39 stable repository.
If problem still persists, please make note of it in this bug report.


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