πŸŽ“ BookMCQ
← Back to 18. The Linux System

πŸ“ Kernel Modules of Linux system (13 MCQs)

Loadable Extensions to the Linux Kernel

Linux kernel modules are separately compiled components that can be loaded into or removed from a running kernel. They commonly provide device drivers, filesystem support, and additional kernel functionality. Modules execute with kernel privileges and use defined kernel interfaces, allowing a modular monolithic kernel to support hardware and features without compiling every component directly into the main kernel image.

Why Optional Functionality Is Kept Outside the Core Image

Compiling every driver and optional subsystem into one kernel would increase its size and require rebuilding it whenever support changes. Loadable modules allow functionality to be installed and activated when required. This flexibility also supports hardware discovery and specialised deployments, although modules must match the running kernel's interfaces and configuration.

Module Loading, Initialisation and Removal

A module file, commonly ending in .ko, contains compiled kernel code and metadata. The kernel loader checks compatibility and dependencies, then runs the module's initialisation routine. When removal is permitted, its exit routine releases resources and unregisters services. The kernel refuses removal when dependencies or active usage prevent safe unloading.

Example of Loading a Network Driver Module

An administrator loads a compatible wireless driver module into a running Linux kernel. The module registers its driver functionality, allowing supported hardware to be managed by the networking subsystem. The kernel can then expose the network interface for configuration and packet transmission, provided the device and driver match.

Hardware Flexibility and Kernel Security Risks

Modules reduce the need to rebuild the complete kernel and allow device support to be added dynamically. However, a faulty or malicious module can access privileged memory and compromise the entire system. Kernel version compatibility, module signing policies, dependency management, and trusted sources are therefore important.

Misconceptions About Kernel Modules

'A kernel module runs as an ordinary user process' is false because it executes in kernel space. 'Every module can be unloaded at any time' ignores active dependencies and usage. 'Modules never affect kernel stability' overlooks their privileged access and ability to cause system-wide faults.

Exam Focus: Module Files and Kernel Integration

Explain why Linux uses loadable modules and identify their initialisation and removal routines. Distinguish compiled-in kernel features from loadable .ko components. Questions may ask how dependencies affect unloading or why module compatibility and trusted code sources matter for system security.

Key Terms of Linux Kernel Modules

  • Module - Loadable kernel extension.
  • .ko - Linux kernel object module file.
  • Init routine - Function preparing a module for use.
  • Exit routine - Function releasing module resources.
  • Dependency - Requirement for another module.
3
Easy
7
Medium
3
Hard

πŸ“ All Kernel Modules of Linux system MCQs

Q1. A system admin wants to add support for a new USB device without rebuilding the kernel. Which command should they use to load the corresponding module?

A.insmod
B.modprobe βœ…
C.rmmod
D.lsmod
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: The correct answer is B because modprobe not only inserts the module but also resolves any dependent modules automatically, which is essential for real hardware support. insmod (A) only loads a single file and would fail if dependencies are missing. rmmod (C) removes modules, and lsmod (D) only lists currently loaded modules, so they cannot add support. In practice, using modprobe streamlines driver deployment on a running system.

Q2. What is the main benefit of loadable kernel modules compared to compiling drivers directly into the kernel?

A.Reduces memory usage
B.Allows runtime loading and unloading βœ…
C.Improves network speed
D.Eliminates need for root privileges
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Option B is correct because modules can be inserted or removed while the kernel is running, letting administrators add or update functionality without rebooting. Reducing memory usage (A) is a side effect, not the primary advantage. Network speed (C) is unrelated, and root privileges (D) are still required to load modules, so those options are incorrect. This flexibility is why many drivers are distributed as modules.

Q3. Under which license must a kernel module be released to be accepted into the mainline Linux kernel?

A.MIT βœ…
B.GPL
C.Apache
D.BSD
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: The Linux kernel only accepts modules that are released under the GPL (or compatible) license, making B the correct choice. The GPL ensures that source code remains available and that derivative works share the same freedoms. MIT (A), Apache (C), and BSD (D) are permissive licenses but are not sufficient for inclusion in the mainline kernel, so they would be rejected.

Q4. A developer compiled a module named netfilter.ko but receives an error about missing symbols when loading it with insmod. Which tool should they use to automatically resolve dependencies before loading?

A.depmod βœ…
B.modinfo
C.ldd
D.grep
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: Option A, depmod, is correct because it scans modules, builds a dependency map, and updates the modules.dep file, allowing the loader to resolve missing symbols. modinfo (B) only displays information about a module, ldd (C) works for user‑space libraries, and grep (D) is a generic text search tool; none of these handle kernel symbol dependencies. Using depmod prevents symbol errors in real deployments.

Q5. During testing, a kernel module crashes the system after being loaded. Which command can be used to unload it safely without rebooting?

A.rmmod
B.modprobe -r βœ…
C.unloadmod
D.killmod
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: The correct answer is B; modprobe -r removes a module and also unloads any modules that depend on it, ensuring a clean state. rmmod (A) can also remove a module but does not handle dependencies, so it may leave orphaned modules and cause instability. unloadmod (C) and killmod (D) are not real commands in Linux, making them incorrect choices.

Q6. A sysadmin wants to prevent a specific module from being loaded automatically at boot. Which file should they edit to blacklist the module?

A./etc/modprobe.d/blacklist.conf βœ…
B./boot/grub.cfg
C./etc/fstab
D./etc/modules-load.d/modules.conf
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: Option A is correct because blacklist.conf in /etc/modprobe.d is read by modprobe and can contain lines like 'blacklist <module>', preventing automatic loading. The GRUB configuration (B) controls bootloader options, not module loading. /etc/fstab (C) mounts filesystems, and /etc/modules-load.d/modules.conf (D) lists modules to load, not to block them. Editing the blacklist file directly stops the unwanted module at boot.

Q7. When building a custom kernel module, the makefile uses the variable KERNELDIR. Which directory should KERNELDIR point to to ensure proper compilation against the running kernel?

A./usr/src/linux βœ…
B./lib/modules/$(uname -r)/build
C./etc/kernel
D./opt/kernel
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: The correct path is B, /lib/modules/$(uname -r)/build, because it is a symlink to the headers and build environment that match the currently running kernel version. /usr/src/linux (A) may contain source for a different kernel version, leading to mismatched symbols. /etc/kernel (C) and /opt/kernel (D) are not standard locations for kernel build trees, so they would not provide the needed files.

Q8. Why does the Linux kernel require that external modules be licensed under GPL to be merged into the mainline tree?

A.To protect intellectual property
B.To ensure source availability βœ…
C.To improve performance
D.To simplify debugging
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Option B is correct because the GPL license obligates developers to make source code available, aligning with the kernel's open‑source philosophy and allowing anyone to audit or modify the code. Protecting IP (A) is opposite to the GPL’s intent, and performance (C) or debugging simplicity (D) are not reasons for the licensing requirement. This policy maintains transparency and collaboration across the community.

Q9. A module uses a symbol that was exported with EXPORT_SYMBOL_GPL. What will happen if the module is compiled with a non‑GPL license and loaded?

A.It loads but with warnings
B.It fails to load due to symbol not found βœ…
C.It loads but disables GPL features
D.It automatically changes its license to GPL
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: The correct answer is B; the kernel will reject the module because symbols marked EXPORT_SYMBOL_GPL are only available to GPL‑licensed modules, resulting in an \unknown symbol\ error at load time. Loading with warnings (A) does not happen, and the kernel does not alter a module's license (D). Option C is incorrect because the module simply cannot load, preventing any partial functionality.

Q10. During runtime, a loaded module creates a /proc entry to expose statistics. Which kernel API function should be used to create this entry safely?

A.create_proc_entry
B.proc_create βœ…
C.proc_mkdir
D.proc_register
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: proc_create (B) is the modern and safe API for creating entries in the /proc filesystem; it handles reference counting and works with the newer procfs infrastructure. create_proc_entry (A) is deprecated and can lead to memory leaks. proc_mkdir (C) only creates directories, not files, and proc_register (D) does not exist in the kernel API. Using proc_create ensures stability in production environments.

Q11. How does using loadable kernel modules improve system security compared to having all drivers built into the kernel?

A.They run in user space
B.They can be signed and verified before loading
C.They reduce attack surface by only loading needed code βœ…
D.They prevent any kernel bugs
πŸ’‘ Difficulty: medium | βœ… Correct: C

πŸ“– Explanation: Option C is correct because loading only the necessary modules limits the amount of privileged code residing in memory, thereby shrinking the potential attack surface. Running in user space (A) is false; modules execute in kernel mode. While signing (B) adds verification, it does not inherently reduce exposure. Claiming that modules prevent kernel bugs (D) is unrealistic; bugs can still exist in loaded code.

Q12. What is the relationship between the 'modprobe' command and the '/etc/modprobe.d' configuration files?

A.modprobe reads those files to apply options and blacklists βœ…
B.modprobe writes to those files
C.Those files are only used by insmod
D.They store compiled module binaries
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: The correct answer is A; modprobe parses the files in /etc/modprobe.d to apply module parameters, aliases, and blacklist directives before loading a module. It does not write to these files (B), nor are they used by insmod (C) which ignores configuration files. The directory does not contain compiled binaries (D); it holds plain‑text configuration that influences module loading behavior.

Q13. Explain why a kernel module cannot safely use standard C library functions like printf without special handling.

A.Because the kernel lacks a userspace library βœ…
B.Because printf is not thread‑safe
C.Because using libc would cause licensing issues
D.Because kernel code must avoid dynamic memory allocation
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: Option A is correct because the kernel runs without the standard C library (libc) and therefore cannot call functions like printf that depend on user‑space facilities. The thread‑safety concern (B) is secondary, and licensing (C) is not the primary technical barrier. While dynamic allocation (D) is allowed in the kernel, it must use kernel‑specific APIs, not libc. Hence, kernel modules must use printk or related kernel logging facilities.

πŸ”— Related Topics (MCQs)