uutils / uutils/coreutils

cp: `--archive` support on Android

Open
#3,477 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - cp wontfix
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

One of the things left for future work in #3396 was xattr support for Android, as part of the implementation for cp --archive. I tested that xattrs do work on Android, and we can set them, so the upstream xattr library we use merged a PR for Android support. Yay. \o/

However, after writing a patch to support it here, the relevant tests still fail on Android. Boo. /o\

Poking around with strace, it appears the problem is the SELinux xattrs. SELinux is part of Android's security model (i.e., how it prevents one app from mucking around with another app), and SELinux is implemented, in part, using security xattrs, so it makes sense that Android wouldn't allow us to touch those -- even though in our tests, the value we're trying to write is the value those files would have anyway (the source and dest are owned by us). I did an strace | grep xattr on GNU's cp --archive, and they're not calling any of the xattr syscalls on Android, even listxattr, which implies they simply chose not to support xattrs on that platform.

Right now, cp --archive is crashing for us on Android, and doesn't in GNU's implementation, so something needs to change. The question is what. The way I see it, we have 3 options:

  • Directly copy GNU behavior, and just drop support for xattrs entirely on Android. Pros: Nobody can really complain much, we're just matching the exiting tools. Cons: Seems like a waste to drop support entirely for just one unsupported xattr.
  • On Android, specifically skip security xattrs. Pros: Gives us support for every xattr we can use (AFAIK). Cons: Presumably root shells don't have this restriction, so if someone were running cp --archive in one, this would be unexpected.
  • Handle EACCES errors, and keep going with the rest of the copy, perhaps logging a warning to stderr. Pros: Guaranteed to handle all xattrs we can, even in edge cases like root shells. Cons: If we log, that'll show up in basically every cp --archive call on Android; if we don't log, we could potentially be silently swallowing an error the user would want to know about.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the implementation from #3396 and the linked Android test run, then review the Android xattr patch and the failing cp --archive tests. Compare the observed SELinux EACCES behavior with GNU cp on Android and determine which of the three proposed handling strategies the project should adopt. Done means cp --archive no longer crashes on Android and the relevant tests reflect the agreed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, rust
Domain
cli, operating-systems, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.