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

kmod: fix depmod crash on darwin #107824

Merged
merged 1 commit into from Mar 21, 2021
Merged

Conversation

mroi
Copy link
Contributor

@mroi mroi commented Dec 28, 2020

The kmod tools, most importantly depmod are needed when cross-compiling a Linux kernel on macOS (Darwin). Currently depmod will just segfault and I diagnosed the problem as follows:

  • all kmod tools are symlinked to one binary
  • this binary uses basename(argv[0]) to determine its personality
  • basename() requires the libgen.h header on Darwin, which is not included
  • the return type is thus assumed to be int
  • this causes the resulting char * (the actual return type) to be truncated to 32 bit
  • depmod crashes

The fix is to include libgen.h at a prominent location so that all invocations of basename() are covered.

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.

include the proper header for basename(), otherwise the returned
pointer is truncated to 32 bit because an int return type is assumed
@ofborg ofborg bot added 6.topic: darwin Running or building packages on Darwin 10.rebuild-darwin: 101-500 10.rebuild-linux: 0 labels Dec 28, 2020
@mroi
Copy link
Contributor Author

mroi commented Feb 15, 2021

As further motivation for this pull request: I have succeeded cross-compiling a recent Linux kernel on Darwin and this change is part of the picture.

@mroi
Copy link
Contributor Author

mroi commented Mar 9, 2021

Paging @matthewbauer: You made the last commit regarding kmod and Darwin compatibility. Sorry to bother you, but it looks like this package here has no clear maintainer?

@SuperSandro2000 SuperSandro2000 merged commit b1526be into NixOS:master Mar 21, 2021
@mroi mroi deleted the patch-kmod branch March 22, 2021 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants