Commit Graph

451 Commits

Author SHA1 Message Date
Jim Huang
9543ca4e40 CI: Install libsqlite3 required by Sparse 2024-12-11 16:35:55 +08:00
Jim Huang
519033d2cc CI: Skip style with Cppcheck
For callback functions, we may not expect to changes their prototypes,
and this commit skips the corresponding checks.
2024-12-11 16:18:47 +08:00
Jim Huang
6e3aee651a
Merge pull request from Integral-Tech/update-ci
CI: Update Ubuntu, gcc & clang-format
2024-11-13 05:57:49 +08:00
Integral
2c29aef35f
CI: Update Ubuntu, gcc & clang-format 2024-11-12 17:09:24 +08:00
Integral
885da47d5b
Add missing close() and use EXIT_FAILURE macro ()
In cat_nonblock.c, function call of close() is missing, which could
lead to resource leak. Besides, using EXIT_FAILURE macro defined in
stdlib.h provides better readability.
2024-11-12 14:14:20 +08:00
Jim Huang
60d391509f
Merge pull request from Integral-Tech/simplify-enum
Remove unnecessary enum assignments
2024-11-11 19:53:56 +08:00
Jim Huang
af8a3e6572
Merge pull request from Integral-Tech/remove-unused-sudo
Remove unnecessary sudo
2024-11-11 19:52:11 +08:00
Integral
980d8f3b30
Remove unnecessary enum assignments 2024-11-11 18:51:47 +08:00
Integral
6d9d12717a
Remove unnecessary sudo
In some commands such as "lsmod", root permission is not required.
2024-11-11 18:32:47 +08:00
Jim Huang
f3405fecd9
Merge pull request from Integral-Tech/replace-make
Replace make with $(MAKE) in Makefile
2024-11-11 14:03:42 +08:00
Integral
56c16b9ba0
Replace make with $(MAKE) in Makefile
According to GNU Make Manual,

Recursive make commands should always use the variable MAKE, not
the explicit command name "make".
2024-11-11 13:57:43 +08:00
Jim Huang
9c39011c21
Merge pull request from NOVBobLee/fix_err_handle
Fix missing function call in error handling path
2024-11-05 20:35:58 +08:00
Bob Lee
620bb0f5f8
Fix missing function call in error handling path
Previously, the code did not call kobject_put when sysfs_create_file
failed, leading to a potential memory leak. This commit adds the missing
kobject_put to ensure proper resource cleanup.
2024-11-05 19:48:42 +08:00
Jim Huang
e3e2ee35af
Merge pull request from NOVBobLee/fix_memleak
Fix potential memory leak in vinput
2024-10-26 23:31:39 +08:00
Bob Lee
b482911efb
Fix potential memory leak in vinput
In the export_store function, the error handling paths followed a
successful vinput_alloc_vdevice call are missing a corresponding
input_free_device call. Since vinput_alloc_vdevice internally calls
input_allocate_device, and input_register_device has not been called
yet, input_free_device should be used to properly free the allocated
input_device struct in this scenario[1].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/input/input.c#n2094
2024-10-25 12:22:29 +08:00
Jim Huang
67713859df
Merge pull request from NOVBobLee/fix_refcnt
Fix potential reference count leak in vinput
2024-10-25 11:06:51 +08:00
Bob Lee
3ec01e2cf1
Fix potential reference count leak in vinput
In the export_store function, when vinput_register_vdevice fails, the
current error handling process calls device_unregister followed by
vinput_destroy_vdevice. However, the device_unregister here triggers its
release function, which already includes a call to
vinput_destroy_vdevice. As a result, vinput_destroy_vdevice is called
twice. Since vinput_destroy_vdevice contains module_put, this double
call must be avoided to prevent potential reference count issues.
2024-10-24 19:24:01 +08:00
Jim Huang
ac1894673d
Merge pull request from NOVBobLee/pr
Fix incorrect failure handling in vinput_init
2024-10-21 02:42:13 +08:00
Bob Lee
9b89d0ca04
Fix incorrect failure handling in vinput_init
After class_register failure, the wrong function class_unregister was
used. The correct cleanup function should be unregister_chrdev, as
register_chrdev was used before class_register.
2024-10-21 00:33:06 +08:00
Jim Huang
e2b1756efc
Merge pull request from ChinYikMing/fix/typo
Fix typo
2024-10-17 09:00:32 +08:00
ChinYikMing
4002426f7a Fix typo
The "Message" should be in lower case, so that it matches the variable
which declared as "message".
2024-10-17 02:23:21 +08:00
Jim Huang
756871e427
Merge pull request from NOVBobLee/pr_patch
Correct the function type
2024-10-09 00:56:51 +08:00
Bob Lee
93b35f7819
Fix function declaration
The function pointer type of myvariable_store was incompatible with the
store member of struct kobj_attribute, leading to a compilation error
when the type conversion (void *) was omitted. This patch corrects the
function declaration and eliminates the need for type conversion.
2024-10-09 00:45:04 +08:00
Jim Huang
3203aa3ce5
Merge pull request from NOVBobLee/pr_patch2
Remove the redundant code
2024-10-08 21:27:38 +08:00
Bob Lee
2a04a64041
Remove the redundant code
As myvariable is declared as an integer, it is meaningless that putting
u after %d in the format specifier of sscanf for scanning an integer.
This patch removes the u in the format specifier for avoiding
misleading.
2024-10-08 12:21:25 +08:00
Jim Huang
2eadbb1ecf
Merge pull request from NOVBobLee/pr_patch
Fix a wierd behavior of a function
2024-10-07 12:11:10 +08:00
Bob Lee
d1d2a2b031
Fix a weird behavior of a function
The procfile_write prints the content what user writes into. However,
when the content size is greater than or equal to PROCFS_MAX_SIZE,
procfile_write will print nothing, because the index for appending the
tail NULL character will be modulo to 0, which is an off-by-one error.

