RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1041576 - Due to lack of CAP_DAC_OVERRIDE, pluto cannot write to directories not owned by root
Summary: Due to lack of CAP_DAC_OVERRIDE, pluto cannot write to directories not owned ...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: openswan
Version: 6.5
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: ---
Assignee: Paul Wouters
QA Contact: Jaroslav Aster
URL:
Whiteboard:
Depends On:
Blocks: 1039346 1090614 1092047 1122942
TreeView+ depends on / blocked
 
Reported: 2013-12-12 17:54 UTC by Terry Wilson
Modified: 2016-05-16 14:03 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
openswan dropped various privileges that prevented it from reading configuration files in directories not owned by root.
Clone Of:
: 1092047 (view as bug list)
Environment:
Last Closed: 2014-10-14 08:19:07 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Keep CAP_DAC_OVERRIDE only when necessary (2.29 KB, patch)
2014-03-25 22:23 UTC, Terry Wilson
no flags Details | Diff
patch to move CAP_DAC_OVERRIDE drop after we create the socket (1.92 KB, patch)
2014-03-26 04:14 UTC, Paul Wouters
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2014:1588 0 normal SHIPPED_LIVE openswan bug fix and enhancement update 2014-10-14 01:39:53 UTC

Description Terry Wilson 2013-12-12 17:54:59 UTC
Description of problem:

The neutron-vpn-agent in OpenStack attempts to run:

ipsec pluto --ctlbase /var/lib/neutron/ipsec/be47e2c7-2ee1-4e77-bcfb-a21769de5118/var/run/pluto --ipsecdir /var/lib/neutron/ipsec/be47e2c7-2ee1-4e77-bcfb-a21769de5118/etc --use-netkey --uniqueids --nat_traversal --secretsfile /var/lib/neutron/ipsec/be47e2c7-2ee1-4e77-bcfb-a21769de5118/etc/ipsec.secrets --virtual_private %v4:172.24.4.224/28,%v4:10.0.0.2/

The /var/lib/neutron/... directories are all owned neutron:neutron 0755. Since pluto sets its capabilities in programs/pluto/plutomain.c without including CAP_DAC_OVERRIDE, it fails with:

pluto: unable to create lock dir: "/var/lib/neutron/ipsec/be47e2c7-2ee1-4e77-bcfb-a21769de5118/var/run/pluto": Permission denied


Version-Release number of selected component (if applicable):

openswan-2.6.32-27.el6.x86_64


How reproducible:
make a non-root-owned directory and pass it in as --ctlbase


Actual results:

pluto fails to run with the above error

Expected results:

pluto runs successfully

Comment 2 Terry Wilson 2013-12-12 21:39:20 UTC
I can verify that rebuilding openswan with the following patch:

--- programs/pluto/plutomain.c.old  2013-12-12 15:06:52.182664449 -0600
+++ programs/pluto/plutomain.c  2013-12-12 15:08:01.229676601 -0600
@@ -359,7 +359,7 @@
    capng_clear(CAPNG_SELECT_BOTH);
    capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
            CAP_NET_BIND_SERVICE, CAP_NET_ADMIN, CAP_NET_RAW,
-           CAP_IPC_LOCK, -1);
+           CAP_IPC_LOCK, CAP_DAC_OVERRIDE, -1);
    /* our children must be able to CAP_NET_ADMIN to change routes.
     */
    capng_updatev(CAPNG_ADD, CAPNG_BOUNDING_SET,

does fix the problem for neutron-vpn-agent using openswan.

Comment 3 Paul Wouters 2013-12-13 17:42:45 UTC
Terry, can you try using groups and giving it a group write? We are strongly encouraged not to remove CAP_DAC_OVERRIDE. That is, put root in the neutron group and make directory g+w

Comment 4 Terry Wilson 2013-12-13 18:22:50 UTC
We can hack around it, but that's what it'll be: a hack. Since the directories are created at runtime each time a particular vpn service object is created, it would mean editing the code in neutron to just assume that root happens to be in the neutron group or editing the code to do setfacl every time a directory is created, etc. It certainly doesn't seem like the type of patch that they'd accept upstream.

It seems like if one is 1) running a service as root and 2) passing in a directory that needs to be written to owned by 'not root', the admin intention is pretty clear. Just my $0.02, of course. Any chance of detecting that particular case and only enabling CAP_DAC_OVERRIDE then? Or even just enabling it just long enough to create the necessary directories/files, then disabling again?

Comment 5 Terry Wilson 2014-03-25 22:23:19 UTC
Created attachment 878708 [details]
Keep CAP_DAC_OVERRIDE only when necessary

This patch, instead of unconditionally keeping CAP_DAC_OVERRIDE, instead checks the parent directory of ctlbase for RWX owner/gid perms if running as root and keeps CAP_DAC_OVERRIDE if root is passing in a ctlbase that it wouldn't be able to access after dropping the capability. In this way, only when it is absolutely necessary and obviously the intention of the user running pluto is this capability retained.

As a note, in most normal circumstances I'd never check permissions then try an operation, but as you can't restore capabilities that you've given up and you would need the capability removed to be able to test via creation, I go ahead and do the check. Also, I would have used euidaccess() instead of manually checking the uid/gid permissions, but access/euidaccess code in to return 0 if uid/euid == 0.

Comment 6 Paul Wouters 2014-03-26 04:14:53 UTC
Created attachment 878844 [details]
patch to move CAP_DAC_OVERRIDE drop after we create the socket

Can you try the attached patch - It works for me, although due to the missing permissions during shutdown, you will have to remove the parent directory so the pid file and socket get cleaned up properly, as we have lost the capability to clean those up if the parent dir is non-root

Comment 7 Terry Wilson 2014-03-31 18:28:42 UTC
The attached patch didn't quite work, but pwouters did another build moving the privilege drop even later that seems to work: https://brewweb.devel.redhat.com/taskinfo?taskID=7275538.

With the patch, pluto now starts without error. When deleting the ipsec site connection via neutron, the /var/lib/neutron/ipsec/${id} directory is successfully deleted as well.

Comment 13 Paul Wouters 2014-06-23 04:42:00 UTC
yes: https://bugzilla.redhat.com/show_bug.cgi?id=1092047

Comment 18 Paul Wouters 2014-09-29 16:27:20 UTC
shouldn't this bug be closed by now?

Comment 19 Karel Srot 2014-09-29 18:31:00 UTC
It will be closed by the rhel-6.6 release

Comment 20 errata-xmlrpc 2014-10-14 08:19:07 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2014-1588.html


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