Bug 1211871 - heap corruption by memp_stat
Summary: heap corruption by memp_stat
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: libdb
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jan Staněk
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1203338 1224316
TreeView+ depends on / blocked
 
Reported: 2015-04-15 07:05 UTC by Ludwig
Modified: 2020-09-13 21:23 UTC (History)
7 users (show)

Fixed In Version: libdb-5.3.28-12.fc21
Clone Of:
: 1224316 (view as bug list)
Environment:
Last Closed: 2015-06-07 16:07:51 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Upstream patch for the 6.1.23 version (4.93 KB, patch)
2015-05-18 06:48 UTC, Jan Staněk
no flags Details | Diff
Upstream patch for the 5.3.21 version (5.13 KB, patch)
2015-05-19 09:00 UTC, Jan Staněk
no flags Details | Diff
Upstream patch for the 4.7.25 version (5.25 KB, patch)
2015-05-19 09:01 UTC, Jan Staněk
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Github 389ds 389-ds-base issues 1480 0 None None None 2020-09-13 21:23:20 UTC

Description Ludwig 2015-04-15 07:05:00 UTC
Description of problem:

389 directory can crash when a search for th ememory pool file statistics is executed. Invesigation shows that __memp_stat can overwrite the allocated memory

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

4.7.25 and later

How reproducible:
hard. the crashes occured occasionally at a customer site, so far it was possible to reproduce the crash only with manually interfering into th etiming in gdb, see below

Steps to Reproduce with libdb as component in 389-ds:

Create and instance with several backends, start the server and run a monitor search, only a couple of files will be open.
attach gdb to slapd and set a breakpoint in __memp_stat()
start the monitor search
when the breakpoint is hit, set another breakpoint in __memp_get_files(), this will be called for each file contained in the mpfstat
when this breakpoint is hit the first time, start a search for a backend and attribute where the index file is not yet open, choose a "long" filename, eg suffix=moremoremore attr is telephonenumber, which will result in "moremoremore/telephonenumber.db4"
continue the thread with the monitor search, the __memp_get_files breakpoint will be hit several times, inparallel the seaarch thjread gets enough time to open the telephonenumber index file and add it to the file list.
After several itearations I got the crash.


Actual results:


Expected results:


Additional info:
In my analysis I think the problem is here in __memp_stat:
        /* Per-file statistics. */
        if (fspp != NULL) {
                *fspp = NULL;

                /* Count the MPOOLFILE structures. */

It does not only count the files, but also determines the length of the filenames and calculates the len ot allocate
                i = 0;
                len = 0;
                if ((ret = __memp_walk_files(env,
                     mp, __memp_count_files, &len, &i, flags)) != 0)
                        return (ret);
len is the size of memory to allocate
i is the number of files counted

                if (i == 0)
                        return (0);
                len += sizeof(DB_MPOOL_FSTAT *);        /* Trailing NULL */

                /* Allocate space */
                if ((ret = __os_umalloc(env, len, fspp)) != 0)
                        return (ret);

here the space is allocated and used

                tfsp = *fspp;
                *tfsp = NULL;

                /*
                 * Files may have been opened since we counted, don't walk
                 * off the end of the allocated space.
                 */
this comment indicates that it could happen that files are opened in between and does a countdown of i, stopping if i == 0
this works only if a new file is always appended at the end, if not the required space for file names can increase
                if ((ret = __memp_walk_files(env,
                    mp, __memp_get_files, &tfsp, &i, flags)) != 0)
                        return (ret);

                *++tfsp = NULL;
        } 

It looks like this was introduced when hash buckets for mpool files were introduced, in my opinion the problem didn't exist in libdb 3.x

Comment 1 Marcel Wysocki 2015-04-16 17:01:51 UTC
+1

Comment 2 Account closed by the user 2015-04-20 21:49:29 UTC
Reported upstream: https://community.oracle.com/thread/3701204

...

