Bug 433860

Summary: Daemons linked to libdevmapper segfault if they call dm_task_get_deps on task with no deps
Product: [Fedora] Fedora Reporter: Philip Spencer <pspencer>
Component: device-mapper-obsoleteAssignee: Alasdair Kergon <agk>
Status: CLOSED WONTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: low    
Version: 8CC: agk, bmarzins, dwysocha, mbroz, prockai
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-01-09 06:02:42 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Philip Spencer 2008-02-21 20:13:31 UTC
Description of problem:

rpc.mountd periodically segfaults, because it is linked to e2fsprogs libraries
which call dm_task_get_deps on a task with no info structure.

See bz#433857 filed against e2fsprogs.

However, even though it is probably the fault of e2fsprogs for not properly
checking first, the fact the device-mapper code is linked in to critical system
daemons (for which a segfault is unacceptable) means the device-mapper should be
fixed as well, to return gracefully instead of segfaulting in this situation.

The relevant code is in ioctl/libdm-iface.c line 950:

    return (struct dm_deps *) (((void *) dmt->dmi.v4) +
                                        dmt->dmi.v4->data_start);

This will cause a segfault if the dmi.v4 field of dmt is null.

Simply changing this to something like (note I have not actually applied and
compiled the following change, so please forgive any mistakes)

    return dmt && dmt->dmi.v4 ? (struct dm_deps *) (((void *) dmt->dmi.v4) +
                                        dmt->dmi.v4->data_start)
                  : (struct dm_deps *) 0;

should stop the segfaulting, leaving it up to the caller to deal with a null
return value. Similar changes to the other nearby routines in the code should
also make device-mapper libraries safer and less prone to segfaulting.

Version-Release number of selected component (if applicable):
device-mapper-libs-1.02.22-1.fc8

Comment 1 Alasdair Kergon 2008-02-21 20:52:23 UTC
I'll think about it.  Sometimes a fatal segfault is preferable to a silent
failure when the cause is a coding error.

Comment 2 Alasdair Kergon 2008-02-21 20:55:59 UTC
Could you quote the actual segment of e2fsprogs library code that caused this?

Comment 3 Alasdair Kergon 2008-02-21 21:08:11 UTC
Ah - found it in the other bug.

Yes, poorly-written code - hard to protect against that.  Easy to spot in a code
review though.  I'll comment on that bug.

        struct dm_info info;
        int i;

        task = dm_task_create(DM_DEVICE_DEPS);
        if (!task)
                return 0;

        dm_task_set_name(task, name);
        dm_task_run(task);
        dm_task_get_info(task, &info);

        if (!info.exists) {
                dm_task_destroy(task);
                return 0;
        }

        deps = dm_task_get_deps(task);



Comment 4 Philip Spencer 2008-02-21 21:15:34 UTC
One thing to notice, though, is that AFTER the fragment I quoted it does check
the return value from dm_task_get_deps:

        deps = dm_task_get_deps(task);
        if (!deps || deps->count == 0) {
                dm_task_destroy(task);
                return 0;
        }

So here is one case where if dm_task_get_deps had returned null instead of
segfaulting when passed a task without deps, the caller would have done the
right thing.

Comment 5 Bug Zapper 2008-11-26 09:54:24 UTC
This message is a reminder that Fedora 8 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 8.  It is Fedora's policy to close all
bug reports from releases that are no longer maintained.  At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '8'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 8's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 8 is end of life.  If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping

Comment 6 Bug Zapper 2009-01-09 06:02:42 UTC
Fedora 8 changed to end-of-life (EOL) status on 2009-01-07. Fedora 8 is 
no longer maintained, which means that it will not receive any further 
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of 
Fedora please feel free to reopen this bug against that version.

Thank you for reporting this bug and we are sorry it could not be fixed.