potential arbitrary code execution in the srb volume driver

Bug #1414531 reported by gvb
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Low
Jordan Pittier
OpenStack Security Advisory
Won't Fix
Undecided
Unassigned

Bug Description

There's a potential arbitrary code execution in the srb volume driver in
cinder.

The offending code is below. At point #1 a value is being read which
comes from /etc/cinder/cinder.conf. If this value is set to something like `echo
hello > /tmp/test.txt` then one can achieve code execution at #2. Obviously it's
a defense in depth thing as one would need to have write access to
/etc/cinder/cinder.conf but it's strongly recommended to properly filter
out malicious shell characters to prevent any possibility of accidental or
malicious code execution.

/opt/stack/cinder/cinder/volume/drivers/srb.py

    def _setup_urls(self):
        if not self.base_urls:
            message = _("No url configured")
            raise exception.VolumeBackendAPIException(data=message)

        with handle_process_execution_error(
                message=_LE('Cound not setup urls on the Block
                Driver.'),
                info_message=_LI('Error creating Volume'),
                reraise=False):
            cmd = 'echo ' + self.base_urls + ' >
            /sys/class/srb/add_urls'
            putils.execute('sh', '-c', cmd,
                           root_helper='sudo', run_as_root=True) <---
                           #2
            self.urls_setup = True

    def do_setup(self, context):
        """Any initialization the volume driver does while starting."""
        self.backend_name =
        self.configuration.safe_get('volume_backend_name')

        base_urls = self.configuration.safe_get('srb_base_urls') <-- #1
        if base_urls:
            base_urls = ','.join(s.strip() for s in
            base_urls.split(','))

        self.base_urls = base_urls

        self._setup_urls()

To illustrate the issue consider the following:

>>> from oslo_concurrency import processutils as p
>>> bla = "`echo hello > /tmp/test.txt`"
>>> cmd = 'echo ' + bla + ' > /sys/class/srb/add_urls'
>>> cmd
'echo `echo hello > /tmp/test.txt` > /sys/class/srb/add_urls'
>>> p.execute("sh","-c",cmd)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
  "/usr/local/lib/python2.7/dist-packages/oslo_concurrency/processutils.py",
  line 224, in execute
    cmd=sanitized_cmd)
oslo_concurrency.processutils.ProcessExecutionError: Unexpected error
while running command.
Command: sh -c echo `echo hello > /tmp/test.txt` >
/sys/class/srb/add_urls
Exit code: 2
Stdout: u''
Stderr: u'sh: 1: cannot create /sys/class/srb/add_urls: Directory
nonexistent\n'
>>>

$ ls -l /tmp
total 8
-rw-r--r-- 1 stack stack 6 Jan 13 19:18 test.txt
drwx------ 2 stack stack 4096 Jan 13 19:19 vFg4zZS
$ cat /tmp/test.txt
hello

Revision history for this message
Tristan Cacqueray (tristan-cacqueray) wrote :

Since this report concerns a possible security risk, an incomplete security advisory task has been added while the core security reviewers for the affected project or projects confirm the bug and discuss the scope of any vulnerability along with potential solutions.

Changed in ossa:
status: New → Incomplete
Revision history for this message
Thierry Carrez (ttx) wrote :

The code this report refers to is pretty broken, so I suspect it's not working at all.

That putils.execute call ends up calling "sudo sh -c echo foo > bar", which:
1. won't work because I doubt anyone gave their cinder user sudoers rights to execute "sh"
2. would fail to achieve expected result because the ">" redirection would execute as the cinder user

Since this driver was added in kilo-1, this won't get an OSSA anyway, so I will mark the task as wontfix. I would suggest opening this report so that it gets quickly fixed.

Let me know if that works for you.

Revision history for this message
gvb (gvb-2) wrote :

Works for me; I've changed it to be a publicly available bug.

information type: Private Security → Public
Revision history for this message
Mike Perez (thingee) wrote :

Driver maintainer contacted.

tags: added: drivers scality
Changed in cinder:
milestone: none → kilo-2
Revision history for this message
Jordan Pittier (jordan-pittier) wrote :

We are currently working on this.

Revision history for this message
Mike Perez (thingee) wrote :

Jordan, feel free to set this in progress and the assignee please. Thanks!

Changed in cinder:
milestone: kilo-2 → kilo-3
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/152117

Changed in cinder:
assignee: nobody → Jordan Pittier (jordan-pittier)
status: New → In Progress
Revision history for this message
Tristan Cacqueray (tristan-cacqueray) wrote :

Marking the OSSA tasks as Won't fix since this driver is not released yet...

Changed in ossa:
status: Incomplete → Won't Fix
Mike Perez (thingee)
Changed in cinder:
importance: Undecided → Critical
importance: Critical → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/152117
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=114c84ae585c11c7e9492c96efa21570b6cd6b02
Submitter: Jenkins
Branch: master

commit 114c84ae585c11c7e9492c96efa21570b6cd6b02
Author: JordanP <email address hidden>
Date: Mon Feb 2 13:36:52 2015 +0000

    Fix Scality SRB driver security concerns

    LP #1414531 raised 2 issues :
    1)A potential arbitrary code execution if the Cinder Linux user
    has write access to /etc/cinder/cinder.conf
    2)An overall concern/question about the usage of the command
    'sudo sh -c' throughout the srb driver

    This patch fixes 1) with proper configuration validation and
    2) with usage of cinder-rootwrap.

    Closes-Bug: 1414531
    Change-Id: Idddb9633af3a45d65bbfa0146a14575e2984f6bd

Changed in cinder:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in cinder:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in cinder:
milestone: kilo-3 → 2015.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.