Skip to content

chown: use Link instead of Chown for dup inodes#1258

Merged
rhatdan merged 1 commit intocontainers:mainfrom
giuseppe:chown-add-check
Jun 14, 2022
Merged

chown: use Link instead of Chown for dup inodes#1258
rhatdan merged 1 commit intocontainers:mainfrom
giuseppe:chown-add-check

Conversation

@giuseppe
Copy link
Copy Markdown
Member

@giuseppe giuseppe commented Jun 13, 2022

If the inode was already encountered and chowned, use link(2) instead
of chown(2).

This is needed when the underlying storage (as it could be overlay
with index=off) breaks the hard link on copy up.

#1144 added the initial
check.

Closes: #1257

Signed-off-by: Giuseppe Scrivano gscrivan@redhat.com

Copy link
Copy Markdown
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM

// If the dev/inode was already chowned but the file has the original
// owner then it means the underlying hard link was broken (as it happens with
// overlay when index=off) so we need to chown again and not rely on the previous
// chown for the same inode.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This comment really confused me - it didn't describe the checks on the next line, and after suggesting that if the checks were true, we still needed to do something, it just returned.

@nalind
Copy link
Copy Markdown
Member

nalind commented Jun 13, 2022

Do we want to take the hit of checking inode numbers after the system.Lchown(), and re-linking things that we know were linked before we started walking the tree?

@nalind
Copy link
Copy Markdown
Member

nalind commented Jun 13, 2022

I suppose if we only checked for "that multiply-linked thing got a new inode number" when st.Nlinks > 1, it might not hurt too bad. If we kept a mapping from old inode numbers to new link targets, and relinked it instead of chowning the no-longer-linked lower item, would that work?

@giuseppe
Copy link
Copy Markdown
Member Author

I suppose if we only checked for "that multiply-linked thing got a new inode number" when st.Nlinks > 1, it might not hurt too bad. If we kept a mapping from old inode numbers to new link targets, and relinked it instead of chowning the no-longer-linked lower item, would that work?

that is a much better solution. I've played with it and it seems to work fine, I'll test it more and update the PR

@giuseppe giuseppe changed the title chown: validate uid/gid before skipping chown chown: use Link instead of Chown for dup inodes Jun 13, 2022
@giuseppe giuseppe marked this pull request as draft June 14, 2022 07:03
@giuseppe giuseppe marked this pull request as ready for review June 14, 2022 07:09
@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Jun 14, 2022

LGTM
@nalind PTAL

@nalind
Copy link
Copy Markdown
Member

nalind commented Jun 14, 2022

Are there any tests we can add for this?

@nalind
Copy link
Copy Markdown
Member

nalind commented Jun 14, 2022

LGTM

If the inode was already encountered and chowned, use link(2) instead
of chown(2).

This is needed when the underlying storage (as it could be overlay
with index=off) breaks the hard link on copy up.

containers#1144 added the initial
check.

Closes: containers#1257

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@rhatdan rhatdan merged commit 388efef into containers:main Jun 14, 2022
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.

Hard links losing ownership information when run with user namespaces

4 participants