Closed Bug 1693462 Opened 5 years ago Closed 5 years ago

Avoid quarantine attribute being set when using nsILocalFile.copyTo* on macOS

Categories

(Core :: XPCOM, task)

task

Tracking

()

RESOLVED FIXED
88 Branch
Tracking Status
firefox88 --- fixed

People

(Reporter: glandium, Assigned: glandium)

References

Details

Attachments

(1 file)

A bunch of unit tests are failing on experimental arm64 workers (bug 1693134) because they copy some executables around (for good reasons) before executing the copies, but the copies receive the quarantine attribute because of LSFileQuarantineEnabled being set at the Firefox level (https://searchfox.org/mozilla-central/rev/d504494eab038fd1bbc82eb4191bb334b4de2c8d/browser/app/macbuild/Contents/Info.plist.in#237).

I think a reasonable way to handle the situation to make the copyTo* methods of nsILocalFile avoid setting the quaranting attribute when the file that is being copied doesn't have it.

There are three ways I can see us solving this:

  • calling getxattr(old_path, "com.apple.quarantine", nullptr, 0, 0 , 0) and if that returns ENOATTR, call removexattr(new_path, "com.apple.quarantine")
  • similarly-ish, calling fgetxattr(...) and fremovexattr(...)`, but that requires getting into NSPR internals that are not exposed (which we kind of do on Windows for the append mode since bug 331453)
  • use copyfile() instead of NSPR on mac.

Nika, what do you think?

Flags: needinfo?(nika)

There are variations around copyfile, where it can be used to just copy the ACL/extended attributes, but also to copy the data, and there's fcopyfile too, which does the same thing with fds, so the 2 first ways above could also use copyfile/fcopyfile. ETOOMANYCHOICES.

Given that apple actively maintains a copyfile library with their OS for this use-case, I think our best option for forward-compatibility is probably to switch nsLocalFile::CopyToNative to shell out to copyfile under the hood, rather than maintaining our own implementation on top of NSPR. I'm sure there are other xattrs which we're failing to copy over properly as well, and by using their method it's more likely stuff will continue to work in the future. I'm optimistic we won't run into too many compatibility issues if we switch over, but perhaps we can reconsider if we do.

Flags: needinfo?(nika)
Flags: needinfo?(mh+mozilla)

I admit to not knowing much about nsLocalFile, but I did attempt to use OSX copyfile and this isn't working so well:
https://treeherder.mozilla.org/jobs?repo=try&revision=f93632f6d04c52b5b5aea9c3ad2c832ad6409655

I was hoping to hack something together as a proof of concept, I have tried a few flag combinations, but possibly I am failing there to do what is right.

happy to hack more if this is the right direction.

(In reply to Joel Maher ( :jmaher ) (UTC -0800) from comment #3)

I admit to not knowing much about nsLocalFile, but I did attempt to use OSX copyfile and this isn't working so well:
https://treeherder.mozilla.org/jobs?repo=try&revision=f93632f6d04c52b5b5aea9c3ad2c832ad6409655

I was hoping to hack something together as a proof of concept, I have tried a few flag combinations, but possibly I am failing there to do what is right.

happy to hack more if this is the right direction.

Your patch is using COPYFILE_MOVE, which is not what you'd want for a function that copies a file.

Flags: needinfo?(mh+mozilla)

quick update, adjusting some flags AND identifying a directory then CopyDirectoryTo(), seems to solve most of the problems- I was testing on OSX 10.14 where things work, more data and I should know if I have something which could welcome more feedback.

I would think I should have two different methodsinstead of hacking inside the same method:

#if defined(XP_MACOSX)
nsLocalFile::CopyToNative(nsIFile* aNewParent, const nsACString& aNewName) {
  // copyfile()
}
#else
nsLocalFile::CopyToNative(nsIFile* aNewParent, const nsACString& aNewName) {
  // existing implementation
}
#endif

there are also some references to: #ifdef DEBUG_blizzard that appear to be 20+ years old, should those be removed?

I'm guessing a bit here, but based on comment 2 talking about extended attributes, and seeing:

 copyfile_flags_t flags = COPYFILE_DATA;

versus

https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/copyfile.3.html

we might want COPYFILE_ALL instead?

Joel clarified on Slack that COPYFILE_ALL is what he tried first.

So we expect this to mean that LSFileQuarantineEnabled overrides the copyfile arguments and we still end up with a quarantined file.

We could use getxattr/fgetxattr to log the file attributes before and after the copy operation to confirm if the quarantine attribute is still being set.

As an alternative to this more automatic approach, we could have test code remove the quarantined attribute before trying to execute the binary.

(In reply to Haik Aftandilian [:haik] from comment #9)

So we expect this to mean that LSFileQuarantineEnabled overrides the copyfile arguments and we still end up with a quarantined file.

We could use getxattr/fgetxattr to log the file attributes before and after the copy operation to confirm if the quarantine attribute is still being set.

I confirmed this is what happens.

As an alternative to this more automatic approach, we could have test code remove the quarantined attribute before trying to execute the binary.

I started doing that, and in face of the number there are, I filed this bug. I guess the simpler thing to do is the first proposal in comment 0.

Assignee: nobody → mh+mozilla

Joel, can you give the attached patch a spin?

Flags: needinfo?(jmaher)

here is a try push:
https://treeherder.mozilla.org/jobs?repo=try&revision=5a51c1059f33b556ac7a6474b49a3378bb85e489&selectedTaskRun=KzYCxuvqQg6aTbpXHhJPkg.0

overall I think this is working, the errors I get are much different and it seems that shippable isn't required for the aus tests. here is a reference from a few weeks ago:
https://treeherder.mozilla.org/jobs?repo=try&searchStr=macosx1100-64%2Cxpcshell&revision=4eed037ddb35c7e316d418a0d4a459648e0e8d49

Flags: needinfo?(jmaher)
Pushed by mh@glandium.org: https://hg.mozilla.org/integration/autoland/rev/5aec36bc42a3 Avoid quarantine attribute being set when using nsILocalFile.copyTo* on macOS. r=nika
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 88 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: