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

fix canon-cups-ufr2 for previously broken printers #79689

Closed
wants to merge 1 commit into from

Conversation

kazcw
Copy link
Contributor

@kazcw kazcw commented Feb 10, 2020

The ufr2 driver relies on black-box binaries from Canon, with baked-in FHS assumptions. Previously, a LD_PRELOAD shim has been used to adapt calls to some libc functions and correct the path arguments passed. Unfortunately, this hack doesn't work for all printers; some of the Canon libraries rely on invoking syscalls directly, and can't be mollified with ld.so tricks.

And so blacker arts were needed. Introduce a wrapper that uses ptrace to intercept all syscalls performed by the binary; when a supported syscall is identified, read its path argument from the binary's address space, see if it's a broken FHS path, and if necessary inject a corrected path into the process's address space before allowing the fixed-up syscall to proceed.

This has some pros and cons. The cons:

  • ptrace is sometimes restricted (it's allowed under the default NixOS config though)
  • ptrace is only available on Linux (but I think installing cups drivers through nix only makes sense on NixOS?)
  • there's a minor performance penalty (syscalls cost several times as much)
  • it's crazy (this binary doesn't seem to do any of the things that might break it, though)

The pros:

  • got my D530 working (just in time to print that shipping label...)
  • it's a general solution; it should work for any printer that uses this driver, and it should work for future versions of the driver

Fixes #44330

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

The ufr2 driver relies on black-box binaries from Canon, with baked-in
FHS assumptions. Previously, a `LD_PRELOAD` shim has been used to adapt
calls to some libc functions and correct the path arguments passed.
Unfortunately, this hack doesn't work for all printers; some of the
Canon libraries rely on invoking syscalls directly, and can't be
mollified with `ld.so` tricks.

And so blacker arts were needed. Introduce a wrapper that uses `ptrace`
to intercept all syscalls performed by the binary; when a supported
syscall is identified, read its path argument from the binary's address
space, see if it's a broken FHS path, and if necessary inject a
corrected path into the process's address space before allowing the
fixed-up syscall to proceed.

This has some pros and cons. The cons:
- `ptrace` is sometimes restricted (it's allowed under the default NixOS
  config though)
- there's a minor performance penalty (syscalls cost several times as
  much)
- it's crazy (this binary doesn't seem to do any of the things that
  might break it, though)
The pros:
- got my D530 working (just in time to print that shipping label...)
- it's a general solution; it should work for any printer that uses this
  driver, and it should work for future versions of the driver
@veprbl
Copy link
Member

veprbl commented Feb 10, 2020

Can't you just use proot?

@stale

This comment has been minimized.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 8, 2020
@SuperSandro2000
Copy link
Member

Is this PR still relevant?

@kylesferrazza
Copy link
Member

Is this PR still relevant?

Unsure.. I no longer have a Canon printer, so can't test @kazcw's changes here.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 25, 2021
@stale
Copy link

stale bot commented Sep 21, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 21, 2021
@veprbl veprbl mentioned this pull request Jan 19, 2022
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: printing 10.rebuild-darwin: 0 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when printing to canon printer
4 participants