Bug 1943410 - CVE-2021-32492 djvulibre: Out of bounds read in function DJVU::DataPool::has_data() via crafted djvu file [fedora-all]
Summary: CVE-2021-32492 djvulibre: Out of bounds read in function DJVU::DataPool::has_...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: djvulibre
Version: 33
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Marek Kašík
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: CVE-2021-32492
TreeView+ depends on / blocked
 
Reported: 2021-03-26 02:06 UTC by 1vanChen
Modified: 2021-11-25 15:21 UTC (History)
1 user (show)

Fixed In Version: djvulibre-3.5.27-24.fc32 djvulibre-3.5.27-27.fc33
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-11-25 15:21:13 UTC
Type: Bug


Attachments (Terms of Use)
poc file (100 bytes, application/octet-stream)
2021-03-26 02:06 UTC, 1vanChen
no flags Details
Check input DataPool (528 bytes, patch)
2021-04-08 12:07 UTC, Marek Kašík
no flags Details | Diff

Description 1vanChen 2021-03-26 02:06:22 UTC
Created attachment 1766466 [details]
poc file

Out of bounds read in function `DJVU::DataPool::has_data` when input craft djvu file 



To Reproduce

```shell
./ddjvu ./poc.djvu
```

Debug Info

```shell
# ./ddjvu ./poc.djvu
==21493==ERROR: AddressSanitizer: SEGV on unknown address 0x0000000001b8 (pc 0x0000005bb4df bp 0x7fffffffd0d0 sp 0x7fffffffd0a0 T0)
==21493==The signal is caused by a READ memory access.
==21493==Hint: address points to the zero page.
    #0 0x5bb4df in DJVU::DataPool::has_data(int, int) /src/djvulibre-ddjvu/libdjvu/DataPool.cpp:1089:21
    #1 0x5b85de in DJVU::DataPool::connect(DJVU::GP<DJVU::DataPool> const&, int, int) /src/djvulibre-ddjvu/libdjvu/DataPool.cpp:883:14
    #2 0x5b82f6 in DJVU::DataPool::create(DJVU::GP<DJVU::DataPool> const&, int, int) /src/djvulibre-ddjvu/libdjvu/DataPool.cpp:797:10
    #3 0x6135ee in DJVU::DjVuFile::init(DJVU::GURL const&, DJVU::GP<DJVU::DjVuPort>) /src/djvulibre-ddjvu/libdjvu/DjVuFile.cpp:249:19
    #4 0x61313a in DJVU::DjVuFile::create(DJVU::GURL const&, DJVU::GP<DJVU::DjVuPort>, DJVU::DjVuPort::ErrorRecoveryAction, bool) /src/djvulibre-ddjvu/libdjvu/DjVuFile.cpp:216:9
    #5 0x5f828f in DJVU::DjVuDocument::url_to_file(DJVU::GURL const&, bool) const /src/djvulibre-ddjvu/libdjvu/DjVuDocument.cpp:891:12
    #6 0x5f89c4 in DJVU::DjVuDocument::get_djvu_file(int, bool) const /src/djvulibre-ddjvu/libdjvu/DjVuDocument.cpp:963:22
    #7 0x5fa911 in DJVU::DjVuDocument::get_page(int, bool, DJVU::DjVuPort*) const /src/djvulibre-ddjvu/libdjvu/DjVuDocument.cpp:1063:28
    #8 0x569f7a in DJVU::DjVuDocument::get_page(int, bool, DJVU::DjVuPort*) /src/djvulibre-ddjvu/libdjvu/./DjVuDocument.h:604:53
    #9 0x5363cd in ddjvu_page_create(DJVU::ddjvu_document_s*, DJVU::ddjvu_job_s*, char const*, int) /src/djvulibre-ddjvu/libdjvu/ddjvuapi.cpp:1580:23
    #10 0x4d33f6 in dopage(int) /src/djvulibre-ddjvu/tools/ddjvu.cpp:733:17
    #11 0x4d4717 in parse_pagespec(char const*, int, void (*)(int)) /src/djvulibre-ddjvu/tools/ddjvu.cpp:825:11
    #12 0x4df19b in main /src/djvulibre-ddjvu/tools/ddjvu.cpp:1214:3
    #13 0x7ffff651a83f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
    #14 0x41eff8 in _start (/mnt/disk/out/djvulibre-ddjvu/ddjvu_asan+0x41eff8)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /src/djvulibre-ddjvu/libdjvu/DataPool.cpp:1089:21 in DJVU::DataPool::has_data(int, int)
==21493==ABORTING
```



I think  unchecked variables pool is the root cause of this vulnerability

```c
GP<DataPool>
DataPool::create(const GP<DataPool> & pool, int start, int length)
{
  DEBUG_MSG("DataPool::DataPool: pool=" << (void *)((DataPool *)pool) << " start=" << start << " length= " << length << "\n");
  DEBUG_MAKE_INDENT(3);

  DataPool *xpool=new DataPool();
  GP<DataPool> retval=xpool;
  xpool->init();
  xpool->connect(pool, start, length);
                 ^^^^
  return retval;
}
```


Environment:

- version : djvulibre master (ee314b880c926e884be77d53ee459d9850c9c7f0)
- OS: Ubuntu 16.04
- clang version: 11


Credit: 1vanChen of NSFOCUS Security Team

Comment 1 Marek Kašík 2021-04-08 12:07:32 UTC
Created attachment 1770220 [details]
Check input DataPool

You are right, checking the input DataPool fixes this. I've added the check to the DataPool::create() method.

Comment 2 1vanChen 2021-04-11 12:57:11 UTC
(In reply to Marek Kašík from comment #1)
> Created attachment 1770220 [details]
> Check input DataPool
> 
> You are right, checking the input DataPool fixes this. I've added the check
> to the DataPool::create() method.

This patch looks great! I cannot reproduce this bug after applying this patch.

Comment 3 Ben Cotton 2021-11-04 14:03:01 UTC
This message is a reminder that Fedora 33 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 33 on 2021-11-30.
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 EOL if it remains open with a
Fedora 'version' of '33'.

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.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 33 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, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

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.

Comment 4 Ben Cotton 2021-11-04 14:32:14 UTC
This message is a reminder that Fedora 33 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 33 on 2021-11-30.
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 EOL if it remains open with a
Fedora 'version' of '33'.

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.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 33 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, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

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.

Comment 5 Ben Cotton 2021-11-04 15:29:56 UTC
This message is a reminder that Fedora 33 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 33 on 2021-11-30.
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 EOL if it remains open with a
Fedora 'version' of '33'.

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.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 33 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, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

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.

Comment 6 Marek Kašík 2021-11-25 15:21:13 UTC
This has been fixed quite some time ago (since Fedora 32).


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