Bug 740631 - rpm -qa call cause segfault in libdb after write() failed
Summary: rpm -qa call cause segfault in libdb after write() failed
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: db4
Version: 6.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Matej Mužila
QA Contact: Jakub Prokes
URL:
Whiteboard:
Depends On:
Blocks: 1359256
TreeView+ depends on / blocked
 
Reported: 2011-09-22 18:08 UTC by Konstantin Volkov
Modified: 2017-03-21 09:31 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: No Doc Update
Doc Text:
undefined
Clone Of:
Environment:
Last Closed: 2017-03-21 09:31:23 UTC


Attachments (Terms of Use)
Patch (223 bytes, patch)
2011-09-22 18:14 UTC, Konstantin Volkov
no flags Details | Diff


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2017:0609 normal SHIPPED_LIVE db4 bug fix update 2017-03-21 12:27:13 UTC

Description Konstantin Volkov 2011-09-22 18:08:38 UTC
Description of problem:

rpm -qa call cause segfault in libdb after write() failed

Here some strace (from Parallels Virtuozzo Containers, don't pay attention for /vz/root/$VEID rpmdb prefixes):

---
open("/proc/stat", O_RDONLY|O_CLOEXEC)  = 4
read(4, "cpu  307856 1169 351181 11937594"..., 8192) = 1243
close(4)                                = 0
open("/vz/root/17000/var/lib/rpm/DB_CONFIG", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/vz/root/17000/var/lib/rpm/__db.001", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0644) = 4
fcntl64(4, F_GETFD)                     = 0
fcntl64(4, F_SETFD, FD_CLOEXEC)         = 0
open("/vz/root/17000/var/lib/rpm/__db.001", O_RDWR|O_CREAT|O_LARGEFILE, 0644) = 5
fcntl64(5, F_GETFD)                     = 0
fcntl64(5, F_SETFD, FD_CLOEXEC)         = 0
_llseek(5, 16384, [16384], SEEK_SET)    = 0
write(5, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192) = -1 EDQUOT (Disk quota exceeded)
write(2, "rpmdb", 5)                    = 5
write(2, ": ", 2)                       = 2
write(2, "write: 0x918e698, 8192", 22)  = 22
write(2, ": Disk quota exceeded", 21)   = 21
write(2, "\n", 1)                       = 1
mmap2(NULL, 24576, PROT_READ|PROT_WRITE, MAP_SHARED, 5, 0) = 0xffffffffb7716000
close(5)                                = 0
--- SIGBUS (Bus error) @ 0 (0) ---
---

As you can see, libdb got the EDQUOT error at write() call, but try to call mmap2() and segfaults.

Here gdb dump:

---
(gdb) bt
#0  0x00288d52 in __env_alloc_init (infop=0x86350a0, size=24492) at /usr/include/bits/string3.h:85
#1  0x00292046 in __env_attach (env=0x8636320, init_flagsp=0xbfb78e78, create_ok=1, retry_ok=1) at ../../env/env_region.c:389
#2  0x0028ee26 in __env_open (dbenv=0x8635f90, db_home=0x863e618 "/vz/root/17000/var/lib/rpm", flags=289, mode=420) at ../../env/env_open.c:308
#3  0x0028f638 in __env_open_pp (dbenv=0x8635f90, db_home=0x863e618 "/vz/root/17000/var/lib/rpm", flags=289, mode=420) at ../../env/env_open.c:184
#4  0x006a6f98 in db_init (rpmdb=0x8635b40, rpmtag=0, dbip=0xbfb78fbc) at backend/db3.c:181
#5  db3open (rpmdb=0x8635b40, rpmtag=0, dbip=0xbfb78fbc) at backend/db3.c:620
#6  0x006addec in dbiOpen (db=0x8635b40, rpmtag=0, flags=0) at rpmdb.c:237
#7  0x006ae392 in openDatabase (prefix=0x863e590 "/vz/root/17000/", dbpath=<value optimized out>, _dbapi=3, dbp=0x86356c8, mode=0, perms=420, flags=0) at rpmdb.c:994
#8  0x006ae51b in rpmdbOpen (prefix=0x863e590 "/vz/root/17000/", dbp=0x86356c8, mode=0, perms=420) at rpmdb.c:1052
#9  0x006e201e in rpmtsOpenDB (ts=0x86356a0, dbmode=0) at rpmts.c:82
#10 0x006e2366 in rpmtsInitIterator (ts=0x86356a0, rpmtag=RPMTAG_NAME, keyp=0x6f32fe, keylen=0) at rpmts.c:150
#11 0x006e257a in loadKeyringFromDB (ts=0x86356a0) at rpmts.c:290
#12 loadKeyring (ts=0x86356a0) at rpmts.c:325
#13 0x006e234e in rpmtsInitIterator (ts=0x86356a0, rpmtag=0, keyp=0x0, keylen=0) at rpmts.c:148
#14 0x006d8c7f in rpmgiInitFilter (gi=0x8639878) at rpmgi.c:321
#15 rpmgiNext (gi=0x8639878) at rpmgi.c:472
#16 0x006ce035 in rpmgiShowMatches (qva=0x7085e0, ts=0x86356a0, arg=0x0) at query.c:272
#17 rpmQueryVerify (qva=0x7085e0, ts=0x86356a0, arg=0x0) at query.c:318
#18 0x006ce67e in rpmcliArgIterHelper (ts=0x86356a0, qva=0x7085e0, tag=0, argv=0x0, gFlgs=RPMGI_NONE) at query.c:547
#19 0x006ce908 in rpmcliQuery (ts=0x86356a0, qva=0x7085e0, argv=0x0) at query.c:614
#20 0x0804a4d2 in main (argc=6, argv=0xbfb7a504) at rpmqv.c:776
---

This caused by __db_file_extend() function from env/env_file.c which always return 0, even it fails in __os_write()

Here is the patch that fix it:

---
--- db-4.7.25/env/env_file.c.orig<----->2011-09-22 17:52:33.000000000 +0400
+++ db-4.7.25/env/env_file.c<-->2011-09-22 17:52:37.000000000 +0400
@@ -49,7 +49,7 @@
.
 err:<->__os_free(env, buf);
.
-<----->return (0);
+<----->return (ret);
 }
.
 /*
---

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

db4-4.7.25-16.el6

How reproducible:

100%

Steps to Reproduce:
1. Check that __db00* files are absent in /var/lib/rpm
2. Limit quota for root user so it is already exceeded
3. Try to list rpms installed
  
Actual results:

Coredump

Expected results:

Exit with appropriate error

Additional info:

The same BUG present in db4-4.8.30-3.fc15 in Fedora 15

Comment 2 Konstantin Volkov 2011-09-22 18:14:06 UTC
Created attachment 524457 [details]
Patch

Comment 3 RHEL Product and Program Management 2011-09-22 18:28:00 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unfortunately unable to
address this request at this time. Red Hat invites you to
ask your support representative to propose this request, if
appropriate and relevant, in the next release of Red Hat
Enterprise Linux. If you would like it considered as an
exception in the current release, please ask your support
representative.

Comment 4 RHEL Product and Program Management 2013-10-14 00:57:03 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unable to address this
request at this time.

Red Hat invites you to ask your support representative to
propose this request, if appropriate, in the next release of
Red Hat Enterprise Linux.

Comment 11 errata-xmlrpc 2017-03-21 09:31:23 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2017-0609.html


Note You need to log in before you can comment on or make changes to this bug.