Debian Bug report logs - #612888
postgresql: access denied via peer credentials (kfrebsd-amd64 specific)

version graph

Package: postgresql-8.4; Maintainer for postgresql-8.4 is Debian PostgreSQL Maintainers <pkg-postgresql-public@lists.alioth.debian.org>;

Reported by: skull <skull@spin.it>

Date: Fri, 11 Feb 2011 10:51:01 UTC

Severity: important

Tags: patch, upstream

Found in version postgresql-8.4/8.4.7-0squeeze2

Fixed in version postgresql-8.4/8.4.8-2

Done: Martin Pitt <mpitt@debian.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Martin Pitt <mpitt@debian.org>:
Bug#612888; Package postgresql. (Fri, 11 Feb 2011 10:51:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to skull <skull@spin.it>:
New Bug report received and forwarded. Copy sent to Martin Pitt <mpitt@debian.org>. (Fri, 11 Feb 2011 10:51:04 GMT) Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: skull <skull@spin.it>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: postgresql: access denied as postgres user after default install (kFreeBSD specific)
Date: Fri, 11 Feb 2011 11:40:27 +0100
Package: postgresql
Version: 8.4.7-0squeeze2
Severity: important


After default installation, postgres denies access to postgres user:

root@netmon:~# su - postgres
postgres@netmon:~$ psql template1
psql: FATAL:  Ident authentication failed for user "postgres"

This happens on kFreeBSD flavour only (AFAIK)


-- System Information:
Debian Release: 6.0
  APT prefers squeeze-updates
  APT policy: (500, 'squeeze-updates'), (500, 'stable')
Architecture: kfreebsd-amd64 (x86_64)

Kernel: kFreeBSD 8.1-1-amd64
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages postgresql depends on:
ii  postgresql-8.4           8.4.7-0squeeze2 object-relational SQL database, ve

postgresql recommends no packages.

postgresql suggests no packages.

-- no debconf information




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Pitt <mpitt@debian.org>:
Bug#612888; Package postgresql. (Fri, 11 Feb 2011 21:42:07 GMT) Full text and rfc822 format available.

Acknowledgement sent to Petr Salinger <Petr.Salinger@seznam.cz>:
Extra info received and forwarded to list. Copy sent to Martin Pitt <mpitt@debian.org>. (Fri, 11 Feb 2011 21:42:07 GMT) Full text and rfc822 format available.

Message #10 received at 612888@bugs.debian.org (full text, mbox):

From: Petr Salinger <Petr.Salinger@seznam.cz>
To: 612888@bugs.debian.org
Cc: control@bugs.debian.org, skull <skull@spin.it>
Subject: postgresql: access denied via peer credentials (kfrebsd-amd64 specific)
Date: Fri, 11 Feb 2011 22:44:00 +0100 (CET)
[Message part 1 (text/plain, inline)]
tags 612888 +patch
user debian-bsd@lists.debian.org
usertag 612888 + kfreebsd
retitle 612888 postgresql: access denied via peer credentials (kfrebsd-amd64 specific)
--

The problem is kfrebsd-amd64 specific,
see also thread started by
http://lists.debian.org/debian-bsd/2011/02/msg00093.html

Alternatively,

char            cmsgmem[CMSG_LEN(sizeof(Cred))]

can be used when #defined (CMSG_LEN).

Please forward the problem upstream and
consider the patch also for stable-proposed-updates.

Many thanks

		Petr

---------- Forwarded message ----------
Date: Fri, 11 Feb 2011 15:06:25 +0100 (CET)
From: Petr Salinger <Petr.Salinger@seznam.cz>
To: Nicolas Barbier <nicolas.barbier@gmail.com>
Cc: Emanuele Balla <balla@staff.spin.it>, debian-bsd@lists.debian.org
Subject: Re: Postgresql deying access

>>> 2011-02-11 12:12:50 CET LOG:  could not get peer credentials:
>>> Interrupted system call

The problem seems be in postgresql package.
The sizeof(struct cmsgcred) is 84 on kfrebsd-amd64, there is no reason
for padding it  at the end to 8-byte boundary by kernel.
But postgresql want these extra 4 bytes to receive.

Please verify, whether patch bellow helps also for you.

Thanks

	Petr

