Repository navigation
fsmount: Fix selinux mount parameter parsing - #13754
Conversation
There was a problem hiding this comment.
Pull request overview
Updates internal/fsmount to handle SELinux mount options that may be quoted when coming from the single-syscall mount API, ensuring values passed to the fsconfig() API are unquoted as required.
Changes:
- Detect
*context=mount options and strip surrounding double quotes from their values before callingunix.FsconfigSetString.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dd83a29 to
ab5eae0
Compare
| strings.HasSuffix(val, "\"") { | ||
| val, _ = strings.CutPrefix(val, "\"") | ||
| val, _ = strings.CutSuffix(val, "\"") | ||
| } |
There was a problem hiding this comment.
Go has Unquote and UnquoteChar or strings.Trim.
Also can you introduce a small unit test for this.
ab5eae0 to
76afad7
Compare
76afad7 to
2dce7ea
Compare
| mount := mount.Mount{ | ||
| Type: "tmpfs", | ||
| Options: []string{"mode=0700", ml}, | ||
| } | ||
|
|
||
| err = mount.Mount(tmp) | ||
| t.Cleanup(func() { | ||
| testutil.Unmount(t, tmp) | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| newlabel, err := selinux.FileLabel(tmp) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, label, newlabel) | ||
|
|
||
| err = fsmount.Fsmount(mount, tmp) | ||
| require.NoError(t, err) |
There was a problem hiding this comment.
agreed, although there are a number of existing in-tree instances of mount used as the variable name for a mount.Mount object. Should I adjust it anyway?
There was a problem hiding this comment.
I usually use mnt (or if it's really nearby m) to avoid shadowing. Not a hard blocker for me, unless you need to update (might prevent some code-churn).
There was a problem hiding this comment.
Yeah, might as well adjust this location. I don't think we need to remain consistent with shadowing done elsewhere. m or mnt would be fine.
There was a problem hiding this comment.
Yeah, might as well adjust this location. I don't think we need to remain consistent with shadowing done elsewhere. m or mnt would be fine.
| mount := mount.Mount{ | ||
| Type: "tmpfs", | ||
| Options: []string{"mode=0700", ml}, | ||
| } | ||
|
|
||
| err = mount.Mount(tmp) |
There was a problem hiding this comment.
Had a quick peek; looks like m is most popular 😅
git grep ':= mount.Mount{'
contrib/fuzz/diff_fuzz_test.go: m := mount.Mount{}
contrib/fuzz/diff_fuzz_test.go: m := mount.Mount{}
contrib/fuzz/diff_fuzz_test.go: m := mount.Mount{}
core/mount/manager/manager.go: m := mount.Mount{
core/mount/manager/manager_linux_test.go: m := mount.Mount{
core/mount/manager/mkdir_linux_test.go: m := mount.Mount{
core/unpack/unpacker.go: m := mount.Mount{
pkg/archive/tar_linux_test.go: m := mount.Mount{
plugins/mount/erofs/plugin_linux_test.go: m := mount.Mount{
plugins/mount/erofs/plugin_linux_test.go: m := mount.Mount{
plugins/mount/erofs/plugin_linux_test.go: simpleMount := mount.Mount{
plugins/mount/erofs/plugin_linux_test.go: manyOptionsMount := mount.Mount{
plugins/snapshots/erofs/erofs.go: m := mount.Mount{
plugins/snapshots/erofs/erofs.go: m := mount.Mount{
plugins/snapshots/overlay/overlayutils/check.go: m := mount.Mount{
plugins/snapshots/overlay/overlayutils/check.go: m := mount.Mount{
|
Change itself LGTM; but (per the discussion about) I think it's worth changing that variable name before merging. |
Because selinux contexts can contain commas, context strings may be quoted in the single-syscall mount API. This quoting is not permitted when using the fsconfig API, so strip the quotes when preparing the system call arguments. Signed-off-by: Daniel De Graaf <[email protected]>
2dce7ea to
dd2bcfc
Compare
Because selinux contexts can contain commas, context strings may be quoted in the single-syscall mount API. This quoting is not permitted when using the fsconfig API, so strip the quotes when preparing the system call arguments.