Comment 3 Account closed by the user 2015-05-02 19:00:27 UTC
(In reply to Xose Vazquez Perez from comment #2)

> Reported upstream: https://community.oracle.com/thread/3701204
> 
> ...

At https://community.oracle.com/message/13019543#13019543 yong-Oracle says:

A fix is available for the latest 6.1 code base. If you want a patch for the 6.1 version, please email yong.b.li (at) oracle.com

Comment 4 Ludwig 2015-05-04 08:25:19 UTC
we would need the fix for RHEL6 and RHEL7, can this patch be applied to libdb 4.7 and 5.3 ?

Comment 5 Account closed by the user 2015-05-05 13:54:05 UTC
(In reply to Ludwig from comment #4)

> we would need the fix for RHEL6 and RHEL7, can this patch be applied to
> libdb 4.7 and 5.3 ?

For the time, don't count on it.

The licence of BerkeleyDB >5.3 was changed from Sleepycat(BSD) to GNU AGPL v3:
https://docs.oracle.com/cd/E17076_03/html/installation/license_change60.html

So, you need explicit permission of Oracle to backport fixes to 5.3 or lower releases.

Comment 7 Jan Staněk 2015-05-11 06:31:48 UTC
(In reply to Xose Vazquez Perez from comment #5)
> The licence of BerkeleyDB >5.3 was changed from Sleepycat(BSD) to GNU AGPL
> v3:
> https://docs.oracle.com/cd/E17076_03/html/installation/license_change60.html
> 
> So, you need explicit permission of Oracle to backport fixes to 5.3 or lower
> releases.

I just emailed the the responsible person (yong-Oracle) asking for the patch and the permission to backport. Let's hope we would get it.

Comment 8 Jan Staněk 2015-05-18 06:48:08 UTC
Created attachment 1026575 [details]
Upstream patch for the 6.1.23 version

Comment 9 Jan Staněk 2015-05-18 06:52:53 UTC
Snippets from the email conversation:

> Here is the patch. You're welcomed to backport it to previous BDB versions.

> We can help you backport the patch to previous BDB versions. Which specific versions do you prefer?

So we've got both the patch and the permission to backport, and on top of it offer for help with the backport.

I've responded to the latter with the versions in current RHEL (4.7.25 and 5.3.21), hopefully we will hear back soon.

Comment 10 Jan Staněk 2015-05-19 09:00:41 UTC
Created attachment 1027041 [details]
Upstream patch for the 5.3.21 version

Comment 11 Jan Staněk 2015-05-19 09:01:20 UTC
Created attachment 1027042 [details]
Upstream patch for the 4.7.25 version

Comment 16 Fedora Update System 2015-05-22 13:11:52 UTC
libdb-5.3.28-12.fc22,libdb4-4.8.30-18.fc22 has been submitted as an update for Fedora 22.
https://admin.fedoraproject.org/updates/libdb-5.3.28-12.fc22,libdb4-4.8.30-18.fc22

Comment 17 Fedora Update System 2015-05-22 13:14:08 UTC
libdb-5.3.28-12.fc21,libdb4-4.8.30-18.fc21 has been submitted as an update for Fedora 21.
https://admin.fedoraproject.org/updates/libdb-5.3.28-12.fc21,libdb4-4.8.30-18.fc21

Comment 20 Fedora Update System 2015-05-26 03:38:09 UTC
Package libdb-5.3.28-12.fc21, libdb4-4.8.30-18.fc21:
* should fix your issue,
* was pushed to the Fedora 21 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing libdb-5.3.28-12.fc21 libdb4-4.8.30-18.fc21'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2015-8794/libdb-5.3.28-12.fc21,libdb4-4.8.30-18.fc21
then log in and leave karma (feedback).

Comment 21 Fedora Update System 2015-06-07 16:07:51 UTC
libdb-5.3.28-12.fc22, libdb4-4.8.30-18.fc22 has been pushed to the Fedora 22 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 22 Fedora Update System 2015-06-10 19:19:32 UTC
libdb-5.3.28-12.fc21, libdb4-4.8.30-18.fc21 has been pushed to the Fedora 21 stable repository.  If problems still persist, 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.