Issue 8084 - Segfault on ppc64 caused by commit 6ad38fef3fe63ff86c1e6cff3c6330353b21cc24
Summary: Segfault on ppc64 caused by commit 6ad38fef3fe63ff86c1e6cff3c6330353b21cc24
Status: VERIFIED FEEDBACK
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: slapd (show other issues)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-19 12:56 UTC by jsynacek@redhat.com
Modified: 2021-08-03 18:13 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description jsynacek@redhat.com 2015-03-19 12:56:31 UTC
Full_Name: Jan Synacek
Version: master
OS: GNU/Linux
URL: 
Submission from: (NULL) (213.175.37.10)


On PPC64, slapd segfaults on startup when using mdb as the backend.

Reproducer:

1) ./configure && make && make install STRIP=""
2) slapd -d1 -h "ldap:/// ldapi:///" -f slapd.conf

$ cat slapd.conf
include         /etc/opldldap/schema/core.schema
include         /etc/openldap/schema/cosine.schema
include         /etc/openldap/schema/inetorgperson.schema
include         /etc/openldap/schema/nis.schema
allow bind_v2
pidfile         /var/run/openldap/slapd.pid
argsfile        /var/run/openldap/slapd.args

database  mdb
directory       /var/lib/ldap/
suffix          dc=foo,dc=bar,dc=com
rootdn          "cn=Manager,dc=foo,dc=bar,dc=com"
# password is 'x'
rootpw          {SSHA}tOSmeQCcYIm1S9ujgpg2Km5rpUnR9dRBD%D


There seems to be a program memory corruption, since the backtrace doesn't make
any sense and valgrind reports "Illegal instruction".


gdb --args -d1 -h "ldap:/// ldapi:///" -f slapd.conf
...
(gdb) r
...
Program received signal SIGSEGV, Segmentation fault.
0x000000001014b98c in 000006ae.plt_call.pthread_mutex_unlock@@GLIBC_2.3+0 ()
(gdb) bt
#0  0x000000001014b98c in 000006ae.plt_call.pthread_mutex_unlock@@GLIBC_2.3+0
()
#1  0x000000001014d79c in mdb_env_open (env=0x1034a4e0, path=0x102d5250
"/var/lib/ldap/", flags=536870912, mode=<value optimized out>) at
./../../../libraries/liblmdb/mdb.c:4540
#2  0x00000000100b91d4 in mdb_db_open (be=0x102b02c0, cr=0xfffffffe9a0) at
init.c:174
#3  0x000000001003c130 in backend_startup_one (be=0x102b02c0, cr=0xfffffffe9a0)
at backend.c:224
#4  0x000000001003c58c in backend_startup (be=0x102b02c0) at backend.c:330
#5  0x000000001005d650 in slap_startup (be=0x0) at init.c:220
#6  0x0000000010009b88 in main (argc=<value optimized out>, argv=<value
optimized out>) at main.c:997
(gdb) up
#1  0x000000001014d79c in mdb_env_open (env=0x1034a4e0, path=0x102d5250
"/var/lib/ldap/", flags=536870912, mode=<value optimized out>) at
./../../../libraries/liblmdb/mdb.c:4540
4540		env->me_path = strdup(path);


I bisected the problem and the following commit is the problem:
commit 6ad38fef3fe63ff86c1e6cff3c6330353b21cc24
Author: Howard Chu <hyc@openldap.org>
Date:   Wed Jan 14 19:05:17 2015 +0000

    Fix typo in 45146ba21a9ee494e7058ca7a173fcc6b27df744

diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c
index 46d1c6d..08e733f 100644
--- a/servers/slapd/schema_init.c
+++ b/servers/slapd/schema_init.c
@@ -1826,7 +1826,7 @@ UTF8StringValidate(
                if( LDAP_UTF8_OFFSET( (char *)u ) != len ) return
LDAP_INVALID_SYNTAX;
        }
 
-       if( u >= len ) {
+       if( u > end ) {
                return LDAP_INVALID_SYNTAX;
        }

This problem is already present in 2.4.40, but absent in 2.4.39.
Comment 1 jsynacek@redhat.com 2015-03-20 13:44:17 UTC
jsynacek@redhat.com writes:

> I bisected the problem and the following commit is the problem:
> commit 6ad38fef3fe63ff86c1e6cff3c6330353b21cc24
> Author: Howard Chu <hyc@openldap.org>
> Date:   Wed Jan 14 19:05:17 2015 +0000
>
>     Fix typo in 45146ba21a9ee494e7058ca7a173fcc6b27df744
>
> diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c
> index 46d1c6d..08e733f 100644
> --- a/servers/slapd/schema_init.c
> +++ b/servers/slapd/schema_init.c
> @@ -1826,7 +1826,7 @@ UTF8StringValidate(
>                 if( LDAP_UTF8_OFFSET( (char *)u ) != len ) return
> LDAP_INVALID_SYNTAX;
>         }
>  
> -       if( u >= len ) {
> +       if( u > end ) {
>                 return LDAP_INVALID_SYNTAX;
>         }

This commit obviously doesn't have anything to do with the crash. I'm
not sure why the crash is triggered from this commit onward.

The real issue seems to be the attribute usage in mdb.c:

#  define      ESECT   __attribute__ ((section("text_env")))

If ESECT is simply removed, the crash goes away.

-- 
Jan Synacek
Software Engineer, Red Hat

Comment 2 Howard Chu 2015-03-20 20:37:41 UTC
jsynacek@redhat.com wrote:
> jsynacek@redhat.com writes:
>
>> I bisected the problem and the following commit is the problem:
>> commit 6ad38fef3fe63ff86c1e6cff3c6330353b21cc24
>> Author: Howard Chu <hyc@openldap.org>
>> Date:   Wed Jan 14 19:05:17 2015 +0000
>>
>>      Fix typo in 45146ba21a9ee494e7058ca7a173fcc6b27df744
>>
>> diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c
>> index 46d1c6d..08e733f 100644
>> --- a/servers/slapd/schema_init.c
>> +++ b/servers/slapd/schema_init.c
>> @@ -1826,7 +1826,7 @@ UTF8StringValidate(
>>                  if( LDAP_UTF8_OFFSET( (char *)u ) != len ) return
>> LDAP_INVALID_SYNTAX;
>>          }
>>
>> -       if( u >= len ) {
>> +       if( u > end ) {
>>                  return LDAP_INVALID_SYNTAX;
>>          }
>
> This commit obviously doesn't have anything to do with the crash. I'm
> not sure why the crash is triggered from this commit onward.
>
> The real issue seems to be the attribute usage in mdb.c:
>
> #  define      ESECT   __attribute__ ((section("text_env")))
>
> If ESECT is simply removed, the crash goes away.

Sounds like a ppc64 binutils bug then. You can #if 0 that definition for ppc64 if you want, since it's only a small optimization for text segment size. But if ppc64 is using standard ELF binary format, this should not be breaking.

-- 
   -- Howard Chu
   CTO, Symas Corp.           http://www.symas.com
   Director, Highland Sun     http://highlandsun.com/hyc/
   Chief Architect, OpenLDAP  http://www.openldap.org/project/

Comment 3 Howard Chu 2015-04-16 02:00:31 UTC
changed state Open to Feedback