<div dir="ltr"><div>I attempted to submit this bug report via the online form, but that failed ("Failed to send your message. Please try later or contact the administrator by another method.")<br><br><br><br>Bind, configured with "dlz postgresql", successfully connects to the database, but crashes (or corrupts the heap, randomly) on the very first query submitted, if the "find zone" query receives a "permission denied" error from Postgresql.<br>
<br>The problem goes away when I correct the permissions on the table. :)<br><br>However, BIND should not crash or corrupt its heap on a database query error. I have not reviewed the DLZ postgresql driver code, but I suspect that the error handler needs some tender loving care. :) Stack trace included (see below):<br>
<br><br>CREATE TABLE dns_records<br>(<br> zone text,<br> host text,<br> ttl integer,<br> type text,<br> mx_priority integer,<br> data text,<br> resp_person text,<br> serial integer,<br> refresh integer,<br> retry integer,<br>
minimum integer,<br> expire integer<br>)<br>WITH (<br> OIDS=FALSE<br>);<br>ALTER TABLE dns_records<br> OWNER TO pgsql;<br><br>(no additional grants, and BIND is configured to connect as the user/role "dns", which does NOT have "select" permission on the table (yet)).<br>
<br>Relevant bind config:<br><br># <a href="http://bind-dlz.sourceforge.net/postgresql_example.html">http://bind-dlz.sourceforge.net/postgresql_example.html</a><br># <a href="http://bind-dlz.sourceforge.net/postgresql_driver.html">http://bind-dlz.sourceforge.net/postgresql_driver.html</a><br>
dlz "postgres zone" {<br> database "postgres 2<br> {host=REDACTED port=5432 dbname=dns user=dns}<br> {select zone from dns_records where zone = '$zone$'}<br> {select ttl, type, mx_priority, case when lower(type)='txt' then '\"' || data<br>
|| '\"' else data end from dns_records where zone = '$zone$' and host = '$record$'<br> and not (type = 'SOA' or type = 'NS')}<br> {select ttl, type, mx_priority, data, resp_person, serial, refresh, retry, expire,<br>
minimum from dns_records where zone = '$zone$' and (type = 'SOA' or type='NS')}<br> {select ttl, type, host, mx_priority, data, resp_person, serial, refresh, retry, expire,<br> minimum from dns_records where zone = '$zone$'}<br>
{select zone from xfr_table where zone = '$zone$' and client = '$client$'}";<br>};<br><br><br>Below is a stack trace, followed by other relevant config bits.<br>(ran "/usr/sbin/named -u named -g -d5" inside "gdb", then send a request for "A aisd-7.test.local" via "dig"):<br>
<br>24-Jul-2014 10:18:38.262 client 127.0.0.1#50111: UDP request<br>24-Jul-2014 10:18:38.262 client 127.0.0.1#50111: using view '_default'<br>24-Jul-2014 10:18:38.262 client 127.0.0.1#50111: request is not signed<br>
24-Jul-2014 10:18:38.262 client 127.0.0.1#50111: recursion available<br>24-Jul-2014 10:18:38.262 client 127.0.0.1#50111: query<br>24-Jul-2014 10:18:38.262<br>Query String: select zone from dns_records where zone = 'aisd-7.test.local'<br>
<br>*** Error in `/usr/sbin/named': double free or corruption (!prev): 0x08168828 ***<br><br>Program received signal SIGABRT, Aborted.<br>0xb7fdd424 in __kernel_vsyscall ()<br>(gdb) bt<br>#0 0xb7fdd424 in __kernel_vsyscall ()<br>
#1 0xb7a3298f in raise () from /lib/libc.so.6<br>#2 0xb7a341a3 in abort () from /lib/libc.so.6<br>#3 0xb7a74115 in __libc_message () from /lib/libc.so.6<br>#4 0xb7a7a732 in malloc_printerr () from /lib/libc.so.6<br>#5 0xb7a7b490 in _int_free () from /lib/libc.so.6<br>
#6 0xb7d40546 in PQclear () from /usr/lib/libpq.so.5<br>#7 0x080b3686 in postgres_findzone ()<br>#8 0xb7f06e82 in dns_sdlzfindzone () from /usr/lib/libdns.so.100<br>#9 0xb7e3d546 in dns_dlzfindzone () from /usr/lib/libdns.so.100<br>
#10 0x0807cdb4 in query_getdb ()<br>#11 0x08082bc6 in query_find ()<br>#12 0x0808e701 in ns_query_start ()<br>#13 0x0806e91d in client_request ()<br>#14 0xb7d8f0d0 in isc__taskmgr_dispatch () from /usr/lib/libisc.so.95<br>
#15 0xb7d93224 in evloop () from /usr/lib/libisc.so.95<br>#16 0xb7d939ea in isc__app_ctxrun () from /usr/lib/libisc.so.95<br>#17 0xb7d93e6d in isc__app_run () from /usr/lib/libisc.so.95<br>#18 0x08067c8d in main ()<br>(gdb) quit<br>
<br>mad-dns-3 net-dns # named -V<br>BIND 9.9.5 (Extended Support Version) <id:f9b8a50e> built by make with '--prefix=/usr' '--build=i686-pc-linux-gnu' '--host=i686-pc-linux-gnu' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--datadir=/usr/share' '--sysconfdir=/etc' '--localstatedir=/var/lib' '--libdir=/usr/lib' '--sysconfdir=/etc/bind' '--localstatedir=/var' '--with-libtool' '--enable-full-report' '--disable-threads' '--with-dlopen' '--with-dlz-filesystem' '--with-dlz-stub' '--with-dlz-postgres' '--without-dlz-mysql' '--with-dlz-bdb' '--without-dlz-ldap' '--without-dlz-odbc' '--with-openssl=/usr' '--with-ecdsa' '--without-idn' '--disable-ipv6' '--without-libxml2' '--disable-newstats' '--without-gssapi' '--disable-rpz-nsip' '--disable-rpz-nsdname' '--disable-linux-caps' '--without-gost' '--disable-filter-aaaa' '--disable-fixed-rrset' '--disable-rrl' '--without-python' '--without-readline' '--with-randomdev=/dev/random' 'build_alias=i686-pc-linux-gnu' 'host_alias=i686-pc-linux-gnu' 'CFLAGS=-O2 -march=i686 -pipe -I/usr/include/db4.8' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed'<br>
compiled by GCC 4.7.3<br>using OpenSSL version: OpenSSL 1.0.1h 5 Jun 2014<br><br><br>mad-dns-3 ~ # dig @<a href="http://127.0.0.1">127.0.0.1</a> A aisd-7.test.local<br><br>; <<>> DiG 9.9.5 <<>> @<a href="http://127.0.0.1">127.0.0.1</a> A aisd-7.test.local<br>
; (1 server found)<br>;; global options: +cmd<br>;; connection timed out; no servers could be reached<br><br><br>ASCII dump of TCP capture between BIND server and POSTGRESQL server:<br>(Yes, the database is not properly configured yet, but BIND should not crash just because postgresql returns an error message instead of a query result):<br>
<br>........user.dns.database.dns..R........S....application_name..S....client_encoding.UTF8.S....DateStyle.ISO, MDY.S....integer_datetimes.on.S....IntervalStyle.postgres.S....is_superuser.off.S....server_encoding.UTF8.S....server_version.9.3.4.S....session_authorization.dns.S...#standard_conforming_strings.on.S....TimeZone.US/Central.K........`d.IZ....IQ...Bselect zone from dns_records where zone = 'aisd-7.test.local'.E..._SERROR.C42501.Mpermission denied for relation dns_records.Faclchk.c.L3371.Raclcheck_error..Z....IQ...Bselect zone from dns_records where zone = 'aisd-7.test.local'.E..._SERROR.C42501.Mpermission denied for relation dns_records.Faclchk.c.L3371.Raclcheck_error..Z....IQ...Bselect zone from dns_records where zone = 'aisd-7.test.local'.E..._SERROR.C42501.Mpermission denied for relation dns_records.Faclchk.c.L3371.Raclcheck_error..Z....I<br>
<br></div>Cleaned up ASCII dump of the postgresql conversation:<br><br>Query:<br> select zone from dns_records where zone = 'aisd-7.test.local'<br><br>Response:<br> ERROR.C42501. permission denied for relation dns_records.<br>
</div>