Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/snap-confine: bring /lib/firmware from the host #7104

Merged
merged 2 commits into from Jul 16, 2019

Conversation

zyga
Copy link
Collaborator

@zyga zyga commented Jul 12, 2019

The kernel will use the mount namespace of the invoking process to
auto-load firmware on demand. On core18 systems or on systems using core
and core18 base snap apps the /lib/firmware directory is empty present,
causing issues with CUDA and some wifi stacks. This patch fixes this

Fixes: https://bugs.launchpad.net/snapd/+bug/1821023
Signed-off-by: Zygmunt Krynicki me@zygoon.pl

@zyga zyga requested review from mvo5 and jdstrand July 12, 2019 15:46
The kernel will use the mount namespace of the invoking process to
auto-load firmware on demand. On core18 systems or on systems using core
and core18 base snap apps the /lib/firmware directory is empty present,
causing issues with CUDA and some wifi stacks. This patch fixes this

Fixes: https://bugs.launchpad.net/snapd/+bug/1821023
Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
jdstrand
jdstrand previously approved these changes Jul 12, 2019
Copy link

@jdstrand jdstrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming tests pass, this looks fine. It is curious that the kernel looks at the namespace of the invoking process for firmware load, but not for module load (as discussed in #7053 (comment)). It seems this should be consistent and possibly a bug for the /lib/firmware case (why wouldn't it load from the host for firmware?).

@jdstrand
Copy link

jdstrand commented Jul 12, 2019

This PR is only exposing /lib/firmware from the host to the snap's runtime environment, which is correcting the weird behavior of the kernel (and the snap doesn't have access to /lib/firmware otherwise).

That said, we should blacklist /lib/firmware in layouts so that a snap can't provide firmware itself and then trigger an autoload.

UPDATE: I verified we are already blacklisting /lib/firmware

@mvo5 mvo5 added this to the 2.40 milestone Jul 12, 2019
@zyga
Copy link
Collaborator Author

zyga commented Jul 12, 2019

I force pushed to add the apparmor permission. Sorry about that, didn't think about it up front.

@codecov-io
Copy link

Codecov Report

Merging #7104 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7104      +/-   ##
==========================================
- Coverage    80.4%   80.39%   -0.01%     
==========================================
  Files         627      627              
  Lines       49081    49081              
==========================================
- Hits        39462    39459       -3     
- Misses       6570     6573       +3     
  Partials     3049     3049
Impacted Files Coverage Δ
httputil/useragent.go 77.14% <0%> (-5.72%) ⬇️
cmd/snap-seccomp/main.go 66.66% <0%> (-0.46%) ⬇️
overlord/ifacestate/handlers.go 65.42% <0%> (-0.22%) ⬇️
overlord/hookstate/hookmgr.go 73.8% <0%> (+0.95%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4bb0643...a6e691c. Read the comment docs.

@zyga
Copy link
Collaborator Author

zyga commented Jul 12, 2019

I will need to add the corresponding SELinux permission as well:

grep error: pattern not found, got:
----
type=PROCTITLE msg=audit(07/12/19 18:23:23.496:2273) : proctitle=/usr/libexec/snapd/snap-confine snap.test-snapd-service.test-snapd-sigusr2-service /usr/lib/snapd/snap-exec test-snapd-service.t 
type=SYSCALL msg=audit(07/12/19 18:23:23.496:2273) : arch=x86_64 syscall=mount success=yes exit=0 a0=0x40cc97 a1=0x7ffc8fc21c90 a2=0x0 a3=MS_REC|MS_SLAVE items=0 ppid=1 pid=21712 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=snap-confine exe=/usr/libexec/snapd/snap-confine subj=system_u:system_r:snappy_confine_t:s0 key=(null) 
type=AVC msg=audit(07/12/19 18:23:23.496:2273) : avc:  denied  { mounton } for  pid=21712 comm=snap-confine path=/tmp/snap.rootfs_rBIvxg/lib/firmware dev="sda1" ino=16803111 scontext=system_u:system_r:snappy_confine_t:s0 tcontext=system_u:object_r:lib_t:s0 tclass=dir permissive=1

@pedronis pedronis dismissed jdstrand’s stale review July 12, 2019 21:05

it's unclear if the last sate of the PR was reviewed

@pedronis pedronis requested a review from jdstrand July 12, 2019 21:05
mvo5
mvo5 previously approved these changes Jul 15, 2019
Copy link
Collaborator

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix!

@mvo5
Copy link
Collaborator

mvo5 commented Jul 15, 2019

I pushed the SELinux update but ideally someone knowledgable in this area would double check.

@mvo5 mvo5 dismissed their stale review July 15, 2019 08:40

Pused my own stuff to the PR now

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm (non SELinux bits)

@@ -468,6 +469,7 @@ allow snappy_confine_t etc_t:file mounton;
allow snappy_confine_t home_root_t:dir mounton;
allow snappy_confine_t ifconfig_var_run_t:dir mounton;
allow snappy_confine_t modules_object_t:dir mounton;
allow snappy_confine_t lib_t:dir mounton;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this enough for this functionality to work? It looks okay, but I’m not sure if mounton implies that you can read the stuff inside once it is mounted inside. We did this with several other types, so…

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It seems to be enough, our tests are happy but maybe they are not deep enough - I am inclined to use as is and let @stolowski review later and tweak policy and tests if needed.

@@ -193,6 +193,9 @@
mount options=(rw rbind) {,/usr}/lib{,32,64,x32}/modules/ -> /tmp/snap.rootfs_*{,/usr}/lib/modules/,
mount options=(rw rslave) -> /tmp/snap.rootfs_*{,/usr}/lib/modules/,

mount options=(rw rbind) {,/usr}/lib{,32,64,x32}/firmware/ -> /tmp/snap.rootfs_*{,/usr}/lib/firmware/,
mount options=(rw rslave) -> /tmp/snap.rootfs_*{,/usr}/lib/firmware/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we allowing these to be mounted as read-write? These should be only read-only mounted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I think we need to talk to @zyga because e.g. the modules are probably also fine to be mounted RO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the mount options are not super accurate as in, they are not really respected the way they should be. I will look at a pass that changes most of them to read only.

@mvo5 mvo5 merged commit dba8e09 into snapcore:master Jul 16, 2019
@mvo5 mvo5 modified the milestones: 2.40, 2.41 Jul 16, 2019
@zyga zyga deleted the fix/firmware branch July 23, 2019 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants