1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/libdm
Peter Rajnoha f94f8463b0 libdm: report: fix incorrect memory use while using --select with --unbuffered for reporting
Under certain circumstances, the selection code can segfault:

$ vgs --select 'pv_name=~/dev/sda' --unbuffered vg0
  VG   #PV #LV #SN Attr   VSize   VFree
  vg0    6   3   0 wz--n- 744.00m 588.00m
Segmentation fault (core dumped)

The problem here is the use of --ubuffered together with regex used in
selection criteria. If the report output is not buffered, each row is
discarded as soon as it is reported. The bug is in the use of report
handle's memory - in the example above, what happens is:

  1) report handle is initialized together with its memory pool

  2) selection tree is initialized from selection criteria string
     (using the report handle's memory pool!)

    2a) this also means the regex is initialized from report handle's mem pool

  3) the object (row) is reported

    3a) any memory needed for output is intialized out of report handle's mem pool
    3b) selection criteria matching is executed - if the regex is checked the
        very first time (for the very first row reported), some more memory
        allocation happens as regex allocates internal structures "on-demand",
        it's allocating from report handle's mem pool (see also step 2a)

  4) the report output is executed

  5) the object (row) is discarded, meaning discarding all the mem pool
     memory used since step 3.

Now, with step 5) we have discarded the regex internal structures from step 3b.
When we execute reporting for another object (row), we're using the same
selection criteria (step 3b), but tihs is second time we're using the regex
and as such, it's already initialized completely. But the regex is missing the
internal structures now as they got discarded in step 5) from previous
object (row) reporting (because we're using "unbuffered" reporting).

To resolve this issue and to prevent any similar future issues where each
object/row memory is discarded after output (the unbuffered reporting) while
selection tree is global for all the object/rows, use separate memory pool
for report's selection.

This patch replaces "struct selection_node *selection_root" in struct
dm_report with new struct selection which contains both "selection_root"
and "mem" for separate mem pool used for selection.

We can change struct dm_report this way as it is not exposed via libdevmapper.

(This patch will have even more meaning for upcoming patches where selection
is used even for non-reporting commands where "internal" reporting and
selection criteria matching happens and where the internal reporting is
not buffered.)
2014-12-09 10:41:55 +01:00
..
datastruct Use void pointer instead of char for binary key 2011-03-10 12:48:40 +00:00
ioctl libdm: init char array 2014-11-03 14:19:31 +01:00
misc libdm: Add DM_DEFERRED_REMOVE to dm-ioctl.h. 2014-08-15 13:45:55 +01:00
mm cleanup: indents comments backtraces 2014-11-10 22:05:49 +01:00
regex cleanup: add braces for if() 2014-07-02 10:45:43 +02:00
.exported_symbols dmsetup: Support remove --deferred. 2014-08-16 00:34:48 +01:00
libdevmapper.h libdm: report: compact output applicable only if report is buffered 2014-12-05 14:18:51 +01:00
libdevmapper.pc.in Switch to use Requires.private for devmapper.pc and lvm2app.pc 2010-05-11 08:54:11 +00:00
libdm-common.c libdm: revert incorrect path length size for sscanf 2014-08-29 13:10:18 +02:00
libdm-common.h libdm: introduce and use DEV_UUID macro 2012-10-10 17:16:15 +02:00
libdm-config.c cleanup: warning: declaration of 'remove' shadows a global declaration 2014-11-23 00:49:04 +01:00
libdm-deptree.c libdm: still better API 2014-11-11 00:54:03 +01:00
libdm-file.c Drop unreachable code 2012-02-08 12:59:45 +00:00
libdm-report.c libdm: report: fix incorrect memory use while using --select with --unbuffered for reporting 2014-12-09 10:41:55 +01:00
libdm-string.c cleanup: libdm simplier error comparation 2014-07-02 10:45:42 +02:00
Makefile.in libdm: Add missing UDEV_CFLAGS. 2014-04-01 15:26:26 +02:00