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

kerndat: Skip clone3(set_tid) when unprivileged. #2252

Open
wants to merge 1 commit into
base: criu-dev
Choose a base branch
from

Conversation

osctobe
Copy link
Contributor

@osctobe osctobe commented Aug 24, 2023

A set of fixes for kerndat tests and a few debug logging improvements.

@osctobe osctobe requested a review from avagin August 24, 2023 19:18
@osctobe osctobe changed the title Assorted fixes Assorted fixes for kerndat and log messages Aug 24, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cda1c5c) 70.51% compared to head (e2ae63e) 70.50%.

❗ Current head e2ae63e differs from pull request most recent head ff088a7. Consider uploading reports for the commit ff088a7 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##           criu-dev    #2252      +/-   ##
============================================
- Coverage     70.51%   70.50%   -0.01%     
============================================
  Files           133      133              
  Lines         33534    33534              
============================================
- Hits          23646    23643       -3     
- Misses         9888     9891       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

criu/kerndat.c Outdated
@@ -1384,12 +1384,15 @@ static bool kerndat_has_clone3_set_tid(void)
pid_t pid;
struct _clone_args args = {};

kdat.has_clone3_set_tid = false;
if (opts.unprivileged && !has_cap_checkpoint_restore(opts.cap_eff))
Copy link
Member

Choose a reason for hiding this comment

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

Pretend it's not available instead of failing restore later when running unprivileged.

Can restore succeed if kdat.has_clone3_set_tid isn't set and criu is running w/o cap_sys_admin and cap_cr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It does it using the old method: by using ns_last_pid (via a RPC helper).

Copy link
Member

Choose a reason for hiding this comment

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

Let's write a comment to explain this in the code.

Copy link
Member

Choose a reason for hiding this comment

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

I think this isn't a right solution for the problem:

  • process can be restored in a separate user and pid namespaces and clone3() works fine in this case.
  • this function checks whether clone3 is supported or not, and it is separate from the dump/restore code. I think we have to move these checks to the code that restores processes with specified pids.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we should we treat EPERM here as success (clone3 with set_tid supported)? (And add a fallback path in the restoring code. [separate change])

Copy link
Member

Choose a reason for hiding this comment

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

yes, you are right.

criu/kerndat.c Outdated Show resolved Hide resolved
criu/proc_parse.c Outdated Show resolved Hide resolved
criu/kerndat.c Outdated Show resolved Hide resolved
criu/kerndat.c Outdated Show resolved Hide resolved
@osctobe osctobe force-pushed the assorted-fixes branch 2 times, most recently from 4ae575c to 6a97988 Compare August 28, 2023 12:11
@osctobe osctobe requested a review from avagin August 28, 2023 14:39
@osctobe osctobe force-pushed the assorted-fixes branch 2 times, most recently from b74e9a1 to 06819e6 Compare August 30, 2023 08:46
@avagin avagin changed the title Assorted fixes for kerndat and log messages kerndat: Skip clone3(set_tid) when unprivileged. Oct 5, 2023
@Snorch
Copy link
Member

Snorch commented Oct 24, 2023

Hello @avagin and @osctobe, I had one idea, which I like a lot, but guys in mainstream Linux faced it with total silence.

The idea was to allow clone3 syscall to alter owner user namespace of newly created namespaces (e.g. new pid namespace owner if CLONE_NEWPID is specified). https://lore.kernel.org/all/20210402155131.119872-1-ptikhomirov@virtuozzo.com/

This way using clone3 CRIU is able to create all restored processes in topmost user namespace available, while preserving namespace ownership topology. So at each clone3 call we would have all permissions needed by clone3_set_tid functionality. (Later we can switch to proper user namespace for each process to also preserve task's user namespaces.)

I believe my fix would help in this case too. @osctobe Can you, please, give it a try on your environment?

Copy link

A friendly reminder that this PR had no activity for 30 days.

clone3(set_tid) requires CAP_CHECKPOINT_RESTORE we might not have.
Assume that if it errored out with EPERM it's there and might be
usable from inside a user namespace.

Signed-off-by: Michał Mirosław <emmir@google.com>
@github-actions github-actions bot removed the stale-pr label Jan 10, 2024
@rst0git rst0git added the no-auto-close Don't auto-close as a stale issue label Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-auto-close Don't auto-close as a stale issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants