libkmod: Fix open file which some char device

use lseek SEEK_CUR to get whether it is a regular file,
lseek return -ESPIPE when fd is associated with a pipe, socket, or FIFO.

commit 883d931d1bd04b089b85b554d1df6f41dcf5fbf5 upstream
("modprobe: Allow passing path to module") allow to modprobe a file,
but not handle opening a FIFO device such as modprobe /dev/tty1.

commit 8d03b6c7d990af301950d3ecdc4b5c69fa525928 uptream
("libkmod: Use pread where appropriate") fix some cases,
such as open /dev/tty1, but not for /dev/vmnet0 or /dev/userio etc.

Can be reproduced in run lshw in root and install some vm such ad vmware,
more about the case are in the Link.

Reference: https://github.com/lyonel/lshw/pull/110
Closes: https://bugs.launchpad.net/ubuntu/+source/lshw/+bug/2069649
Closes: https://bbs.deepin.org.cn/post/291466
Reported-by: Qi Xu <xuqi@uniontech.com>
Reported-by: lionheartyu <dongshengyuan@uniontech.com>
Fixes: 883d931d1bd04 ("modprobe: Allow passing path to module")
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Reviewed-by: Lucas De Marchi <demarchi@kernel.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/407
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
1 file changed
tree: cfab97dcabb73935da2cdb670e77a02e52266c8c
  1. .github/
  2. libkmod/
  3. man/
  4. scripts/
  5. shared/
  6. shell-completion/
  7. testsuite/
  8. tools/
  9. .clang-format
  10. .codespellignore
  11. .editorconfig
  12. .gitignore
  13. .mailmap
  14. build-dev.ini
  15. CODING-STYLE.md
  16. CONTRIBUTING.md
  17. COPYING
  18. meson.build
  19. meson_options.txt
  20. NEWS
  21. README.md
README.md

kmod - Linux kernel module handling

OVERVIEW

kmod is a set of tools to handle common tasks with Linux kernel modules like insert, remove, list, check properties, resolve dependencies and aliases.

These tools are designed on top of libkmod, a library that is shipped with kmod. See libkmod/README.md for more details on this library and how to use it. The aim is to be compatible with tools, configurations and indexes from module-init-tools project.

Links

Compilation and installation

In order to compile the source code you need:

  • C11 compiler, supporting a range of GNU extensions - GCC 8+, Clang 6+
  • POSIX.1-2008 C runtime library - Bionic, GNU C library, musl

Optional dependencies, required with the default build configuration:

  • ZLIB library
  • LZMA library
  • ZSTD library
  • OPENSSL library (signature handling in modinfo)

Typical configuration and installation

meson setup builddir/
meson compile -C builddir/
sudo meson install -C builddir/

For end-user and distributions builds, it's recommended to use:

meson setup --buildtype release builddir/

Hacking

When working on kmod, use the included build-dev.ini file, as:

meson setup --native-file build-dev.ini builddir/

The testsuite can be executed with:

meson test -C builddir

It builds test kernel modules, so kernel headers need to be pre-installed. By default it tries to use the kernel header for the currently running kernel. KDIR=any environment variable can be used to tell it to use any installed kernel header or KDIR=/path/to/specific/headers when a specific one is needed. Example:

KDIR=any meson test -C builddir

Make sure to read our contributing guide and the other READMEs: libkmod and testsuite.

Compatibility with module-init-tools

kmod replaced module-init-tools, which was EOL'ed in 2011. All the tools were rewritten on top of libkmod and they can be used as drop in replacements. Along the years there were a few behavior changes and new features implemented, following feedback from Linux kernel community and distros.