Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Interface for modem manager #1226
Conversation
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
add to whitelist |
morphis
reviewed
May 26, 2016
| + | ||
| +var modemManagerPermanentSlotDBus = []byte(` | ||
| +<!-- DBus policy for ModemManager (upstream version 1.4.0) | ||
| + - TODO change to polkit one when we enable it --> |
alfonsosanchezbeato
May 26, 2016
Contributor
Upstream has actually two policy files, one used when policy kit is disabled and one used when policy kit is enabled. This is the upstream one for the case of policy kit disabled.
morphis
reviewed
May 26, 2016
| + | ||
| +LABEL="mm_mbm_check" | ||
| + | ||
| +# Ericsson F3507g |
morphis
May 26, 2016
Contributor
We should drop all device specific rules and just leave the common ones in here. Any device specific rules need to be shipped with the gadget/kernel snap.
niemeyer
May 27, 2016
Contributor
All the rules should actually ship in snapd. No snap, not even kernel or gadget, are allowed to inject security rules into snapd.
morphis
May 27, 2016
Contributor
@niemeyer That wont work as we would have to adjust the interface for each customer specific device we're doing. Keep in mind that that product IDs are changing through simple things like rebranding etc. Both modem-manager and ofono are handling this thing through udev rules which will be device specific and we can't simply ship all of them in this interface. That is a simple maintenance hell.
alfonsosanchezbeato
May 30, 2016
Contributor
Note that this device detection can be done in code from the snap too. For instance, ofono has two ways of detecting the modem type: the old one by using udev rules, and the new one, where it looks directly for vendor/product ID in udev events instead of looking for labels added by udev rules. It just happens that attaching labels used to be more convenient.
As I understand this, interfaces should be kind of general so this interface should be ideally reusable by programs that handle modems, say ModemManager AND ofono. So the ideal thing would be to put this application specific stuff (because these rules are MM rules, ofono has different ones - note again that only for a few modems) inside the snap, not in the gadget snap and not in the interface. As the snap should not add udev rules, this should be handled in code instead, as ofono does. No need for more permissions provided for the interface, as it is just a matter of listening to udev events.
However, this would require intensive modifications in ModemManager that we cannot assume. In the future world, if we get upstream buy-in, they would handle this. Meanwhile, I think this can be added to the interface, otherwise it would need to be added to every gadget snap, for which we do not necessarily will have control in the future. So somebody would install MM snap from the store and will find it is not able to detect the system modem.
jdstrand
Jun 7, 2016
Contributor
Not blocking on the unimplemented idea I posted above, but if modem-manager can use the new way of looking for vendor/product ID in udev events, I think the dynamically generated apparmor rules for udev files would allow this to work and the old udev rules way of doing things can go away?
morphis
reviewed
May 26, 2016
| +@{PROC}/@{pid}/loginuid r, | ||
| +capability setgid, | ||
| +capability setuid, | ||
| +/sbin/resolvconf rix, |
morphis
reviewed
May 26, 2016
| +/dev/ppp rw, | ||
| +/dev/tty[^0-9]* rw, | ||
| +/run/udev/data/* r, | ||
| +/proc/sys/kernel/modprobe r, |
alfonsosanchezbeato
May 26, 2016
Contributor
ppp_deflate, ppp_async, maybe more depending on protocols (VPN case?). Sending packages through PPP and doing some tasks is at the kernel level due to efficiency reasons (otherwise you would need to get IP packets on user side and send them through the tty device back to the kernel).
morphis
May 30, 2016
Contributor
I am not sure if the better thing would be (if we keep ppp in the core snap) to create a ppp interface which would be implicitly provided by the core snap. However we're not doing that for wpa-supplicant as of today which is used the same way from the network-manager snap. If @zyga @jdstrand or @niemeyer don't have anything against this I am fine to keep those for now.
zyga
May 30, 2016
Contributor
If we had a ppp interface on the core snap, how would this make things better?
morphis
May 30, 2016
Contributor
It would be usable by both ofono and modem-manager and we don't need to write the same rules into both interfaces.
jdstrand
May 31, 2016
Contributor
As mentioned, very much against the snap loading modules. Fine with snapd doing this on the snap's behalf via this interface or a 'ppp' interface.
morphis
reviewed
May 26, 2016
| +/bin/kmod ix, | ||
| +capability sys_module, | ||
| +/run/lock/*tty[^0-9]* rw, | ||
| +/run/ppp* rw, |
morphis
May 26, 2016
Contributor
All those ppp ones should go into SNAP_DATA and ppp should come from the snap itself.
alfonsosanchezbeato
May 30, 2016
Contributor
It is part of the core snap and interacts quite heavily with the kernel, so not sure if we should do that
morphis
reviewed
May 26, 2016
| @@ -67,6 +67,29 @@ network packet, | ||
| /dev/rfkill rw, | ||
| +# Needed for modem connections using PPP | ||
| +/usr/sbin/pppd ix, |
alfonsosanchezbeato
May 26, 2016
Contributor
It is part of the core snap and interacts quite heavily with the kernel, so not sure if we should do that.
|
Just one note regarding having security snippets outside of snapd itself, otherwise this is a great review by @morphis. Thanks for that! |
niemeyer
added
the
Reviewed
label
May 27, 2016
jdstrand
reviewed
May 27, 2016
| @@ -29,6 +29,7 @@ var allInterfaces = []interfaces.Interface{ | ||
| &LocationControlInterface{}, | ||
| &LocationObserveInterface{}, | ||
| &NetworkManagerInterface{}, | ||
| + &ModemManagerInterface{}, |
jdstrand
May 27, 2016
Contributor
Totally minor nitpick, but it would be great since there are so many of these if they could be alphabetized.
jdstrand
reviewed
May 27, 2016
| @@ -29,6 +29,7 @@ var allInterfaces = []interfaces.Interface{ | ||
| &LocationControlInterface{}, | ||
| &LocationObserveInterface{}, | ||
| &NetworkManagerInterface{}, | ||
| + &ModemManagerInterface{}, | ||
| NewFirewallControlInterface(), | ||
| NewHomeInterface(), | ||
| NewLocaleControlInterface(), |
jdstrand
May 27, 2016
Contributor
@zyga - as a total aside, I wonder why we sometimes prefix 'New' here....
jdstrand
reviewed
May 27, 2016
| + | ||
| +# To check present devices | ||
| +/run/udev/data/* r, | ||
| +/sys/bus/usb/devices** r, |
jdstrand
May 27, 2016
•
Contributor
I really don't like these kinds of rules-- snapd should be querying udev and adding the /sys and /run/udev accesses that are assigned to the snap. That said, we don't have that yet, so this is ok. Can you adjust this: '/sys/bus/usb/devices** r,' to be '/sys/bus/usb/devices/** r,' though?
EDIT: Can you add a 'FIXME' note regarding how we should be querying udev instead of hard-coding this?
jdstrand
reviewed
May 27, 2016
| +/sys/bus/usb/devices** r, | ||
| + | ||
| +# Access to modem ports | ||
| +/dev/tty[^0-9]* rw, |
jdstrand
May 27, 2016
Contributor
I was hoping that interfaces would solve this sort of thing and snapd would be more dynamic rather than hard-coding devices in this manner, but again, we aren't there yet. Without this dynamism, if there is another interface that needs /dev/tty* then two snaps using two different interfaces on the same system might cause problems for each other by accessing the same device. Can you add a FIXME for this? Also, what about /dev/ttyUSB*, is that handled differently?
alfonsosanchezbeato
May 30, 2016
Contributor
FIXME added. The rule is to be able to access all /dev/tty* but virtual terminals (/dev/tty0, /dev/tty1, ...), as there are many variants possible: /dev/ttyS[N], /dev/ttyUSB[N], /dev/ttyACM[N], etc.
Just added /dev/cdc-* too, had forgotten that one.
jdstrand
reviewed
May 27, 2016
| +/dev/tty[^0-9]* rw, | ||
| + | ||
| +# For ioctl TIOCSSERIAL ASYNC_CLOSING_WAIT_NONE | ||
| +capability sys_admin, |
jdstrand
May 27, 2016
Contributor
Oh sigh, but at least this is a trusted interface. :) The seccomp argument filtering branch should be able to limit the ioctl to TIOCSSERIAL at least.
jdstrand
reviewed
May 27, 2016
| + path=/org/freedesktop/DBus | ||
| + interface=org.freedesktop.DBus | ||
| + member={Request,Release}Name | ||
| + peer=(name=org.freedesktop.DBus), |
jdstrand
reviewed
May 27, 2016
| +dbus (receive, send) | ||
| + bus=system | ||
| + path=/org/freedesktop/ModemManager1{,/**} | ||
| + interface=org.freedesktop.ModemManager1*, |
jdstrand
May 27, 2016
Contributor
This should be moved to ConnectedSlotAppArmor with: peer=(label=###PLUG_SECURITY_TAGS###). See location_observe.go as an example.
I realize you probably did this based on bluez and network-manager, but we learned with location-observe that we could do better (this type of change is what the nm branch I gave you is doing btw (and we'll need another for bluez)).
jdstrand
reviewed
May 27, 2016
| + bus=system | ||
| + path=/org/freedesktop/ModemManager1{,/**} | ||
| + interface=org.freedesktop.DBus.*, | ||
| +`) |
jdstrand
May 27, 2016
Contributor
Same here (move to ConnectedSlotAppArmor with: peer=(label=###PLUG_SECURITY_TAGS###))
jdstrand
reviewed
May 27, 2016
| + bus=system | ||
| + path=/org/freedesktop/ModemManager1{,/**} | ||
| + peer=(label=###SLOT_SECURITY_TAGS###), | ||
| +`) |
jdstrand
May 27, 2016
Contributor
Just to be explicit-- this is granting all of modem manager's DBus API to a connected clients. Is that intentional?
alfonsosanchezbeato
May 30, 2016
Contributor
Yes, it is. I do not see a real reason to limit access to MM DBus interface from clients (see https://www.freedesktop.org/software/ModemManager/api/latest/).
jdstrand
reviewed
May 27, 2016
| +setsockopt | ||
| +shutdown | ||
| +socketpair | ||
| +socket |
jdstrand
May 27, 2016
Contributor
Can you add a: # TODO: add ioctl argument filters when seccomp arg filtering is implemented
jdstrand
reviewed
May 27, 2016
| +send | ||
| +sendto | ||
| +sendmsg | ||
| +socket |
jdstrand
May 27, 2016
Contributor
@zyga - I wonder if these seccomp rules for talking to dbus should be added to PermanentPlugSeccomp rules instead. Idea being, plugging clients will be killed if they try to use dbus if we only put these in ConnectedPlugSeccomp since they aren't connected on install whereas if we allowed them in PermanentPlugSeccomp they would not be killed, get a DBus denied message and be in a position to handle the condition gracefully. Another way to do it is if an interface uses the DBus backend, just add these seccomp rules unconditionally to the policy.
None of this should block this PR.
zyga
May 30, 2016
Contributor
Could we constrain those so that those are not equivalent to a connected network slot? If so then yeah, we could move them to permanent.
jdstrand
May 31, 2016
Contributor
We will be able to do something like that with 'socket' once seccomp arg filtering lands.
jdstrand
reviewed
May 27, 2016
| +KERNEL=="cdc-wdm*", SUBSYSTEM=="usb", ENV{ID_MM_CANDIDATE}="1" | ||
| +KERNEL=="cdc-wdm*", SUBSYSTEM=="usbmisc", ENV{ID_MM_CANDIDATE}="1" | ||
| + | ||
| +LABEL="mm_candidate_end" |
jdstrand
May 27, 2016
Contributor
How do these rules correspond to the /dev/ accesses you gave in the apparmor policy? It seems that we are missing an opportunity here to use our snappy udev device assignment implementation and instead giving blanket apparmor rules with different tagging. If you are unfamiliar with what I am talking about, please see 'devices cgroup' from: https://raw.githubusercontent.com/ubuntu-core/snap-confine/master/README.md
alfonsosanchezbeato
May 30, 2016
Contributor
Modem access is done via /dev/tty* and /dev/cdc-*. Not really sure how this should be modified by reading the link you posted. Note also that modem detection must be dynamic (think of insertion of modem dongle). Would your comment still apply in this case?
jdstrand
May 31, 2016
Contributor
snapd is supposed to be able to handle dynamic detection and AIUI, this is the function of the gadget snap (mapping snappy names to device names) such that snapd can tag these devices accordingly and assign them to the slot via the udev backend.
zyga
May 31, 2016
Contributor
IMHO we cannot and won't be able to do dynamic slots anytime soon. Even with hook support we won't see a distinct serial-port slot for each serial on the device that is not explicitly listed in the gadget snap. If you plug in a new one later it will not show up as a new slot.
jdstrand
reviewed
May 27, 2016
| +/run/udev/data/* r, | ||
| +/proc/sys/kernel/modprobe r, | ||
| +/bin/kmod ix, | ||
| +capability sys_module, |
jdstrand
May 27, 2016
•
Contributor
This gives network-manager ring 0 access to the system. If you can load a kernel module, then you can disable all security, etc, etc. We should try to avoid this at all costs and note also that module autoloading should work fine and not require this access. 'snappy config ubuntu-core' in 15.04 allowed you to load kernel modules and IIRC this was exposed in the gadget snap. 16 removed all of this but we should be designing a system where snaps don't load modules themselves. There are a number of ways to handle this that could all be implemented:
- AIUI, 'snap config' will be coming back and it could support module loading
- the gadget snap could support module loading
- the interface could encode a list of modules to load and upon snap install/connect, snapd could load the modules. I discussed this relative to firewall-control here: https://bugs.launchpad.net/snappy/+bug/1583514
- snapd and the snap implementing a particular slot could talk over a carefully designed protocol for having snapd load requested modules (perhaps this is all abstracted behind a rewritten modprobe)
The main points of all of the above is that snaps don't load modules themselves and if snapd is expanded to load modules on behalf of snaps, that should be carefully controlled.
@tyhicks - fyi, I think you'll want to keep an eye on this
alfonsosanchezbeato
May 30, 2016
Contributor
@jdstrand , the one actually loading modules is pppd, which is part of the core snap and then trusted. How about executing it unconfined (ux)? This would remove most of this new NM rules, so NM process would not have ring 0 access.
jdstrand
May 31, 2016
Contributor
I'd prefer to have snapd add the rules rather than using a Ux/ux rule on pppd. This just shifts the attack from modem manager to pppd.
jdstrand
reviewed
May 27, 2016
| +/etc/ppp/** rwix, | ||
| +/dev/ppp rw, | ||
| +/dev/tty[^0-9]* rw, | ||
| +/run/udev/data/* r, |
jdstrand
reviewed
May 27, 2016
| @@ -43,6 +43,7 @@ var implicitClassicSlots = []string{ | ||
| "opengl", | ||
| "network-manager", | ||
| "pulseaudio", | ||
| + "modem-manager", |
jdstrand
May 27, 2016
Contributor
Is modem manager really needed on classic or is this just something that works with network-manager? I'm trying to understand what snaps would legitimately access modem manager on classic.
alfonsosanchezbeato
May 30, 2016
Contributor
NM, but also alternatives like connman. And, you could also manually configure modem connections.
|
PR refreshed after addressing comments. |
zyga
reviewed
May 30, 2016
| + | ||
| +# Access to modem ports | ||
| +# FIXME snapd should be more dynamic to avoid conflicts between snaps trying to | ||
| +# access same ports. |
zyga
May 30, 2016
Contributor
We might be able to do it with serial port interface but for now I think this is somewhat OK. Caveat: modem-manager has a bad history of poking anything that's not blacklisted and sometimes causing issues but I guess we have no other choice yet.
zyga
reviewed
May 30, 2016
| +/run/udev/data/* r, | ||
| +/sys/bus/usb/devices/ r, | ||
| +# FIXME snapd should be querying udev and adding the /sys and /run/udev accesses | ||
| +# that are assigned to the snap, but we are not there yet. |
jdstrand
Jun 7, 2016
•
Contributor
The idea is this:
-
if snapd knows the device in /dev, do
udevadm info /dev/foootherwise if snapd knows the device in /sys/devices, doudevadm info /sys/devices/.../foo. Eg:$ udevadm info /dev/kmsg P: /devices/virtual/mem/kmsg N: kmsg E: DEVMODE=0644 E: DEVNAME=/dev/kmsg E: DEVPATH=/devices/virtual/mem/kmsg E: MAJOR=1 E: MINOR=11 E: SUBSYSTEM=mem -
at this point we can tag this device as being assigned to the snap, using the udev backend
-
with the output from
udevadm infowe have enough information to grant precise access to /run/udev. Eg, for kmsg above:
/run/udev/data/c1:11 r, # based on MAJOR and MINOR
Opengl is similar:
$ udevadm info /dev/dri/card0
P: /devices/pci0000:00/0000:00:02.0/drm/card0
N: dri/card0
E: DEVNAME=/dev/dri/card0
E: DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0
E: DEVTYPE=drm_minor
E: ID_FOR_SEAT=drm-pci-0000_00_02_0
E: ID_PATH=pci-0000:00:02.0
E: ID_PATH_TAG=pci-0000_00_02_0
E: MAJOR=226
E: MINOR=0
E: SUBSYSTEM=drm
E: TAGS=:master-of-seat:seat:uaccess:
E: USEC_INITIALIZED=3062574
Add:
/run/udev/data/c226:0 r, # based on MAJOR and MINOR
/sys/devices/pci0000:00/0000:00:02.0/{,**} r, # based on DEVPATH
/run/udev/data/+pci:0000:00:02.0 r, # based on ID_PATH
We'll have to have some light per-interface mappings (eg, when ID_PATH is pci-0000:00:02.0, use +pci:0000:00:02.0 in /run/data, but there might already be libraries and udev queries that would do this for us). We might also have to recursively descend directories in /sys/devices to realpath() the files so we know what to add, but that isn't hard to do either. All the pieces are there.
zyga
reviewed
May 30, 2016
| +ATTRS{idVendor}=="0e8d", ATTRS{idProduct}=="00a7", ENV{ID_MM_MTK_TAGGED}="1" | ||
| + | ||
| +GOTO="mm_mtk_port_types_end" | ||
| + |
zyga
May 30, 2016
Contributor
(just keep scrolling).
By now I am convinced we need something better. Since we plan to talk about this tomorrow I won't comment on the rest.
zyga
reviewed
May 30, 2016
| @@ -67,6 +67,29 @@ network packet, | ||
| /dev/rfkill rw, | ||
| +# Needed for modem connections using PPP | ||
| +/usr/sbin/pppd ix, | ||
| +/etc/ppp/** rwix, |
zyga
reviewed
May 30, 2016
| @@ -454,7 +454,7 @@ func (s *interfaceManagerSuite) TestDoSetupProfilesAddsImplicitSlots(c *C) { | ||
| // NOTE: This is not an exact test as it duplicates functionality elsewhere | ||
| // and is was a pain to update each time. This is correctly handled by the | ||
| // implicit slot tests in snap/implicit_test.go | ||
| - c.Assert(len(slots) > 17, Equals, true) |
zyga
May 30, 2016
Contributor
Please merge with master, this is no longer something you have to change.
|
I have done some checks on the kernel modules. No options are used for them. The modules that ppp needs are: ppp_deflate bsd_comp ppp_async crc_ccitt option usb_wwan usbserial I have removed these lines in the NM interface: /proc/sys/kernel/modprobe r, Then I have loaded the modules with commands: sudo modprobe ppp_deflate Finally, I have inserted the modem dongle, and was able to establish a connection with no apparmor denials. Therefore, this /usr/sbin/pppd ix, is what we still need to add to the NM interface to establish a connection. So if we can pre-load said modules we can remove the loading modules permissions. Are we good with the permissions that still need to be added to NM interface? |
|
There is still the auto-connection problem. One option here would be to add DBus calls between NM and MM in the permanent slots for both interfaces, which actually removes the need for creating manually the connection. Thoughts? |
|
Afaik the outcome of the discussion yesterday was that we implement a ppp interface which we delegate the module loading to and the m-m snap will be connected too. @alfonsosanchezbeato Lets not add hacks/workarounds in the interface to overcome the missing auto-connect functionality. Auto-connection is a feature that is a requirement to get snaps included like nm or mm by default in a device image and has to be implemented. @zyga already has some plans for this if I remember well. For the detection of the modem-manager service from network-manager through a dbus name watch we should really only let the trigger go to network-manager once the modem-manager snap is connected of the interface to the network-manager snap and not before. @jdstrand is there a mechanism in apparmor's dbus mediation to cover those things? |
alfonsosanchezbeato
added some commits
May 23, 2016
|
PR refreshed after creating an implicit ppp interface that will eventually use the future snapd backend for loading kernel modules. All permissions needed to run pppd have been transferred to that interface from network-manager one. |
jdstrand
reviewed
Jun 7, 2016
| +# access same ports. | ||
| +/dev/tty[^0-9]* rw, | ||
| +/dev/cdc-* rw, | ||
| + |
jdstrand
Jun 7, 2016
•
Contributor
A snapd interface attribute could specify /dev/tty[0-9]* and /dev/cdc-* such that (pseudocode):
for a in interface_attribs; do
for i in /dev/tty* ; do
add_apparmor_udev_paths_for_device($i) # calls 'udevadm info $i', et al
done
done
|
Thank you for making the requested changes. In terms of security policy, I'm ok with this as is since it is using what we have, but having udev querying is going to help the policy to be more precise for all kinds of interfaces that need access to devices and we should be looking into that sooner than later IMHO. |
morphis
reviewed
Jun 8, 2016
| +/etc/resolvconf/** rw, | ||
| +/etc/resolvconf/update.d/* ix, | ||
| +/lib/resolvconf/* ix, | ||
| +# Loading of modules |
morphis
Jun 8, 2016
Contributor
Lets drop this now that we agreed on a interim solution until module loading is available through snapd.
|
Refreshed after removing the module loading part from ppp interface so this can be finally merged. |
jdstrand
reviewed
Jun 9, 2016
| +/usr/sbin/pppd ix, | ||
| +/etc/ppp/** rwix, | ||
| +/dev/ppp rw, | ||
| +/dev/tty[^0-9]* rw, |
jdstrand
Jun 9, 2016
Contributor
For these /dev accesses, we want to use the udev backend. If this must land now, feel free to add a FIXME note but ideally you'd use the udev backend in this PR.
jdstrand
Jun 9, 2016
Contributor
Eh, these are static devices so using the udev backend isn't required. +1 as is.
jdstrand
reviewed
Jun 9, 2016
| +/etc/resolvconf/** rw, | ||
| +/etc/resolvconf/update.d/* ix, | ||
| +/lib/resolvconf/* ix, | ||
| +`) |
jdstrand
Jun 9, 2016
Contributor
I'm mildly surprised that there isn't a ConnectedPlugSeccomp, but hey, I'm not complaining! :)
|
ppp interface security policy LGTM. If adding a FIXME comment, +1 from me. If using udev backend in this PR, I'd like to take another look. UPDATE: these are static devices so udev is not required. +1 as is. |
zyga
merged commit f80c050
into
snapcore:master
Jun 17, 2016
|
Let's land it and iterate on getting those FIXMEs reduced over time |
alfonsosanchezbeato commentedMay 25, 2016
•
Edited 1 time
-
alfonsosanchezbeato
May 25, 2016
Initial proposal for interface to enable modem-manager snap.
Some additional changes needed for network-manager are included in this PR too.