--- src/backend/libpq/auth.c
+++ src/backend/libpq/auth.c
@@ -1764,7 +1764,7 @@
        Cred       *cred;

        /* Compute size without padding */
-       char            cmsgmem[ALIGN(sizeof(struct cmsghdr)) + ALIGN(sizeof(Cred))];   /* for NetBSD */
+       char            cmsgmem[ALIGN(sizeof(struct cmsghdr)) + (sizeof(Cred))];        /* for NetBSD */

        /* Point to start of first structure */
        struct cmsghdr *cmsg = (struct cmsghdr *) cmsgmem;

Added tag(s) patch. Request was from Petr Salinger <Petr.Salinger@seznam.cz> to control@bugs.debian.org. (Fri, 11 Feb 2011 21:42:10 GMT) Full text and rfc822 format available.

Changed Bug title to 'postgresql: access denied via peer credentials (kfrebsd-amd64 specific)' from 'postgresql: access denied as postgres user after default install (kFreeBSD specific)' Request was from Petr Salinger <Petr.Salinger@seznam.cz> to control@bugs.debian.org. (Fri, 11 Feb 2011 21:42:11 GMT) Full text and rfc822 format available.

Bug 612888 cloned as bug 624480. Request was from Petr Salinger <Petr.Salinger@seznam.cz> to control@bugs.debian.org. (Thu, 28 Apr 2011 18:27:02 GMT) Full text and rfc822 format available.

Bug reassigned from package 'postgresql' to 'postgresql-8.4'. Request was from Petr Salinger <Petr.Salinger@seznam.cz> to control@bugs.debian.org. (Thu, 28 Apr 2011 18:27:06 GMT) Full text and rfc822 format available.

Bug No longer marked as found in versions 8.4.7-0squeeze2. Request was from Petr Salinger <Petr.Salinger@seznam.cz> to control@bugs.debian.org. (Thu, 28 Apr 2011 18:27:07 GMT) Full text and rfc822 format available.

Bug Marked as found in versions postgresql-8.4/8.4.7-0squeeze2. Request was from Petr Salinger <Petr.Salinger@seznam.cz> to control@bugs.debian.org. (Thu, 28 Apr 2011 18:27:08 GMT) Full text and rfc822 format available.

Added tag(s) upstream. Request was from Martin Pitt <martin.pitt@ubuntu.com> to control@bugs.debian.org. (Sun, 22 May 2011 13:33:08 GMT) Full text and rfc822 format available.

Bug 612888 cloned as bugs 627596, 627597. Request was from Martin Pitt <martin.pitt@ubuntu.com> to control@bugs.debian.org. (Sun, 22 May 2011 13:33:09 GMT) Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org:
Bug#612888; Package postgresql-8.4. (Sun, 22 May 2011 14:33:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Martin Pitt <mpitt@debian.org>:
Extra info received and forwarded to list. (Sun, 22 May 2011 14:33:03 GMT) Full text and rfc822 format available.

Message #31 received at 612888@bugs.debian.org (full text, mbox):

From: Martin Pitt <mpitt@debian.org>
To: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Cc: Petr Salinger <Petr.Salinger@seznam.cz>, 612888@bugs.debian.org
Subject: [PATCH] ident authentication fails on kFreeBSD/x86-64 due to wrong struct size
Date: Sun, 22 May 2011 16:19:21 +0200
[Message part 1 (text/plain, inline)]
Hello PostgreSQL developers,

I got this report in http://bugs.debian.org/612888 about ident failure
on the Debian kFreeBSD kernel on 64 bit. The sizeof(struct cmsgcred)
is 84 on kfrebsd-amd64, there is no reason for padding it  at the end
to 8-byte boundary by kernel. However, the process is blocking on
receiving those extra 4 bytes, which will never come.

Petr Salinger <Petr.Salinger@seznam.cz> sent a straightforward patch
for this, I turned it into a git-formatted patch for your convenience.

Thanks,

Martin

----- Forwarded message from skull <skull@spin.it> -----

Date: Fri, 11 Feb 2011 11:40:27 +0100
From: skull <skull@spin.it>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: Bug#612888: postgresql: access denied as postgres user after default install (kFreeBSD specific)
X-Spam-Status: No, score=0.0 required=4.0 tests=BAYES_50 autolearn=no version=3.2.5
Reply-To: skull <skull@spin.it>, 612888@bugs.debian.org

Package: postgresql
Version: 8.4.7-0squeeze2
Severity: important


After default installation, postgres denies access to postgres user:

root@netmon:~# su - postgres
postgres@netmon:~$ psql template1
psql: FATAL:  Ident authentication failed for user "postgres"

This happens on kFreeBSD flavour only (AFAIK)


-- System Information:
Debian Release: 6.0
  APT prefers squeeze-updates
  APT policy: (500, 'squeeze-updates'), (500, 'stable')
Architecture: kfreebsd-amd64 (x86_64)

Kernel: kFreeBSD 8.1-1-amd64
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages postgresql depends on:
ii  postgresql-8.4           8.4.7-0squeeze2 object-relational SQL database, ve

postgresql recommends no packages.

postgresql suggests no packages.

-- no debconf information



----- End forwarded message -----

-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
[0001-Fix-size-of-struct-cmsgcred.patch (text/x-diff, attachment)]
[signature.asc (application/pgp-signature, inline)]

Reply sent to Martin Pitt <mpitt@debian.org>:
You have taken responsibility. (Sun, 22 May 2011 18:36:09 GMT) Full text and rfc822 format available.

Notification sent to skull <skull@spin.it>:
Bug acknowledged by developer. (Sun, 22 May 2011 18:36:09 GMT) Full text and rfc822 format available.

Message #36 received at 612888-close@bugs.debian.org (full text, mbox):

From: Martin Pitt <mpitt@debian.org>
To: 612888-close@bugs.debian.org
Subject: Bug#612888: fixed in postgresql-8.4 8.4.8-2
Date: Sun, 22 May 2011 18:32:32 +0000
Source: postgresql-8.4
Source-Version: 8.4.8-2

We believe that the bug you reported is fixed in the latest version of
postgresql-8.4, which is due to be installed in the Debian FTP archive:

postgresql-8.4_8.4.8-2.diff.gz
  to main/p/postgresql-8.4/postgresql-8.4_8.4.8-2.diff.gz
postgresql-8.4_8.4.8-2.dsc
  to main/p/postgresql-8.4/postgresql-8.4_8.4.8-2.dsc
postgresql-8.4_8.4.8-2_amd64.deb
  to main/p/postgresql-8.4/postgresql-8.4_8.4.8-2_amd64.deb
postgresql-client-8.4_8.4.8-2_amd64.deb
  to main/p/postgresql-8.4/postgresql-client-8.4_8.4.8-2_amd64.deb
postgresql-contrib-8.4_8.4.8-2_amd64.deb
  to main/p/postgresql-8.4/postgresql-contrib-8.4_8.4.8-2_amd64.deb
postgresql-doc-8.4_8.4.8-2_all.deb
  to main/p/postgresql-8.4/postgresql-doc-8.4_8.4.8-2_all.deb
postgresql-plperl-8.4_8.4.8-2_amd64.deb
  to main/p/postgresql-8.4/postgresql-plperl-8.4_8.4.8-2_amd64.deb
postgresql-plpython-8.4_8.4.8-2_amd64.deb
  to main/p/postgresql-8.4/postgresql-plpython-8.4_8.4.8-2_amd64.deb
postgresql-pltcl-8.4_8.4.8-2_amd64.deb
  to main/p/postgresql-8.4/postgresql-pltcl-8.4_8.4.8-2_amd64.deb
postgresql-server-dev-8.4_8.4.8-2_amd64.deb
  to main/p/postgresql-8.4/postgresql-server-dev-8.4_8.4.8-2_amd64.deb



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 612888@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Martin Pitt <mpitt@debian.org> (supplier of updated postgresql-8.4 package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Sun, 22 May 2011 15:41:07 +0200
Source: postgresql-8.4
Binary: postgresql-8.4 postgresql-client-8.4 postgresql-server-dev-8.4 postgresql-doc-8.4 postgresql-contrib-8.4 postgresql-plperl-8.4 postgresql-plpython-8.4 postgresql-pltcl-8.4
Architecture: source all amd64
Version: 8.4.8-2
Distribution: unstable
Urgency: low
Maintainer: Martin Pitt <mpitt@debian.org>
Changed-By: Martin Pitt <mpitt@debian.org>
Description: 
 postgresql-8.4 - object-relational SQL database, version 8.4 server
 postgresql-client-8.4 - front-end programs for PostgreSQL 8.4
 postgresql-contrib-8.4 - additional facilities for PostgreSQL
 postgresql-doc-8.4 - documentation for the PostgreSQL database management system
 postgresql-plperl-8.4 - PL/Perl procedural language for PostgreSQL 8.4
 postgresql-plpython-8.4 - PL/Python procedural language for PostgreSQL 8.4
 postgresql-pltcl-8.4 - PL/Tcl procedural language for PostgreSQL 8.4
 postgresql-server-dev-8.4 - development files for PostgreSQL 8.4 server-side programming
Closes: 612888 616948
Changes: 
 postgresql-8.4 (8.4.8-2) unstable; urgency=low
 .
   * debian/postgresql-8.4.postrm: Clean up pg_ctl.conf on purge.
   * debian/control, debian/rules: Drop usage of pycentral. We don't ship any
     Python extension/module, so we don't need a python helper at all.
     (Closes: #616948)
   * Add 16-cmsgcred-size.patch: Fix size of struct cmsgcred to fix ident
     authentication on kFreeBSD 64 bit. Thanks to Petr Salinger for the patch!
     (Closes: #612888)
Checksums-Sha1: 
 73c7b567e1a88c70a387137b4c71b51c5efc7ad8 2300 postgresql-8.4_8.4.8-2.dsc
 68a81a04fd7cba2eb7ee25edbde6ce35c36a3ebb 41751 postgresql-8.4_8.4.8-2.diff.gz
 af546d7ea3be3a5b5c0e6fb393c48a36ccf694cc 2150652 postgresql-doc-8.4_8.4.8-2_all.deb
 a88add6465f758a3f2ffade1898956bb339f9194 5339802 postgresql-8.4_8.4.8-2_amd64.deb
 baef050e1e835e4169daf52f97fe96223a12c97e 1471334 postgresql-client-8.4_8.4.8-2_amd64.deb
 316a3811eba2dcb1099796ec6b22444c06826a7b 640904 postgresql-server-dev-8.4_8.4.8-2_amd64.deb
 0fb07888e2ca04c5ddcc36932cc1770674b9f00f 432886 postgresql-contrib-8.4_8.4.8-2_amd64.deb
 92d14b86a696086880bb386a4b5985ce9c851f4b 60340 postgresql-plperl-8.4_8.4.8-2_amd64.deb
 9d28e9dc6e92a619da2b852347f5ba2b94f5ae06 57552 postgresql-plpython-8.4_8.4.8-2_amd64.deb
 1d18095f7d795ca0c08eee62a43873e950c65320 43510 postgresql-pltcl-8.4_8.4.8-2_amd64.deb
Checksums-Sha256: 
 aeb07844d5c1dab02b7a3e83a7f1a2571d90f8e821db4b11a60bce74efa58c7d 2300 postgresql-8.4_8.4.8-2.dsc
 c7bc713678b33fcc4517ce17aa3145c5015710a9b7a0e980e4da655d85edbd56 41751 postgresql-8.4_8.4.8-2.diff.gz
 b7df4142fef799a4347247064358215accbb8051ccd3f7c8e245013ee306c0eb 2150652 postgresql-doc-8.4_8.4.8-2_all.deb
 fec802c12ab873ec3a208d4d4be74c999055e7b8699b599706d540a628c2a093 5339802 postgresql-8.4_8.4.8-2_amd64.deb
 5a942e56e10c04ade58b1365f764d67fc2acbb1f2a236a4073e85c3c17074ece 1471334 postgresql-client-8.4_8.4.8-2_amd64.deb
 0dea8d5e4be496d09af673dfd1cb166d9c4dbf12e26e82fe3cf076a0dd06583f 640904 postgresql-server-dev-8.4_8.4.8-2_amd64.deb
 793596a1f5b4d1d3f4fe691bbc92ea023c49bc74474fa5f695c6a0fb3ea01c68 432886 postgresql-contrib-8.4_8.4.8-2_amd64.deb
 1e3f7257e2a6efd881de96117c5995e26510d936163b668de812c2e90310e7c5 60340 postgresql-plperl-8.4_8.4.8-2_amd64.deb
 5907341d73406046a9e3f09f2b820aa073565c30b5affc60ea5e480133795f4e 57552 postgresql-plpython-8.4_8.4.8-2_amd64.deb
 615e0accbded235f2f7ca095de310be0697ac8b1a3269feea729cd2f3fcc25db 43510 postgresql-pltcl-8.4_8.4.8-2_amd64.deb
Files: 
 ba2499e7a7f80d081aed2f5196248c72 2300 database optional postgresql-8.4_8.4.8-2.dsc
 217112be21a952877e7c8cee2c016f22 41751 database optional postgresql-8.4_8.4.8-2.diff.gz
 a85f445031ffba8ff471453d9c174dac 2150652 doc optional postgresql-doc-8.4_8.4.8-2_all.deb
 b9d69c64f86251802e1879dae6d76b40 5339802 database optional postgresql-8.4_8.4.8-2_amd64.deb
 25104e22b85ceb2d80baf9a46bf1692e 1471334 database optional postgresql-client-8.4_8.4.8-2_amd64.deb
 e183bdb42ddd5d2dd122dc2bc6747c12 640904 libdevel optional postgresql-server-dev-8.4_8.4.8-2_amd64.deb
 be6f82ba678a5c902128a7c2b68cb319 432886 database optional postgresql-contrib-8.4_8.4.8-2_amd64.deb
 47b19392efd43f1a4ad70667c0663f47 60340 database optional postgresql-plperl-8.4_8.4.8-2_amd64.deb
 16fc0d527ef90b0e48110b6a972307b3 57552 database optional postgresql-plpython-8.4_8.4.8-2_amd64.deb
 c3cc6642fb171ddf761cc801724e8c35 43510 database optional postgresql-pltcl-8.4_8.4.8-2_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAEBCAAGBQJN2RdgAAoJEPmIJawmtHufMZQP/1Na08L2XYytwNlvsW93bkc5
FRjL9k0KNlYMMcc/jfr2YcDLsLtE6962m2forQgOo0+2mc9r57QsVyh6PAe0uz+X
cdZeaMOqWj9E6YpF/+5i/Tr4bay0v4HEU0rLGMGdU/nfaynuM+P9m1ccqd8ZB96z
FTUuDLG/SYq4wR7OMj1KesY4fTar2hWlR2htLLREwSDzBY+ICHmLAh3nFUxfu/fl
vNzmsZn/H3KUgrwTKsVUmYf+0JNQv7BF4G9txT5guUDHioYgYWVlKi9i26Yxobkw
hPi05DjTqizpWOZ9YjxJ8nn7J7HEMwoE2WOIZ2GWq6fGJcTcNkhwUzLIUXMxpH7n
04fdEvdKk+P0pU9DQT+W30TrAS8F4TmaIbQWBdzzTw+vx/3MPuZ2mGI5lafIgEbz
oZJUwEi3UbX1Qr7XJkogimKUWej6MoPWgD8SrI+QIuIEeO0jFui4EboLIlO9+ImS
wGBDi/9ip5FK2zYjt9rHFTjByHnFGQ5Vb7zhL1lyH7mmuJCXsxWay8ZIyi5EnOH6
z/wDjdhpkA857OrzycdVR/Nx75eKvIUFUHUfy+vJgsoUSybpy7o2OKEa8qkppR/D
+Wx25MxPMPtNEORXaTtlorKbwpe/1uPs/yEqkrv25wfQabM67rEYxSLm904L+i2m
cQUuTiirLC6rpUKLeJUB
=EqIB
-----END PGP SIGNATURE-----





Information forwarded to debian-bugs-dist@lists.debian.org, Martin Pitt <mpitt@debian.org>:
Bug#612888; Package postgresql-8.4. (Sun, 29 May 2011 18:30:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tom Lane <tgl@sss.pgh.pa.us>:
Extra info received and forwarded to list. Copy sent to Martin Pitt <mpitt@debian.org>. (Sun, 29 May 2011 18:30:06 GMT) Full text and rfc822 format available.

Message #41 received at 612888@bugs.debian.org (full text, mbox):

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Martin Pitt <mpitt@debian.org>
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>, Petr Salinger <Petr.Salinger@seznam.cz>, 612888@bugs.debian.org
Subject: Re: [BUGS] [PATCH] ident authentication fails on kFreeBSD/x86-64 due to wrong struct size
Date: Sun, 29 May 2011 14:08:33 -0400
Martin Pitt <mpitt@debian.org> writes:
>  	/* Compute size without padding */
> -	char		cmsgmem[ALIGN(sizeof(struct cmsghdr)) + ALIGN(sizeof(Cred))];	/* for NetBSD */
> +	char		cmsgmem[ALIGN(sizeof(struct cmsghdr)) + sizeof(Cred)];	/* for NetBSD */

Hm.  That code's been like that for a very long time (since 2001
according to the git history...).  How much confidence can we have
that this change won't result in breakage on other flavors of *BSD?

(I'm unable to test this myself, not having any platforms on which
this branch of auth_peer gets compiled...)

			regards, tom lane




Information forwarded to debian-bugs-dist@lists.debian.org, Martin Pitt <mpitt@debian.org>:
Bug#612888; Package postgresql-8.4. (Sun, 29 May 2011 18:51:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tom Lane <tgl@sss.pgh.pa.us>:
Extra info received and forwarded to list. Copy sent to Martin Pitt <mpitt@debian.org>. (Sun, 29 May 2011 18:51:03 GMT) Full text and rfc822 format available.

Message #46 received at 612888@bugs.debian.org (full text, mbox):

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Martin Pitt <mpitt@debian.org>
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>, Petr Salinger <Petr.Salinger@seznam.cz>, 612888@bugs.debian.org
Subject: Re: [BUGS] [PATCH] ident authentication fails on kFreeBSD/x86-64 due to wrong struct size
Date: Sun, 29 May 2011 14:49:43 -0400
I wrote:
> Martin Pitt <mpitt@debian.org> writes:
>> /* Compute size without padding */
>> -	char		cmsgmem[ALIGN(sizeof(struct cmsghdr)) + ALIGN(sizeof(Cred))];	/* for NetBSD */
>> +	char		cmsgmem[ALIGN(sizeof(struct cmsghdr)) + sizeof(Cred)];	/* for NetBSD */

> Hm.  That code's been like that for a very long time (since 2001
> according to the git history...).  How much confidence can we have
> that this change won't result in breakage on other flavors of *BSD?

BTW, I wonder whether the real bug isn't on the libpq side instead.
I notice that its idea of the cmsgmem size is not like the backend's:

#ifdef HAVE_STRUCT_CMSGCRED
	/* Prevent padding */
	char		cmsgmem[sizeof(struct cmsghdr) + sizeof(struct cmsgcred)];

This corresponds to the original coding in the backend, but not to what
the code looks like now.  The subsequent whacking around of the backend
cmsgmem declaration was documented as fixing problems on NetBSD and then
OpenBSD.  If it's true as per the libpq comment that only FreeBSD needs
the client-side cmsgmem buffer, this might not have gotten retested.

			regards, tom lane




Information stored :
Bug#612888; Package postgresql-8.4. (Sun, 29 May 2011 20:12:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Petr Salinger <Petr.Salinger@seznam.cz>:
Extra info received and filed, but not forwarded. (Sun, 29 May 2011 20:12:03 GMT) Full text and rfc822 format available.

Message #51 received at 612888-quiet@bugs.debian.org (full text, mbox):

From: Petr Salinger <Petr.Salinger@seznam.cz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: 612888-quiet@bugs.debian.org, Theo de Raadt <deraadt@cvs.openbsd.org>, Martin Pitt <mpitt@debian.org>
Subject: Re: 612888@bugs.debian.org
Date: Sun, 29 May 2011 22:16:16 +0200 (CEST)
>> -char	cmsgmem[ALIGN(sizeof(struct cmsghdr)) + ALIGN(sizeof(Cred))];	/* for NetBSD */
>> +char	cmsgmem[ALIGN(sizeof(struct cmsghdr)) + sizeof(Cred)];	/* for NetBSD */
>
> The ALIGN()'s were most certainly wrong, but it is not enough to
> fix it in this way.
>
> That will break (not just on OpenBSD, but somewhere else, perhaps not
> on architecture XXX, but perhaps on architecure YYY).  You need a
> union, and you must use CMSG_SPACE().  The CMSG_SPACE is documented in
> Stevens, but he did not anticipate the problems strict-alignment
> architectures would cause us, which also led him to believe that
> CMSG_SPACE and CMSG_LEN could be the same (they can't be).

The postgresql currently does not differentiate between space 
allocated for the buffer and the needed mesage size to be received.

> The best bet is to get religious about following a careful layout
> scheme for the buffers, so please read this manual page for the
> definative way to use the CMSG API correctly:
>
>    http://www.openbsd.org/cgi-bin/man.cgi?query=CMSG_SPACE
...

> So.. that manual page shows the canonical way that userland code
> should be attempting to use the API.  Please, if you can, adjust your
> code to follow this.  It will work better everywhere.

I will be of course glad to verify whether such code works 
correctly on GNU/kFreeBSD. I expect that it will.
By union you will get correctly aligned buffer
and the CMSG_SPACE/CMSG_LEN difference will solve the
missing 4 bytes padding on 64 bit architecture.

Petr

----------
http://bugs.debian.org//cgi-bin/bugreport.cgi?bug=612888





Information stored :
Bug#612888; Package postgresql-8.4. (Mon, 30 May 2011 00:12:11 GMT) Full text and rfc822 format available.

Acknowledgement sent to Theo de Raadt <deraadt@cvs.openbsd.org>:
Extra info received and filed, but not forwarded. (Mon, 30 May 2011 00:12:12 GMT) Full text and rfc822 format available.

Message #56 received at 612888-quiet@bugs.debian.org (full text, mbox):

From: Theo de Raadt <deraadt@cvs.openbsd.org>
To: Petr Salinger <Petr.Salinger@seznam.cz>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, 612888-quiet@bugs.debian.org, Martin Pitt <mpitt@debian.org>
Subject: Re: 612888@bugs.debian.org
Date: Sun, 29 May 2011 17:44:01 -0600
> >> -char	cmsgmem[ALIGN(sizeof(struct cmsghdr)) + ALIGN(sizeof(Cred))];	/* for NetBSD */
> >> +char	cmsgmem[ALIGN(sizeof(struct cmsghdr)) + sizeof(Cred)];	/* for NetBSD */
> >
> > The ALIGN()'s were most certainly wrong, but it is not enough to
> > fix it in this way.
> >
> > That will break (not just on OpenBSD, but somewhere else, perhaps not
> > on architecture XXX, but perhaps on architecure YYY).  You need a
> > union, and you must use CMSG_SPACE().  The CMSG_SPACE is documented in
> > Stevens, but he did not anticipate the problems strict-alignment
> > architectures would cause us, which also led him to believe that
> > CMSG_SPACE and CMSG_LEN could be the same (they can't be).
> 
> The postgresql currently does not differentiate between space 
> allocated for the buffer and the needed mesage size to be received.

That is OK, if I understand you correctly.

You are saying you use CMSG_SPACE() to declare the send space, and
CMSG_SPACE() to declare the receive space.  Fine.  As long as it is
the right size of larger (with any padding at the END).

But note that this is not at all related to CMSG_LEN(), which is
something utterly different, and only related to the cmsg_len.  There
are a few broken systems out there that are overly forgiving when the
cmsg_len field is not exactly the size of the actual object being
passed.  Other systems are rather anal and require that the cmsg_len
field is exactly the size of the object.  Requiring sizes to 100%
correct is the right way, obviously, any part of the kernel which
accepts an "estimate" is totally broken (imagine a world with a type
called closeto_size_t or almost_size_t).

(For a bit of history, someone in IPV6 land tried to break this to an
insane extent, but that problem has gone away.  Same person who made
it so that sockaddr_in6 is the first sockaddr_* type which is not a
power of 2 in size).

> > The best bet is to get religious about following a careful layout
> > scheme for the buffers, so please read this manual page for the
> > definative way to use the CMSG API correctly:
> >
> >    http://www.openbsd.org/cgi-bin/man.cgi?query=CMSG_SPACE
> ...
> 
> > So.. that manual page shows the canonical way that userland code
> > should be attempting to use the API.  Please, if you can, adjust your
> > code to follow this.  It will work better everywhere.
> 
> I will be of course glad to verify whether such code works 
> correctly on GNU/kFreeBSD. I expect that it will.

Well I suspect the key is to not worry about one particular system,
but to get it right for everyone.  Your worst case is going to be a
64-bit strict-alignment architecture, running an operating system
which does not silently emulate mis-aligned accesses.  I know that
Linux runs worse and worse on those every year, but it is still
worthwhile trying to find one.

> By union you will get correctly aligned buffer
> and the CMSG_SPACE/CMSG_LEN difference will solve the
> missing 4 bytes padding on 64 bit architecture.

The union doesn't just get the size "right"-- it make sure that the
relative location of the field after the cmsg is right, too, in case
you want to access it using C code.  Imagine if you were passing a
long long or a double on a strict-alignment architecture, via some
fictional cmsg message type which does not exist today). 

Anytime someone uses something like ALIGN() it is a potential bug.
Fundamentally there is no single alignment rule which applies to all
kinds of object placements (stack, global, allocated, etc).

I googled today and saw a lot of code which assumes "oh, I know the
address, it is whatever + ALIGN(whatever)", but no, it won't get at
the thing you want. That is not how ALIGN() works.  ALIGN() is only
working within that specific declaration, on the stack, or globally,
of that array, to ensure that it is right.  It does not work
dynamically.  NetBSD tried to make it work dynamically, which is why
those morons now can't declare a static or global cmsg object...




Information stored :
Bug#612888; Package postgresql-8.4. (Mon, 30 May 2011 05:45:12 GMT) Full text and rfc822 format available.

Acknowledgement sent to Petr Salinger <Petr.Salinger@seznam.cz>:
Extra info received and filed, but not forwarded. (Mon, 30 May 2011 05:45:13 GMT) Full text and rfc822 format available.

Message #61 received at 612888-quiet@bugs.debian.org (full text, mbox):

From: Petr Salinger <Petr.Salinger@seznam.cz>
To: Theo de Raadt <deraadt@cvs.openbsd.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, 612888-quiet@bugs.debian.org, Martin Pitt <mpitt@debian.org>
Subject: Re: 612888@bugs.debian.org
Date: Mon, 30 May 2011 07:37:31 +0200 (CEST)
>> The postgresql currently does not differentiate between space
>> allocated for the buffer and the needed mesage size to be received.
>
> That is OK, if I understand you correctly.
>
> You are saying you use CMSG_SPACE() to declare the send space, and
> CMSG_SPACE() to declare the receive space.  Fine.  As long as it is
> the right size of larger (with any padding at the END).

No, after education from OpenBSD manpage,
I am saying that postgresql currently on GNU/kFreeBSD does nearby:

/* space allocated for the buffer */
msg.msg_controllen = CMSG_SPACE();

and after recvmsg()

/* needed mesage size to be received */
if (cmsg->cmsg_len < CMSG_SPACE())
	error()

And the CMSG_LEN() is not the same as CMSG_SPACE() for amd64.
Therefore it bails out.

See lines 1900-1930 in
http://git.postgresql.org/gitweb?p=postgresql.git;a=blob;f=src/backend/libpq/auth.c

Petr




Information stored :
Bug#612888; Package postgresql-8.4. (Mon, 30 May 2011 23:36:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tom Lane <tgl@sss.pgh.pa.us>:
Extra info received and filed, but not forwarded. (Mon, 30 May 2011 23:36:05 GMT) Full text and rfc822 format available.

Message #66 received at 612888-quiet@bugs.debian.org (full text, mbox):

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Petr Salinger <Petr.Salinger@seznam.cz>
Cc: Theo de Raadt <deraadt@cvs.openbsd.org>, 612888-quiet@bugs.debian.org, Martin Pitt <mpitt@debian.org>
Subject: Re: 612888@bugs.debian.org
Date: Mon, 30 May 2011 19:18:11 -0400
Petr Salinger <Petr.Salinger@seznam.cz> writes:
> ... No, after education from OpenBSD manpage,
> I am saying that postgresql currently on GNU/kFreeBSD does nearby:
> ...
> And the CMSG_LEN() is not the same as CMSG_SPACE() for amd64.
> Therefore it bails out.

I've applied patches to fix this along the lines suggested by Theo.
Thanks for the report!

			regards, tom lane




Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Tue, 28 Jun 2011 07:37:23 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Thu Apr 17 11:22:22 2014; Machine Name: beach.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.