forked from oditynet/virusSTOP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.patch
More file actions
155 lines (152 loc) · 5.46 KB
/
exec.patch
File metadata and controls
155 lines (152 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
--- exec.c 2025-07-24 09:58:43.000000000 +0300
+++ fs/exec.c 2025-08-02 14:16:34.620235544 +0300
@@ -22,6 +22,12 @@
* trying until we recognize the file or we run out of supported binary
* formats.
*/
+#include <linux/xattr.h>
+#include <linux/mnt_idmapping.h>
+
+#include <linux/fs.h>
+#include <linux/fs_types.h>
+
#include <linux/kernel_read_file.h>
#include <linux/slab.h>
@@ -1716,10 +1722,136 @@
*/
static int prepare_binprm(struct linux_binprm *bprm)
{
- loff_t pos = 0;
+ loff_t pos = 0;
+ ssize_t size;
+ char value[2];
+ struct dentry *dentry;
+ struct mnt_idmap *idmap;
+ struct inode *inode;
+ const char *fstype;
+
+ dentry = file_dentry(bprm->file);
+ idmap = file_mnt_idmap(bprm->file);
+ inode = d_inode(dentry);
+ fstype = inode->i_sb->s_type->name;
+
+ // Критическое исключение для tmpfs и других виртуальных ФС
+ if (strcmp(fstype, "tmpfs") == 0 ||
+ strcmp(fstype, "ramfs") == 0 ||
+ strcmp(fstype, "devtmpfs") == 0 ||
+ strcmp(fstype, "proc") == 0 ||
+ strcmp(fstype, "sysfs") == 0 ||
+ strcmp(fstype, "cgroup") == 0) {
+ goto read_file;
+ }
+
+ if (WARN_ON(!idmap)) {
+ printk(KERN_ERR "[bitX] Failed to get idmap for file: %s\n", dentry->d_name.name);
+ return -EPERM;
+ }
+
+ size = vfs_getxattr(idmap, dentry, "user.bitX", value, sizeof(value) - 1);
+
+ if (size == 1) {
+ value[1] = '\0';
+ if (value[0] == '0') {
+ printk(KERN_WARNING "[bitX] Execution denied: %s has user.bitX=0\n",
+ dentry->d_name.name);
+ return -EPERM;
+ }
+ } else if (size == -ENODATA) {
+ printk(KERN_INFO "[bitX] Execution NOT allowed (no bitX): %s\n", dentry->d_name.name);
+ return -EPERM;
+ //goto read_file;
+ } else if (size < 0) {
+ printk(KERN_WARNING "[bitX] Error %ld reading user.bitX for %s (FS: %s)\n",
+ size, dentry->d_name.name, fstype);
+ goto read_file;
+ }
+
+/*
+ const char *interpreter;
+ //char bitx_value[2];
+ const char *xattr_name = "user.bitX";
+ idmap = file_mnt_idmap(bprm->file);
+
+ //printk(KERN_ERR "[bitX] file: %s and %d\n", dentry->d_name.name, bprm->argc);
+
+ // Проверяем, является ли процесс интерпретатором (bash, perl, python и т. д.)
+ interpreter = bprm->filename;
+ char *kernel_script_path = NULL;
+ if (strstr(dentry->d_name.name, "bash") || strstr(dentry->d_name.name, "perl") || strstr(dentry->d_name.name, "python3") || strstr(dentry->d_name.name, "rust") ||strstr(dentry->d_name.name, "ruby") ||strstr(dentry->d_name.name, "php") ||strstr(dentry->d_name.name, "sed") || strstr(dentry->d_name.name, "python") || strstr(dentry->d_name.name, "sh") || strstr(dentry->d_name.name, "zsh")) {
+ const char *script_file = NULL;
+ if (bprm->argc > 1) {
+ char **argv = (char **)bprm->p;
+ script_file = argv[1];
+ //if (! script_file)
+ // script_file = bprm->interp;
+
+ char __user *user_path = (char __user *)bprm->p;
+ kernel_script_path = kmalloc(PATH_MAX, GFP_KERNEL);
+
+ if (!copy_from_user(kernel_script_path, user_path, PATH_MAX)) {
+ printk(KERN_ERR "[bitX] copy_from_user error\n");
+ kfree(kernel_script_path);
+ return -EFAULT;
+ }
+
+
+ script_file = kernel_script_path;
+ kfree(kernel_script_path);
+
+
+ if (script_file) {
+ struct path script_path;
+
+ printk(KERN_ERR "[bitX]1 %s %s | %s\n", bprm->interp,bprm->filename,script_file);
+
+ if (!kern_path( script_file, LOOKUP_FOLLOW, &script_path)) {
+ char *path_buf = kmalloc(PATH_MAX, GFP_KERNEL);
+ char *dpath = d_path(&script_path.dentry, path_buf, PATH_MAX);
+ printk(KERN_INFO "[bitX] Checking path: %s\n", dpath ? dpath : "(null)");
+
+ printk(KERN_ERR "[bitX] f1ile path: %s\n", script_path);
+ size = vfs_getxattr(idmap, script_path.d, xattr_name, value, sizeof(value));
+
+ kfree(path_buf);
+
+ path_put(&script_path);
+ printk(KERN_ERR "[bitX] file path1: %s\n", value);
+ //value[1] = '\0';
+ if (value[0] == '1') {
+ goto read_file;
+ }
+ if (size == 1) {
+ value[1] = '\0';
+ if (value[0] == '0') {
+ printk(KERN_WARNING "[bitX] Script denied execute: %s has user.bitX=0\n",script_file);
+ return -EPERM;
+ }
+ if (value[0] == '1') {
+ //printk(KERN_WARNING "[bitX] Script denied execute: %s has user.bitX=0\n",script_file);
+ //return -EPERM;
+ goto read_file;
+ }
+ } else if (size == -ENODATA) {
+ printk(KERN_INFO "[bitX] Script NOT allowed execute (no bitX): %s\n", script_file);
+ return -EPERM;
+ //goto read_file;
+ } else if (size < 0) {
+ printk(KERN_WARNING "[bitX] Error %ld reading user.bitX for %s (FS: %s)\n", size, script_file, fstype);
+ goto read_file;
+ }
+
+ }
+ }
+ }
+ }
- memset(bprm->buf, 0, BINPRM_BUF_SIZE);
- return kernel_read(bprm->file, bprm->buf, BINPRM_BUF_SIZE, &pos);
+*/
+read_file:
+ memset(bprm->buf, 0, BINPRM_BUF_SIZE);
+ return kernel_read(bprm->file, bprm->buf, BINPRM_BUF_SIZE, &pos);
}
/*