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: lazy set up of device cgroup, only when devices were assigned #10968

Conversation

bboozzoo
Copy link
Collaborator

Historically, a snap process ended up in a device cgroup (with device filtering)
only when there were assigned devices for it. On systems where CURRENT_TAGS is
supported and set by systemd/udev, snap-confine needs to do 2 passes on the list
of assigned devices. It may happen, that despite snap tag being present in the
TAGS list, it will not be present in the CURRENT_TAGS, in which case we may end
up in a scenario when no devices are actually assigned to the snap. The current
code would incorrectly handle such situation, and move the process into device
cgroup.

The branch introduces a lazy initialization of device cgroup and moves the
process to the group (or sets up device filtering on v2) only when there were
any assigned device.

…e assigned

Historically, a snap process ended up in a device cgroup (with device filtering)
only when there were assigned devices for it. On systems where CURRENT_TAGS is
supported and set by systemd/udev, snap-confine needs to do 2 passes on the list
of assigned devices. It may happen, that despite snap tag being present in the
TAGS list, it will not be present in the CURRENT_TAGS, in which case we may end
up in a scenario when no devices are actually assigned to the snap. The current
code would incorrectly handle such situation, and move the process into device
cgroup.

The branch introduces a lazy initialization of device cgroup and moves the
process to the group (or sets up device filtering on v2) only when there were
any assigned device.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
@bboozzoo bboozzoo added the Needs security review Can only be merged once security gave a :+1: label Oct 22, 2021
@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2021

Codecov Report

Merging #10968 (a4deb7a) into master (35528dd) will decrease coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10968      +/-   ##
==========================================
- Coverage   78.18%   78.17%   -0.01%     
==========================================
  Files         910      910              
  Lines      102788   102788              
==========================================
- Hits        80360    80358       -2     
- Misses      17405    17406       +1     
- Partials     5023     5024       +1     
Flag Coverage Δ
unittests 78.17% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
store/cache.go 69.23% <0.00%> (-1.93%) ⬇️

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 35528dd...a4deb7a. Read the comment docs.

Now that device cgroup assignment when no devices match is done properly, i.e.
we do not end up in a cgroup with just the common set of devices if none are
assigned, the test needs to be updated as we correctly observe first the
AppArmor denial, and then a device cgroup one.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Copy link
Contributor

@mardy mardy left a comment

Choose a reason for hiding this comment

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

LGTM with nitpicks :-)

cmd/snap-confine/udev-support.c Outdated Show resolved Hide resolved
cmd/snap-confine/udev-support.c Outdated Show resolved Hide resolved
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Copy link
Contributor

@stolowski stolowski left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for catching!

Copy link
Collaborator

@alexmurray alexmurray left a comment

Choose a reason for hiding this comment

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

LGTM!

@alexmurray alexmurray removed the Needs security review Can only be merged once security gave a :+1: label Oct 26, 2021
@bboozzoo
Copy link
Collaborator Author

some unrelated test failers, @mvo5 can you land this branch?

@mvo5 mvo5 merged commit 6102d79 into snapcore:master Oct 26, 2021
Copy link
Member

@anonymouse64 anonymouse64 left a comment

Choose a reason for hiding this comment

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

post merge lgtm, thanks for this

@anonymouse64
Copy link
Member

Also I think we should cherry-pick this onto 2.53 for 2.53.1

@anonymouse64
Copy link
Member

or sorry for 2.53.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants