CVE-2018-20346 - Integer Overflow or Wraparound

Severity

68%

Complexity

86%

Confidentiality

106%

SQLite before 3.25.3, when the FTS3 extension is enabled, encounters an integer overflow (and resultant buffer overflow) for FTS3 queries that occur after crafted changes to FTS3 shadow tables, allowing remote attackers to execute arbitrary code by leveraging the ability to run arbitrary SQL statements (such as in certain WebSQL use cases), aka Magellan.

SQLite before 3.25.3, when the FTS3 extension is enabled, encounters an integer overflow (and resultant buffer overflow) for FTS3 queries that occur after crafted changes to FTS3 shadow tables, allowing remote attackers to execute arbitrary code by leveraging the ability to run arbitrary SQL statements (such as in certain WebSQL use cases), aka Magellan.

CVSS 3.0 Base Score 8.1. CVSS Attack Vector: network. CVSS Attack Complexity: high. CVSS Vector: (CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H).

CVSS 2.0 Base Score 6.8. CVSS Attack Vector: network. CVSS Attack Complexity: medium. CVSS Vector: (AV:N/AC:M/Au:N/C:P/I:P/A:P).

Demo Examples

Integer Overflow or Wraparound

CWE-190

The following image processing code allocates a table for images.


               
...

This code intends to allocate a table of size num_imgs, however as num_imgs grows large, the calculation determining the size of the list will eventually overflow (CWE-190). This will result in a very small list to be allocated instead. If the subsequent code operates on the list as if it were num_imgs long, it may result in many types of out-of-bounds problems (CWE-119).

Integer Overflow or Wraparound

CWE-190

The following code excerpt from OpenSSH 3.3 demonstrates a classic case of integer overflow:


               
}
for (i = 0; i < nresp; i++) response[i] = packet_get_string(NULL);

If nresp has the value 1073741824 and sizeof(char*) has its typical value of 4, then the result of the operation nresp*sizeof(char*) overflows, and the argument to xmalloc() will be 0. Most malloc() implementations will happily allocate a 0-byte buffer, causing the subsequent loop iterations to overflow the heap buffer response.

Integer Overflow or Wraparound

CWE-190

Integer overflows can be complicated and difficult to detect. The following example is an attempt to show how an integer overflow may lead to undefined looping behavior:


               
}
bytesRec += getFromInput(buf+bytesRec);

In the above case, it is entirely possible that bytesRec may overflow, continuously creating a lower number than MAXGET and also overwriting the first MAXGET-1 bytes of buf.

Integer Overflow or Wraparound

CWE-190

In this example the method determineFirstQuarterRevenue is used to determine the first quarter revenue for an accounting/business application. The method retrieves the monthly sales totals for the first three months of the year, calculates the first quarter sales totals from the monthly sales totals, calculates the first quarter revenue based on the first quarter sales, and finally saves the first quarter revenue results to the database.


               
}
return 0;// Variable for sales revenue for the quarter// Calculate quarterly total// Calculate the total revenue for the quarter

However, in this example the primitive type short int is used for both the monthly and the quarterly sales variables. In C the short int primitive type has a maximum value of 32768. This creates a potential integer overflow if the value for the three monthly sales adds up to more than the maximum value for the short int primitive type. An integer overflow can lead to data corruption, unexpected behavior, infinite loops and system crashes. To correct the situation the appropriate primitive type should be used, as in the example below, and/or provide some validation mechanism to ensure that the maximum value for the primitive type is not exceeded.


               
}
...// Calculate quarterly total// Calculate the total revenue for the quarter

Note that an integer overflow could also occur if the quarterSold variable has a primitive type long but the method calculateRevenueForQuarter has a parameter of type short.

Overview

First reported 6 years ago

2018-12-21 21:29:00

Last updated 5 years ago

2019-12-19 20:15:00

Affected Software

Red Hat Linux 6.0

6.0

Debian Linux 8.0 (Jessie)

8.0

openSUSE Leap 15.0

15.0

openSUSE Leap 42.3

42.3

References

openSUSE-SU-2019:1159

Third Party Advisory

openSUSE-SU-2019:1222

Mailing List, Third Party Advisory

106323

Third Party Advisory, VDB Entry

https://access.redhat.com/articles/3758321

Third Party Advisory

https://blade.tencent.com/magellan/index_en.html

Third Party Advisory

https://bugzilla.redhat.com/show_bug.cgi?id=1659379

Issue Tracking, Third Party Advisory

https://bugzilla.redhat.com/show_bug.cgi?id=1659677

Issue Tracking, Third Party Advisory

https://chromereleases.googleblog.com/2018/12/stable-channel-update-for-desktop.html

Third Party Advisory

https://chromium.googlesource.com/chromium/src/+/c368e30ae55600a1c3c9cb1710a54f9c55de786e

Third Party Advisory

https://crbug.com/900910

Permissions Required, Third Party Advisory

https://github.com/zhuowei/worthdoingbadly.com/blob/master/_posts/2018-12-14-sqlitebug.html

Exploit, Third Party Advisory

[debian-lts-announce] 20181222 [SECURITY] [DLA 1613-1] sqlite3 security update

Mailing List, Third Party Advisory

FEDORA-2019-49f80a78bc

https://news.ycombinator.com/item?id=18685296

Third Party Advisory

GLSA-201904-21

Third Party Advisory

https://sqlite.org/src/info/940f2adc8541a838

Patch, Third Party Advisory

https://sqlite.org/src/info/d44318f59044162e

Patch, Third Party Advisory

https://support.apple.com/HT209443

https://support.apple.com/HT209446

https://support.apple.com/HT209447

https://support.apple.com/HT209448

https://support.apple.com/HT209450

https://support.apple.com/HT209451

USN-4019-1

USN-4019-2

https://worthdoingbadly.com/sqlitebug/

Exploit, Third Party Advisory

FreeBSD-EN-19:03

Third Party Advisory

https://www.mail-archive.com/[email protected]/msg113218.html

Mailing List, Third Party Advisory

N/A

https://www.sqlite.org/releaselog/3_25_3.html

Release Notes, Vendor Advisory

https://www.synology.com/security/advisory/Synology_SA_18_61

Third Party Advisory

Stay updated

ExploitPedia is constantly evolving. Sign up to receive a notification when we release additional functionality.

Get in touch

If you'd like to report a bug or have any suggestions for improvements then please do get in touch with us using this form. We will get back to you as soon as we can.