This fixes the problem by changing the upper bound of procfs_buffer_size
to (PROCFS_MAX_SIZE - 1), leaving one byte for NULL character. After
the change, we can discard the modulo because the range of
procfs_buffer_size is already between 0 and (PROCFS_MAX_SIZE - 1).
2024-10-07 12:05:43 +08:00
Jim Huang
1fc5305714
Merge pull request from NOVBobLee/pr_patch
Remove the redundant code
2024-10-06 21:20:39 +08:00
Bob Lee
8c641a2deb
Remove the redundant code
proc_remove does nothing when the argument is NULL[1]. We don't need
proc_remove after proc_create failed.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/proc/generic.c#n789
2024-10-06 14:25:49 +08:00
Jim Huang
3a09a1e473 Apply editorial changes 2024-10-05 12:01:45 +08:00
Jim Huang
31a14a036c
Merge pull request from sysprog21/ci-bump
CI: Bump dependency versions
2024-10-05 11:51:02 +08:00
Jim Huang
b1f0c58575 CI: Bump dependency versions 2024-10-05 11:49:44 +08:00
Jim Huang
eb5b4636c4
Merge pull request from algonell/master
Fix typos
2024-10-05 11:45:01 +08:00
Andrew Kreimer
98201b85aa Fix typos via codespell
atleast -> at least
encouter -> encounter
2024-10-04 19:08:50 +03:00
Jim Huang
47663d6aa1
Merge pull request from Ayxan13/fix-sleep-toctou
Fix blocking O_NONBLOCK process bug
2024-08-12 09:34:04 +08:00
Aykhan Hagverdili
4adbf1dd9b Fix: blocking O_NONBLOCK process bug in sleep.c
There is a subtle bug that if the atomic flag changes
between the time it was checked and the second time
it was checked, sleep.c would potentially block a
process that had specified O_NONBLOCK. This fixes
the bug by using atomic_cmpxchg instead of atomic_read.
2024-08-11 21:56:09 +02:00
Andrew Lin
84cc7fee1c
Fix typo ()
Change return-object programming to return-oriented programming.
2024-07-22 01:56:37 +08:00
Hao.Dong
950408472e
Add a hook on syscall using Kprobes under x86 ()
For x86 architecture, the system call table cannot be used to invoke
a system call after commit 1e3ad78 since v6.9. This commit has been
backported to long term stable kernels, like v5.15.154+, v6.1.85+,
v6.6.26+ and v6.8.5+[1]. In this case, thanks to Kprobes, a hook can be
used instead on the system call entry to intercept the system call.

[1] https://stackoverflow.com/a/78607015

Co-authored-by: Hao Dong <hao.dong.work@outlook.com>
2024-07-05 07:40:53 +08:00
Jim Huang
032d1b8c0c
Merge pull request from jouae/master
Fix a typo
2024-07-04 02:12:50 +08:00
jouae
74a450ba92
Fix a typo
Delete the duplicate word "otherwise"

Before and after:
otherwise, otherwise -> otherwise
2024-07-03 18:46:45 +08:00
Jim Huang
7bcc4fbf46
Merge pull request from pao0626/command-permission-changes
Add sudo for file access permissions
2024-07-03 17:04:14 +08:00
HJ Pao
be16ad6710 Add sudo for file access permissions
Add sudo to commands in Chapter 8 for example module interaction.

The "myvariables" in the module are set with 0660 permissions
via __ATTR(), preventing direct user access.

Options to fix this:
1. Instruct users to use 'sudo' to read/write files.
2. Relax the permission settings to 0666.

This commit adopts the sudo method to maintain security constraints.
2024-07-03 16:31:53 +08:00
Jim Huang
031b9d2b39
Merge pull request from jouae/master
Modify the descritions of seq_file and flowchart
2024-07-03 00:04:38 +08:00
jouae
7a6dd1f582
Modify the descritions of seq_file and flowchart
7.4 The seq_file is missing the behavior that occurs when it
directly returns NULL after the start step.

Also, in the flowchart, the first decision where `return is NULL`
is `Yes` points to nothing, which is not defined in ISO 5807.

ISO 5807 section 10.3.1.2 states logic path of a decision,
"Each exit from a symbol be accompanied by the appropriate
condition values to show the logic path which it represents,
so that the conditions and the associated references are identified."

The behavior of pointing to nothing does not have associated
references and does not indicate the relation of this logic path.

Refs:
	1. The Liunx Kernel Module Programming Guide
	   7.4 Manage /proc file with seq_file
	2. ISO-5807-1985
2024-07-02 23:47:43 +08:00
Jim Huang
1d3943a72b CI: Enforce newline at end of files
Reference:
https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e
2024-06-21 16:39:05 +08:00
Jim Huang
b5709f89f8 Update contributor list 2024-05-26 01:49:53 +08:00
Jim Huang
e1eced6d2f
Merge pull request from visitorckw/fix-vinput
vinput: Fix multiple issue
2024-05-15 05:54:44 +08:00
Kuan-Wei Chiu
0a23ecd027 vinput: Fix incorrect handling on raw_copy_to_user() failure
When raw_copy_to_user() failed in vinput_read(), the function would set
'count' to -EFAULT and then subtract EFAULT from '*offset'. However,
modifying '*offset' on raw_copy_to_user() failure was incorrect. Fix
this behavior by changing count = -EFAULT to return -EFAULT.
2024-05-09 02:01:18 +08:00
Kuan-Wei Chiu
c068fa47e9 vinput: Fix NULL pointer dereference caused by failed kzalloc allocation
When kzalloc fails to allocate memory and returns NULL, it leads to a
NULL pointer dereference error later on. Add a check for the return
value of kzalloc. When kzalloc fails to allocate memory, it prints an
error message and returns ERR_PTR(-ENOMEM).
2024-05-09 02:01:14 +08:00
Kuan-Wei Chiu
1e26743c30 vinput: Remove redundant memset call
Remove redundant memset calls as memory allocated with kzalloc is
already zeroed due to the presence of the __GFP_ZERO gfp flag.
2024-05-09 01:38:14 +08:00