Bug 1733967

Summary: Peer authentication broken on ppc64le
Product: [Fedora] Fedora Reporter: Tom Hughes <tom>
Component: postgresqlAssignee: Patrik Novotný <panovotn>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: anon.amish, devrim, hhorak, jmlich83, jstanek, panovotn, pkajaba, pkubat, praiskup, tgl
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-07-31 12:18:28 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Tom Hughes 2019-07-29 11:04:49 UTC
Description of problem:

Peer authentication appears to be broken in the latest ppc64le build for rawhide - all my builds which use postgres in their %check failed during the mass rebuild with:

createdb: could not connect to database template1: FATAL:  Peer authentication failed for user "mockbuild"

Version-Release number of selected component (if applicable):

postgresql-11.4-1.fc31

How reproducible:

Reproduced in rawhide mock on ppc64le test machine.

Steps to Reproduce:
1. initdb $PWD/data -U $(id -un) --auth-local=peer --auth-host=md5
2. pg_ctl -D $PWD/data -l $PWD/data/start.log start -o '-k /tmp -p 58196' -w
3. createdb -h /tmp $(id -un) --owner $(id -un) -p 58196

Actual results:

createdb: could not connect to database template1: FATAL:  Peer authentication failed for user "mockbuild"

Expected results:

Database is created.

Additional info:

Comparing an strace of the server on ppc64le shows:

4761  recv(10, "\0\0\0D\0\3\0\0user\0mockbuild\0database\0"..., 8192, 0) = 68 
...

4761  getsockopt(10, SOL_SOCKET, SO_SNDLOWAT, [1], [12->4]) = 0 

while on x86_64 we see:

24657 recvfrom(9, "\0\0\0>\0\3\0\0user\0thh\0database\0postgr"..., 8192, 0, NULL, NULL) = 62 
...
24657 getsockopt(9, SOL_SOCKET, SO_PEERCRED, {pid=24656, uid=2067, gid=103}, [12]) = 0 

I'm not sure why ppc64le is using recv instead of recvfrom, but the big issue is that it uses the wrong socket option to get the peer credentials. I think because of this on ppc64le:

[tomh@ppc64le-test ~][PROD]$ fgrep SO_PEERCRED /usr/include/**/*.h
/usr/include/asm-generic/socket.h:#define SO_PEERCRED   17
/usr/include/asm/socket.h:#define SO_PEERCRED   21
[tomh@ppc64le-test ~][PROD]$ fgrep SO_SNDLOWAT /usr/include/**/*.h
/usr/include/asm-generic/socket.h:#define SO_SNDLOWAT   19
/usr/include/asm/socket.h:#define SO_SNDLOWAT   17

versus x86_64:

rawhide [~] % fgrep SO_PEERCRED /usr/include/**/*.h
/usr/include/asm-generic/socket.h:#define SO_PEERCRED    17
rawhide [~] % fgrep SO_SNDLOWAT /usr/include/**/*.h
/usr/include/asm-generic/socket.h:#define SO_SNDLOWAT    19 

So on ppc64le it has obviously used the generic value of SO_PEERCRED which actually matches the ppc64le specific value of SO_SNDLOWAT :-(

Comment 1 Tom Hughes 2019-07-29 11:05:31 UTC
Oh the previous build (postgresql-11.3-2.fc31) seems to have been fine as the same packages built OK against that.

Comment 2 Tom Hughes 2019-07-29 12:01:37 UTC
Per Florian on the devel list this was likely due to broken kernel-headers on ppc64le when postgresql-11.4-1.fc31 was built, and it should be fixed by the masss rebuild...

Comment 3 Tom Hughes 2019-07-31 12:18:28 UTC
I can confirm that the mass rebuild has fixed this.