Skip to content

Conversation

@lifubang
Copy link
Member

@lifubang lifubang commented Apr 4, 2019

In some old kernels, for example, 3.10.0-862.el7.x86_64 in RedHat Enterprise Linux 7.5.
With selinux enabled.
SetKeyLabel with empty string "" in the first time is not supported.
But with non empty string is supported.

It will cause runc fail if selinuxLabel is "" in config.json in these kernels.

Signed-off-by: Lifubang lifubang@acmcoder.com

@lifubang
Copy link
Member Author

lifubang commented Apr 4, 2019

I think we should not be hurry to close this PR, we need a full discussion to reduce regressions which have impact to runc.

@lifubang lifubang changed the title fix SetKeyLabel in old kernels fix SetKeyLabel in old kernels with selinux enabled Apr 5, 2019
@lifubang lifubang force-pushed the oldkernel branch 2 times, most recently from 743263d to 645c7cc Compare April 5, 2019 04:06
@lifubang
Copy link
Member Author

lifubang commented Apr 5, 2019

I spent a whole morning dig into this issue. And find out in this old kernel with selinux enabled:

(1) "/proc/self/attr/keycreate" is always exist since Linux 2.6.18;

(2) When we write "" to "/proc/self/attr/keycreate" in the first time, it will cause write /proc/self/attr/keycreate: permission denied error;

(3) When we read "/proc/self/attr/keycreate" in the first time, it will get an error io.EOF;

(4) After we write non empty string to "/proc/self/attr/keycreate" , then we can read and write to "/proc/self/attr/keycreate" in any time without any errors.

So I think we can use io.EOF to check we should write "" to "/proc/self/attr/keycreate".

I have submit the latest commit. PTAL @cyphar @rhatdan Thanks.
If have any suggestions, please input here. I will debug it.

}
}
err := selinux.SetKeyLabel(processLabel)
if err != nil && processLabel == "" && os.IsNotExist(err) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think processLabel == "" should be here. really it should just be:

if os.IsNotExist(err) {
}

With the note that os.IsNotExist(nil) == false.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your review. I have update it.

return nil
}
}
err := selinux.SetKeyLabel(processLabel)
Copy link
Member

Choose a reason for hiding this comment

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

Why not put this check inside selinux.SetKeyLabel? Seems a bit odd to put it in this wrapper.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is.
If the user just use "github.com/opencontainers/selinux/go-selinux", not "github.com/opencontainers/selinux/go-selinux/label".
I have update it.

func SetKeyLabel(label string) error {
return writeCon("/proc/self/attr/keycreate", label)
if label == "" && GetEnabled() {
if _, err := KeyLabel(); err == io.EOF {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not check ENoExists here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, Because we add it after write action. Anyway, I think we can add. I will add it later.

Copy link
Member Author

Choose a reason for hiding this comment

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

And the ENoExists check after writeCon should also be remained.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for your review, it will reduce one file write call, does these code change make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It will still fail on Permission Denied. If the user tries to write to a KeyLabel they are allowed to read but not allowed to write.
I am not even sure what the io.EOF does?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it does make sense that Permission Denied err when write to keycreate should be throwed to runc.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not even sure what the io.EOF does?

I think it is what is the older kernel really mean! It also be very very strange to me, but it really happens. I think this is a selinux bug in this old kernel.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What OS and What Kernel?

Copy link
Member Author

Choose a reason for hiding this comment

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

What OS and What Kernel?

I think I have provided it in PR description.
In some old kernels, for example, 3.10.0-862.el7.x86_64 in RedHat Enterprise Linux 7.5.
With selinux enabled.

@lifubang lifubang force-pushed the oldkernel branch 3 times, most recently from 336944d to f8fdde7 Compare April 5, 2019 15:43
Signed-off-by: Lifubang <lifubang@acmcoder.com>
@lifubang lifubang changed the title fix SetKeyLabel in old kernels with selinux enabled [WIP] fix SetKeyLabel in old kernels with selinux enabled Apr 8, 2019
@lifubang
Copy link
Member Author

lifubang commented Apr 8, 2019

@rhatdan Could you tell me when you submit the PR opencontainers/runc#2012, you test it in what OS version and what kernel version?

@rhatdan
Copy link
Collaborator

rhatdan commented Apr 8, 2019

I tested it in Fedora.

@cpuguy83
Copy link
Contributor

Note there is also a regression with just the default docker setup (where --selinux-enabled=false), runc is unable to create containers as it gets EPERM when trying to SetKeyLabel.

@rhatdan
Copy link
Collaborator

rhatdan commented Apr 24, 2019

The other patch got merged.

@rhatdan rhatdan closed this Apr 24, 2019
@kolyshkin
Copy link
Collaborator

The other patch got merged.

For the sake of other lost souls reading this, "the other patch" here means #49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants