[security] please use apparmor to restrict access to ofono to approved services

Bug #1296415 reported by Antti Kaijanmäki
22
This bug affects 2 people
Affects Status Importance Assigned to Milestone
indicator-network (Ubuntu)
Triaged
Wishlist
Unassigned
Utopic
Won't Fix
Wishlist
Unassigned
isc-dhcp (Ubuntu)
Fix Released
Undecided
Jamie Strandboge
Utopic
Fix Released
Undecided
Jamie Strandboge
network-manager (Ubuntu)
Triaged
Wishlist
Unassigned
Utopic
Won't Fix
Wishlist
Unassigned
nuntium (Ubuntu)
Triaged
Wishlist
Unassigned
Utopic
Won't Fix
Wishlist
Unassigned
ofono (Ubuntu)
Triaged
Wishlist
Unassigned
Utopic
Won't Fix
Wishlist
Unassigned
powerd (Ubuntu)
Triaged
Wishlist
Unassigned
Utopic
Won't Fix
Wishlist
Unassigned
ubuntu-download-manager (Ubuntu)
Triaged
Wishlist
Unassigned
Utopic
Won't Fix
Wishlist
Unassigned
ubuntu-system-settings (Ubuntu)
Triaged
Wishlist
Unassigned
Utopic
Won't Fix
Wishlist
Unassigned
urfkill (Ubuntu)
Triaged
Wishlist
Unassigned
Utopic
Won't Fix
Wishlist
Unassigned

Bug Description

NOTE: After further review from the security team, unfortunately what is presented as a solution in this bug is not sufficient to block unconfined processes from connecting to ofono for essentially two reasons:

 a) anything that is unconfined can change into another profile, so an unconfined process can simply change into the profile of one of the allowed services, and
 b) this doesn't protect against scenarios where the user is able to alter the behavior of the allowed services running in the user session (eg, indicator-network and ubuntu-system-settings)

'a' is solvable by making sure that the user's session starts under a new AppArmor "user-session" profile that prevents changing profile in to one of the allowed services (of course, the user session services continue to run under their own profiles). We'd have to investigate the best method for profile attachment in this case as well. An alternative might be to store the profile attachment in the inode of the binary when AppArmor adds this.

'b' is perhaps solvable by more strictly confining these allowed user session services (eg, 'audit deny ptrace tracedby peer=user-session, audit deny owner /** m, preventing QML loading, future AppArmor environment filtering, etc') along with, importantly, hardening these services to the point that they can't be controlled via environment, configuration, library loading, etc, etc. An alternative solution would be to run these services as another user in such a way that the user cannot alter their behavior beyond what is exposed in the UI.

Preventing unconfined from doing things is a difficult prospect and while I think with the recent improvements with AppArmor over the last two cycles finally makes the notion plausible, significant work remains to solve 'a' and 'b'. This is cannot be achieved for RTM (note, this only affected limiting unconfined and has no effect on application isolation, which is in full effect and does not suffer from this at all).

Description:
It would be useful to limit the services that can connect to ofonod over DBus. We can implement this be creating an otherwise permissive AppArmor profile for ofonod that will limit any DBus calls to ofonod to a list of peer profiles (specifically excluding 'unconfined'). The list of peer profiles is:
 - indicator-network
 - network-manager (and dispatcher.d/03mmsproxy)
 - nuntium
 - telepathy-ofono
 - ofono-scripts
 - powerd
 - ubuntu-download-manager
 - system-settings
 - urfkill

Each of the above needs to have a profile created for it, adjusting the boot scripts as necessary to ensure that the profile is loaded before the service starts. The peer profile implementation will be wide open as the purpose of the profile is (currently) to simply ensure the process of the service has the correct AppArmor labeling (though this opens the possibility to confine these services down the road if desired).

Merge requests have been requested for everything except urfkill, which has a debdiff attached to this bug. As mentioned, the AppArmor profiles for everything except ofonod is wide open so the risk of regression is very low for these. In fact, if it is helpful, everything except ofono could be uploaded to the archive independently and at any time.

For ofono, as mentioned, the AppArmor profile is also lenient except for the policy for its DBus interface. It is critical that ofono is updated at the same time or after all the other packages in this bug, otherwise any packages that aren't updated will fail to connect to ofono.

I've been running this configuration on my phone for weeks with no denials (excepting 03mmsproxy which I adjusted for yesterday). I've tested the packaging on x86 emulator to make sure that the profiles are installed and loaded properly on boot.

Test Plan (additional to any existing appropriate test plans)
 1. Install all services on a device
 2. reboot (important to restart the session and any services that aren't
    restarted automatically, like nuntium. reboot is easiest). Note the time
    of the reboot on the device
 3. in addition to any applicable test plans, after full boot:
    adb shell grep DEN /var/log/syslog # there should be no denials for
                                       # ofono after the system boots (there
                                       # likely will be denials during
                                       # upgrade)
    adb shell tail -f /var/log/syslog | grep DEN # run this during all tests
 4. make a call
 5. send a text
 6. send an mms (if possible)
 7. connect to wifi
 8. connect to 3G
 9. download an app
 10. toggle wifi in system-settings
 11. verify ofono-scripts (eg, /usr/share/ofono/scripts/list-modems and
     /usr/share/ofono/scripts/online-modem
 12. double check `adb shell grep DEN /var/log/syslog` for no ofono denials
     during the testing

= Original text =
We should try to find ways to restrict certain properties and interfaces to well known callers, for example Modem 'Online' should be settable by urfkill only. We don't want to allow other processes to set these properties. This would also help to identify if some unintended process is trying to set such properties by accident.

Related branches

Tony Espy (awe)
Changed in ofono (Ubuntu):
assignee: nobody → Tony Espy (awe)
status: New → Confirmed
importance: Undecided → High
Changed in indicator-network (Ubuntu):
assignee: nobody → Jamie Strandboge (jdstrand)
Changed in network-manager (Ubuntu):
assignee: nobody → Jamie Strandboge (jdstrand)
Changed in powerd (Ubuntu):
assignee: nobody → Jamie Strandboge (jdstrand)
Changed in urfkill (Ubuntu):
assignee: nobody → Jamie Strandboge (jdstrand)
Changed in ofono (Ubuntu):
assignee: Tony Espy (awe) → Jamie Strandboge (jdstrand)
summary: - [security] setting "dangerous" properties such as [service].Modem
- 'Powered' and 'Online' should be restricted.
+ [security] please use apparmor to restrict access to ofono to approved
+ software
summary: [security] please use apparmor to restrict access to ofono to approved
- software
+ services
Revision history for this message
Tony Espy (awe) wrote :

After discussion with Jamie, I think we merely want to restrict ofono usage to a particular set of system processes.

AppArmor is not capable of restricting individual properties, and unfortunately "Online" is a property of the top-level org.ofono.Modem interface which we really can't restrict to just urfkill.

Our current plan of record is that we will provide basic unrestrictive AppArmor profiles to the following system/session processes:

- NetworkManager
- telepathy-ofono ( or related telepathy process/component )
- urfkill
- indicator-network
- nuntium ( MMS daemon )
- powerd

Revision history for this message
Tony Espy (awe) wrote :

We also need some further investigation as the following components *may* also need access:

- ubuntu-download-manager
- greeter

Revision history for this message
Michael Terry (mterry) wrote :

The greeter code itself probably doesn't need its own access to ofono, but if you are basing any checks on which user is running, please remember that telepathy-ofono and friends run as the 'lightdm' user inside a greeter session.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Looks like rild will also need a profile. Furthermore, we need to create the symlinks in /etc/apparmor/init/network-interface-security to make sure these things are coming up confined.

Changed in ubuntu-system-settings (Ubuntu):
assignee: nobody → Jamie Strandboge (jdstrand)
Changed in nuntium (Ubuntu):
assignee: nobody → Jamie Strandboge (jdstrand)
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

I think I was wrong about rild and was hitting another issue.

I seem to have this all working locally by creating profiles for:
  usr.bin.nuntium
  usr.bin.powerd
  usr.bin.system-settings
  usr.lib.indicator-network-service
  usr.lib.urfkilld
  usr.sbin.NetworkManager
  usr.sbin.ofonod

then adjusting these upstart jobs to load the profile prior to launch (I may end up adjusting all the upstart jobs to be sure):
  ofono.conf
  powerd.conf
  urfkill.conf

To demonstrate what this looks like, the ofonod profile has:
# Permissive profile limit dbus access
/usr/sbin/ofonod (attach_disconnected) {
...

  # We can do anything on dbus
  dbus (bind, send),

  # Some methods are ok by anyone (ie, dbus-daemon itself)
  dbus (receive)
       bus=system
       interface="org.freedesktop.DBus.Properties",

  # Limit who can connect on DBus to processes with these apparmor labels (LP: #1296415)
  dbus (receive) peer=(label=/usr/lib/*/indicator-network/indicator-network-service),
  dbus (receive) peer=(label=/usr/sbin/NetworkManager),
  dbus (receive) peer=(label=/usr/bin/nuntium),
  dbus (receive) peer=(label=/usr/bin/powerd),
  dbus (receive) peer=(label=/usr/bin/system-settings),
  dbus (receive) peer=(label=/usr/lib/*/urfkill/urfkilld),
  dbus (receive) peer=(label=/usr/lib/telepathy/telepathy-ofono),
  dbus (receive) peer=(label=ofono_scripts),
...
}

profile ofono_scripts /usr/share/ofono/scripts/* (attach_disconnected) {
  capability,
  mount,
  remount,
  umount,
  network,
  dbus,
  ptrace,
  signal,

  / rwkl,
  /** rwlkmix,
}

All of the peers have permissive profiles ala the 'ofono_scripts' policy above. Each then gets an apparmor label for it, and the ofonod apparmor policy allows connections from only those labels (not even unconfined can connect). Light testing shows that 'list-modems' and 'online-modem' from /usr/share/ofono/scripts work fine and on reboot the phone comes up and connects to 3G and generally seems to work ok. indicator-network and settings all work correctly when switching back and forth between wifi and 3g). Toggling cellular data works.

I did notice that ubuntu-download-manager gets a denial:
Jun 4 10:19:42 ubuntu-phablet dbus[756]: apparmor="DENIED" operation="dbus_method_call" bus="system" path="/" interface="org.ofono.Manager" member="GetModems" name=":1.77" mask="receive" pid=1350 profile="/usr/sbin/ofonod" peer_pid=4086 peer_profile="unconfined"
Jun 4 10:19:42 ubuntu-phablet dbus[756]: message repeated 16 times: [ apparmor="DENIED" operation="dbus_method_call" bus="system" path="/" interface="org.ofono.Manager" member="GetModems" name=":1.77" mask="receive" pid=1350 profile="/usr/sbin/ofonod" peer_pid=4086 peer_profile="unconfined"]

# ps auxww|grep 4086
root 4086 2.0 0.4 65996 7776 ? Sl 10:19 0:00 /usr/bin/ubuntu-download-manager

Should ubuntu-download-manager be added to the list?

Changed in indicator-network (Ubuntu):
status: New → In Progress
Changed in network-manager (Ubuntu):
status: New → In Progress
Changed in nuntium (Ubuntu):
status: New → In Progress
Changed in ofono (Ubuntu):
status: Confirmed → In Progress
Changed in powerd (Ubuntu):
status: New → In Progress
Changed in ubuntu-system-settings (Ubuntu):
status: New → In Progress
Changed in urfkill (Ubuntu):
status: New → In Progress
tags: added: apparmor application-confinement rtm14
Revision history for this message
Tony Espy (awe) wrote :

I just added a task for ubuntu-download-manager. Nice catch. Please let me know when you're ready for some more hands-on testing.

Changed in ubuntu-download-manager (Ubuntu):
assignee: nobody → Jamie Strandboge (jdstrand)
status: New → Triaged
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

So, I have things working locally, but there is a problem in that a race condition is being hit (LP: #1305108) where telepathy-ofono is launching before their profile is loaded, which breaks the dialer (since the process is running under the 'unconfined' label which isn't allowed to talk to ofono). Basically, I think we need bug #1305108 fixed before we can proceed with this.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

AppArmor packages are in https://launchpad.net/~ubuntu-security-proposed/+archive/ppa/+packages to unblock this bug. I'm testing local modifications for this bug with those packages now and everything works well. We will be requesting a silo for the apparmor packages on monday. As such, I will be preparing MRs for this bug then.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

FYI, /etc/NetworkManager/dispatcher.d/03mmsproxy also needs to talk to ofono. This is actually called by /usr/lib/NetworkManager/nm-dispatcher.action as opposed to /usr/sbin/NetworkManager and /etc/NetworkManager/dispatcher.d/03mmsproxy is shipped by lxc-android-config. This isn't a problem, but I think I'd prefer to keep that policy in with the network manager packaging rather than shipping an apparmor profile in lxc-android-config.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

I'll be attaching debdiffs for review and also proposing merge requests.

Changed in ubuntu-download-manager (Ubuntu):
status: Triaged → In Progress
tags: added: patch
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Ok, at this point I am handing off to Phonedations to perform the landing. I've updated the description for testing, risk, implementation, etc and I believe everything is in place and am of course available for questions.

description: updated
description: updated
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Ok, I made a small change to the policy in the MRs so I deleted the debdiffs since they aren't that useful now that I linked the MRs to this bug. Attached is an updated debdiff for urfkill.

Changed in isc-dhcp (Ubuntu Utopic):
assignee: nobody → Jamie Strandboge (jdstrand)
status: New → In Progress
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Adding an isc-dhcp task. It doesn't need to talk to ofono, but dhclient is confined and the dhclient profile needs to allow receiving signals and ptrace reads by /usr/sbin/NetworkManager.

Changed in isc-dhcp (Ubuntu Utopic):
status: In Progress → Fix Committed
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

indicator-network-autopilot needs to talk to ofono directly.
inside lp:indicator-network tree see tests/autopilot/indicator_network/helpers/phonesim_manager.py

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package isc-dhcp - 4.2.4-7ubuntu13

---------------
isc-dhcp (4.2.4-7ubuntu13) utopic; urgency=medium

  * apparmor-profile.dhclient: allow signal receive and ptrace readby by
    peer=/usr/sbin/NetworkManager to dhclient and nm-dhcp-client.action
    (LP: #1296415)
 -- Jamie Strandboge <email address hidden> Wed, 25 Jun 2014 07:05:47 -0500

Changed in isc-dhcp (Ubuntu Utopic):
status: Fix Committed → Fix Released
description: updated
description: updated
description: updated
Revision history for this message
Tony Espy (awe) wrote :

Removed the "rtm14" tag based on Jamie's NOTE in the bug description.

tags: removed: rtm14
Revision history for this message
Tony Espy (awe) wrote :

Bumped Importance to WishList as it's clear this will not be fixed for RTM.

Changed in ofono (Ubuntu Utopic):
importance: High → Wishlist
Changed in indicator-network (Ubuntu Utopic):
status: In Progress → Won't Fix
Changed in network-manager (Ubuntu Utopic):
status: In Progress → Won't Fix
Changed in nuntium (Ubuntu Utopic):
status: In Progress → Won't Fix
Changed in ofono (Ubuntu Utopic):
status: In Progress → Won't Fix
Changed in powerd (Ubuntu Utopic):
status: In Progress → Won't Fix
Changed in ubuntu-download-manager (Ubuntu Utopic):
status: In Progress → Won't Fix
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Adjusted the bug statuses based on the updated description. This is "Won't Fix" for Utopic ("Triaged" when "V" opens).

Changed in urfkill (Ubuntu Utopic):
status: In Progress → Won't Fix
Changed in ubuntu-system-settings (Ubuntu Utopic):
status: In Progress → Won't Fix
Changed in indicator-network (Ubuntu):
status: In Progress → Triaged
importance: Undecided → Wishlist
Changed in indicator-network (Ubuntu Utopic):
status: Won't Fix → Triaged
importance: Undecided → Wishlist
Changed in network-manager (Ubuntu):
status: In Progress → Triaged
importance: Undecided → Wishlist
Changed in network-manager (Ubuntu Utopic):
status: Won't Fix → Triaged
importance: Undecided → Wishlist
Changed in nuntium (Ubuntu):
status: In Progress → Triaged
importance: Undecided → Wishlist
Changed in nuntium (Ubuntu Utopic):
status: Won't Fix → Triaged
importance: Undecided → Wishlist
Changed in ofono (Ubuntu):
status: In Progress → Triaged
Changed in ofono (Ubuntu Utopic):
status: Won't Fix → Triaged
Changed in powerd (Ubuntu):
status: In Progress → Triaged
importance: Undecided → Wishlist
Changed in powerd (Ubuntu Utopic):
status: Won't Fix → Triaged
importance: Undecided → Wishlist
Changed in ubuntu-download-manager (Ubuntu):
status: In Progress → Triaged
importance: Undecided → Wishlist
Changed in ubuntu-download-manager (Ubuntu Utopic):
status: Won't Fix → Triaged
importance: Undecided → Wishlist
Changed in urfkill (Ubuntu):
status: In Progress → Triaged
importance: Undecided → Wishlist
Changed in urfkill (Ubuntu Utopic):
status: Won't Fix → Triaged
importance: Undecided → Wishlist
Changed in ubuntu-system-settings (Ubuntu):
status: In Progress → Triaged
importance: Undecided → Wishlist
Changed in ubuntu-system-settings (Ubuntu Utopic):
status: Won't Fix → Triaged
importance: Undecided → Wishlist
Changed in indicator-network (Ubuntu Utopic):
status: Triaged → Won't Fix
Changed in network-manager (Ubuntu Utopic):
status: Triaged → Won't Fix
Changed in nuntium (Ubuntu Utopic):
status: Triaged → Won't Fix
Changed in ofono (Ubuntu Utopic):
status: Triaged → Won't Fix
Changed in powerd (Ubuntu Utopic):
status: Triaged → Won't Fix
Changed in ubuntu-download-manager (Ubuntu Utopic):
status: Triaged → Won't Fix
Changed in urfkill (Ubuntu Utopic):
status: Triaged → Won't Fix
Changed in ubuntu-system-settings (Ubuntu Utopic):
status: Triaged → Won't Fix
Changed in indicator-network (Ubuntu):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in indicator-network (Ubuntu Utopic):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in network-manager (Ubuntu):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in network-manager (Ubuntu Utopic):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in nuntium (Ubuntu):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in nuntium (Ubuntu Utopic):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in ofono (Ubuntu):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in ofono (Ubuntu Utopic):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in powerd (Ubuntu):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in powerd (Ubuntu Utopic):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in ubuntu-download-manager (Ubuntu):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in ubuntu-download-manager (Ubuntu Utopic):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in ubuntu-system-settings (Ubuntu):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in ubuntu-system-settings (Ubuntu Utopic):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in urfkill (Ubuntu):
assignee: Jamie Strandboge (jdstrand) → nobody
Changed in urfkill (Ubuntu Utopic):
assignee: Jamie Strandboge (jdstrand) → nobody
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.