Bug 907434 (CVE-2014-9114) - VUL-0: CVE-2014-9114: util-linux: command injection flaw in blkid
Summary: VUL-0: CVE-2014-9114: util-linux: command injection flaw in blkid
Status: RESOLVED FIXED
Alias: CVE-2014-9114
Product: SUSE Security Incidents
Classification: Novell Products
Component: Incidents (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Deadline: 2014-12-12
Assignee: Security Team bot
QA Contact: Security Team bot
URL: https://smash.suse.de/issue/111072/
Whiteboard: maint:released:sle11-sp1:60707 maint...
Keywords:
Depends on:
Blocks: 961016
  Show dependency treegraph
 
Reported: 2014-11-27 08:29 UTC by Victor Pereira
Modified: 2016-01-07 16:18 UTC (History)
5 users (show)

See Also:
Found By: Security Response Team
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
blkid overflow patch (2.41 KB, patch)
2014-12-10 13:41 UTC, Sebastian Krahmer
Details | Diff
blkid overflow patch (2.41 KB, patch)
2014-12-15 13:47 UTC, Sebastian Krahmer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Victor Pereira 2014-11-27 08:29:51 UTC
Sebastian Krahmer reported a command injection flaw in blkid. This could possibly result in command execution with root privileges (for example, when running blkid on a malicious USB drive)



References:
http://www.openwall.com/lists/oss-security/2014/11/26/13
https://bugzilla.redhat.com/show_bug.cgi?id=1168485
Comment 1 Victor Pereira 2014-11-27 21:37:41 UTC
there is already a commit related with that https://github.com/karelzak/util-linux/commit/89e90ae7b2826110ea28c1c0eb8e7c56c3907bdc
Comment 2 Swamp Workflow Management 2014-11-27 23:00:14 UTC
bugbot adjusting priority
Comment 3 Swamp Workflow Management 2014-11-28 12:25:49 UTC
An update workflow for this issue was started.
This issue was rated as moderate.
Please submit fixed packages until 2014-12-12.
When done, reassign the bug to security-team@suse.de.
https://swamp.suse.de/webswamp/wf/59827
Comment 4 Sebastian Krahmer 2014-12-01 12:33:16 UTC
Please wait with the update. I am currently reviewing upstream
patches and it looks like there could be more that needs fixing.
Comment 5 Sebastian Krahmer 2014-12-03 10:11:33 UTC
Sent more patches to upstream, waiting for a reply from them.
Comment 6 Sebastian Krahmer 2014-12-10 13:41:11 UTC
Created attachment 616579 [details]
blkid overflow patch

My proposal sent upstream for the overflows.
Comment 7 Sebastian Krahmer 2014-12-15 13:47:00 UTC
Created attachment 617178 [details]
blkid overflow patch

New patch, fixing a twisted compare.
Comment 8 Sebastian Krahmer 2014-12-15 13:47:51 UTC
Thanks to upstream. There was a wrong compare. Everything should
be in place now. Please go ahead.
Comment 9 Stanislav Brabec 2014-12-17 22:43:07 UTC
openSUSE (12.3, 13.1, 13.2): Created OBS maintenance request 265631.

openSUSE:Factory: Not updated, I will wait for version 2.25.3.

SLE12: Created IBS maintenance request 47646.

SLE10 and SLE11: I am now going for vacation. I'll be back on January 2nd.

If you are in hurry, please re-assign it to somebody. The best start point would be 12.3, as it backports needed modifications of void safe_print().

If not in hurry, I'll backport these patches in January.


Please confirm that all 6 versions of util-linux are still supported and need update:

https://build.suse.de/project/show/home:sbrabec:branches:OBS_Maintained:util-linux-bsc907434
Comment 10 Marcus Meissner 2015-01-07 13:46:37 UTC
that url above is somehow broken.

I looked at home:sbrabec:branches:OBS_Maintained:util-linux-bsc907434

we do NOT need (EOLed in this version)
util-linux.SUSE_SLE-11_Update_Test

we MIGHT need for LTSS:
util-linux.SUSE_SLE-10-SP4_Update_Test and 
util-linux.SUSE_SLE-11-SP2_Update_Test

(Not sure if we want a LTSS update.)


The others (10-sp3, 11-sp1, 11-sp3) are definitely needed.
Comment 11 Stanislav Brabec 2015-01-08 19:14:03 UTC
URL again:

https://build.suse.de/project/show/home:sbrabec:branches:OBS_Maintained:util-linux-bsc907434

I finished backports to SUSE:SLE-11-SP3:Update:Test and SUSE:SLE-11-SP1:Update:Test. I am going to work on SUSE:SLE-10-SP3:Update:Test.

Backporting process is not trivial, so please let me know, which other repositories are requested.


Several features are not present in SUSE:SLE-11-SP1:Update:Test, so many hunks don't apply there. I believe that I did not lost any. Other parts are significantly different.

There is one specific think, that seems to have a different way to exploit and needs a different fix.

Here is the fix for Factory:

--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -103,6 +103,7 @@
 #include <inttypes.h>
 #include <stdint.h>
 #include <stdarg.h>
+#include <limits.h>
 
 #ifdef HAVE_LIBUUID
 # include <uuid.h>
@@ -578,6 +579,12 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr,
 			return NULL;
 		}
 
+		/* someone trying to overflow some buffers? */
+		if (len >= ULONG_MAX - sizeof(struct blkid_bufinfo)) {
+			errno = ENOMEM;
+			return NULL;
+		}
+
 		/* allocate info and space for data by why call */
 		bf = calloc(1, sizeof(struct blkid_bufinfo) + len);
 		if (!bf) {

Here is a proposed fix for a similar issue in SLE11 SP1. The place in the code is similar, the allocation purpose as well, but the way they allocate is different. I think that it could be exploited if off > 0 || len > 0 but off + len overflows and it is < 0.

Index: util-linux-ng-2.16/shlibs/blkid/src/probe.c
===================================================================
--- util-linux-ng-2.16.orig/shlibs/blkid/src/probe.c
+++ util-linux-ng-2.16/shlibs/blkid/src/probe.c
@@ -25,6 +25,7 @@
 #endif
 #include <stdint.h>
 #include <stdarg.h>
+#include <limits.h>
 
 #ifdef HAVE_LIBUUID
 # ifdef HAVE_UUID_UUID_H
@@ -207,7 +208,7 @@ unsigned char *blkid_probe_get_buffer(bl
 {
 	ssize_t ret_read = 0;
 
-	if (off < 0 || len < 0) {
+	if (off < 0 || len < 0 || off + len < 0) {
 		DBG(DEBUG_LOWPROBE,
 			printf("unexpected offset or length of buffer requested\n"));
 		return NULL;
Comment 12 Marcus Meissner 2015-01-09 12:40:55 UTC
I think the patch can go in that way.

the other overflow is not in blkid_probe_get_buffer()

Main topic of this bug is the command injection in
 util-linux-libblkid-unsafe-chars.patch


Can you backport this more easily to all the code streams?
Comment 13 Stanislav Brabec 2015-01-09 14:11:16 UTC
Trying URL again with escaping:
https://build.suse.de/project/show/home:sbrabec:branches:OBS_Maintained:util-linux-%62%73%63907434

Old versions of SLE (SLE11 SP1) don't have --export in blkid, so the chances to exploit them in scripts is significantly lower.

Very old SLE versions (SLE10) don't have blkid at all, but they have mount by ID.
Comment 14 Stanislav Brabec 2015-01-09 14:36:19 UTC
Should I backport fixes for SUSE:SLE-10-SP4:Update:Test and SUSE:SLE-11-SP2:Update:Test?


Regarding SLE10:

Hopefully, the code using blkid in SLE10 is dependent on external libblkid. And our packages are compiled without blkid support (at least in SLE10 SP3).

[   43s] You don't have blkid

Theere is only minor part of libblkid-like functionality without libblkid: mounting by name and UUID. As it is not exploitable by itself, I would stay away from backporting of parse_token() changes. These changes cannot be considered as fixes, they are just complementary changes to exploit-preventing save_quoted(). And these changes even cause minor change of behavior for volumes with " or \ in names.
Comment 15 Marcus Meissner 2015-01-09 15:58:33 UTC
so i think there is no need for SLES10 backports at all?


I would say leave out the LTSS updates for now (so NO backports for
SUSE:SLE-10-SP4:Update:Test and SUSE:SLE-11-SP2:Update:Test)
Comment 16 Stanislav Brabec 2015-01-09 16:29:45 UTC
I just finished my review of util-linux in SLE10 SP3.


Regarding unsafe characters in blkid:

As I say in comment 14, I believe that the code is not exploitable, as there is no machine readable output.


Regarding buffer allocation overflow:

The fix from libblkid/src/partitions/gpt.c:get_gpt_header() has a valid backport to util-linux-2.12r/partx/gpt.c:alloc_read_gpt_entries():
https://build.suse.de/package/view_file/home:sbrabec:branches:OBS_Maintained:util-linux-%62%73%63907434/util-linux.SUSE_SLE-10-SP3_Update_Test/util-linux-libblkid-overflow.patch?expand=1

I was trying to find the same exploit vector like libblkid/src/probe.c:blkid_probe_get_buffer()

The code is very different there. There is no similar call, all probers are handing needed buffers by itself.
I believe that the code implementing that functionality is here:
util-linux-2.12r/mount/mount_guess_fstype.c.

As far as I see, there is only one offset that can possibly overflow:
offset = 2048 * (toc[i]->cdte_addr.lba + 16);

Hopefully, there cannot happen anything worse than passing bad offset to lseek() and reading random chunk from CD ROM.

I found no other backport-able fixes.


I just submitted the fix to IBS. It depends on you whether you want to release the fix as a security update.
Comment 17 Stanislav Brabec 2015-01-09 17:59:44 UTC
Thinking about the upstream fix, I still see no way, how to safely parse blkid output in shell. According to the manual page, this should be done by -o export. But it is still dangerous:

PoC:

dd if=/dev/null of=test.img bs=1024 seek=65536
/sbin/mkfs.ext4 -L 'a uname' test.img

(/sbin/blkid -o export test.img ; echo 'echo "Label is $LABEL."') | sh

Expected output:
Label is a uname.

Current output:
Linux
Label is .
Comment 18 Stanislav Brabec 2015-01-09 19:28:42 UTC
Please ignore my last comment. I tested it with an unfixed blkid. The fix escapes spaces, so everything is OK, and the string does not need quotes.

-o export is first supported in SLE11 SP3, and not supported in SLE11 SP1.
Comment 19 Stanislav Brabec 2015-01-09 20:35:23 UTC
Submitted:
SLE10-SP3: Created IBS request id 48058.
SLE11-SP1: created IBS request id 48057.
SLE11-SP3: created IBS request id 48056.

Other versions were submitted in December or will not be submitted. Factory is still waiting for a new upstream version. If it will not appear in a month or so, I'll submit patches there as well.

Vulnerability matrix:

SLE10-SP3: blkid cache: N/A, blkid export: N/A, safe print: N/A, probe buffer: no, GPT table: yes

SLE11-SP1: blkid cache: N/A, blkid export: N/A, safe print: yes, probe buffer: different, GPT table: yes

SLE11-SP3: blkid cache: yes, blkid export: yes, safe print: yes, probe buffer: yes, GPT table: yes

SLE12: blkid cache: yes, blkid export: yes, safe print: yes, probe buffer: yes, GPT table: yes
Comment 22 Swamp Workflow Management 2015-01-16 10:05:04 UTC
openSUSE-SU-2015:0066-1: An update that fixes one vulnerability is now available.

Category: security (moderate)
Bug References: 907434
CVE References: CVE-2014-9114
Sources used:
openSUSE 13.2 (src):    python-libmount-2.25.1-9.2, util-linux-2.25.1-9.1, util-linux-systemd-2.25.1-9.1
openSUSE 13.1 (src):    util-linux-2.23.2-24.1
Comment 25 Stanislav Brabec 2015-02-04 19:44:11 UTC
Checked in for SLE11 SP1, SLE11 SP3 and SLE10 SP3.

As ther is no new upstream stable version with a fix yet, I backported it for Factory as well. Submitted as OBS request id 284107.

From my side everything is done.

Feel free to close the bug.
Comment 26 Bernhard Wiedemann 2015-02-04 20:00:07 UTC
This is an autogenerated message for OBS integration:
This bug (907434) was mentioned in
https://build.opensuse.org/request/show/284107 Factory / util-linux
Comment 27 Swamp Workflow Management 2015-02-12 14:05:04 UTC
SUSE-SU-2015:0270-1: An update that solves one vulnerability and has one errata is now available.

Category: security (moderate)
Bug References: 907434,908742
CVE References: CVE-2014-9114
Sources used:
SUSE Linux Enterprise Workstation Extension 12 (src):    util-linux-2.25-10.1
SUSE Linux Enterprise Software Development Kit 12 (src):    util-linux-2.25-10.1
SUSE Linux Enterprise Server 12 (src):    python-libmount-2.25-10.3, util-linux-2.25-10.1, util-linux-systemd-2.25-10.1
SUSE Linux Enterprise Desktop 12 (src):    python-libmount-2.25-10.3, util-linux-2.25-10.1, util-linux-systemd-2.25-10.1
Comment 28 Bernhard Wiedemann 2015-02-12 16:00:09 UTC
This is an autogenerated message for OBS integration:
This bug (907434) was mentioned in
https://build.opensuse.org/request/show/285827 Factory / util-linux
Comment 29 Bernhard Wiedemann 2015-02-12 17:00:14 UTC
This is an autogenerated message for OBS integration:
This bug (907434) was mentioned in
https://build.opensuse.org/request/show/285829 Factory / util-linux
Comment 31 Swamp Workflow Management 2015-03-24 05:05:40 UTC
SUSE-SU-2015:0580-1: An update that solves one vulnerability and has 5 fixes is now available.

Category: security (moderate)
Bug References: 888678,900965,901549,907434,917164,918041
CVE References: CVE-2014-9114
Sources used:
SUSE Linux Enterprise Software Development Kit 11 SP3 (src):    util-linux-2.19.1-6.62.1
SUSE Linux Enterprise Server 11 SP3 for VMware (src):    util-linux-2.19.1-6.62.1
SUSE Linux Enterprise Server 11 SP3 (src):    util-linux-2.19.1-6.62.1
SUSE Linux Enterprise Desktop 11 SP3 (src):    util-linux-2.19.1-6.62.1
Comment 32 Marcus Meissner 2015-03-24 09:54:56 UTC
main distros released