Bitdefender Hypervisor Memory Introspection
lixddefs.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 //
6 // Contains various defines & structures (that aren't changed often) form the linux kernel,
7 // adapted for using by introspection.
8 //
9 #ifndef _LIXDEFS_H_
10 #define _LIXDEFS_H_
11 
12 //
13 // fork() flags
14 //
15 #define CSIGNAL 0x000000ff // signal mask to be sent at exit
16 #define CLONE_VM 0x00000100 // set if VM shared between processes
17 #define CLONE_FS 0x00000200 // set if fs info shared between processes
18 #define CLONE_FILES 0x00000400 // set if open files shared between processes
19 #define CLONE_SIGHAND 0x00000800 // set if signal handlers and blocked signals shared
20 #define CLONE_PTRACE 0x00002000 // set if we want to let tracing continue on the child too
21 #define CLONE_VFORK 0x00004000 // set if the parent wants the child to wake it up on mm_release
22 #define CLONE_PARENT 0x00008000 // set if we want to have the same parent as the cloner
23 #define CLONE_THREAD 0x00010000 // Same thread group?
24 #define CLONE_NEWNS 0x00020000 // New namespace group?
25 #define CLONE_SYSVSEM 0x00040000 // share system V SEM_UNDO semantics
26 #define CLONE_SETTLS 0x00080000 // create a new TLS for the child
27 #define CLONE_PARENT_SETTID 0x00100000 // set the TID in the parent
28 #define CLONE_CHILD_CLEARTID 0x00200000 // clear the TID in the child
29 #define CLONE_DETACHED 0x00400000 // Unused, ignored
30 #define CLONE_UNTRACED 0x00800000 // set if the tracing process can't force CLONE_PTRACE on this clone
31 #define CLONE_CHILD_SETTID 0x01000000 // set the TID in the child
32 #define CLONE_NEWUTS 0x04000000 // New utsname group?
33 #define CLONE_NEWIPC 0x08000000 // New ipcs
34 #define CLONE_NEWUSER 0x10000000 // New user namespace
35 #define CLONE_NEWPID 0x20000000 // New pid namespace
36 #define CLONE_NEWNET 0x40000000 // New network namespace
37 #define CLONE_IO 0x80000000 // Clone io context
38 
39 
40 // currently active flags
41 #define VM_READ 0x00000001
42 #define VM_WRITE 0x00000002
43 #define VM_EXEC 0x00000004
44 #define VM_SHARED 0x00000008
45 
46 // limits for mprotect() etc
47 #define VM_MAYREAD 0x00000010
48 #define VM_MAYWRITE 0x00000020
49 #define VM_MAYEXEC 0x00000040
50 #define VM_MAYSHARE 0x00000080
51 
52 #define VM_GROWSDOWN 0x00000100 // general info on the segment
53 #define VM_UFFD_MISSING 0x00000200 // missing pages tracking
54 #define VM_PFNMAP 0x00000400 // Page-ranges managed without "struct page", just pure PFN
55 #define VM_DENYWRITE 0x00000800 // ETXTBSY on write attempts
56 #define VM_UFFD_WP 0x00001000 // write-protect pages tracking
57 
58 #define VM_LOCKED 0x00002000
59 #define VM_IO 0x00004000 // Memory mapped I/O or similar
60 
61 // Used by sys_madvise()
62 #define VM_SEQ_READ 0x00008000 // App will access data sequentially
63 #define VM_RAND_READ 0x00010000 // App will not benefit from clustered reads
64 
65 #define VM_DONTCOPY 0x00020000 // Do not copy this vma on fork
66 #define VM_DONTEXPAND 0x00040000 // Cannot expand with mremap()
67 #define VM_LOCKONFAULT 0x00080000 // Lock the pages covered when they are faulted in
68 #define VM_ACCOUNT 0x00100000 // Is a VM accounted object
69 #define VM_NORESERVE 0x00200000 // should the VM suppress accounting
70 #define VM_HUGETLB 0x00400000 // Huge TLB Page VM
71 #define VM_ARCH_1 0x01000000 // Architecture-specific flag
72 #define VM_ARCH_2 0x02000000
73 #define VM_DONTDUMP 0x04000000 // Do not include in the core dump
74 
75 #define VM_SOFTDIRTY 0x08000000 // Not soft dirty clean area
76 
77 #define VM_MIXEDMAP 0x10000000 // Can contain "struct page" and pure PFN pages
78 #define VM_HUGEPAGE 0x20000000 // MADV_HUGEPAGE marked this vma
79 #define VM_NOHUGEPAGE 0x40000000 // MADV_NOHUGEPAGE marked this vma
80 #define VM_MERGEABLE 0x80000000 // KSM may merge identical pages
81 
82 
83 
84 //
85 // Self reference
86 //
87 #define LINUX_PROC_SELF_REFERENCE "/proc/self/exe"
88 #define LINUX_PROC_DIR "/proc/"
89 
90 
91 //
92 // ptrace requests
93 //
94 #define PTRACE_TRACEME 0
95 #define PTRACE_PEEKTEXT 1
96 #define PTRACE_PEEKDATA 2
97 #define PTRACE_PEEKUSR 3
98 #define PTRACE_POKETEXT 4
99 #define PTRACE_POKEDATA 5
100 #define PTRACE_POKEUSR 6
101 #define PTRACE_CONT 7
102 #define PTRACE_KILL 8
103 #define PTRACE_SINGLESTEP 9
104 
105 #define PTRACE_GETREGS 12
106 #define PTRACE_SETREGS 13
107 #define PTRACE_GETFPREGS 14
108 #define PTRACE_SETFPREGS 15
109 #define PTRACE_GETFPXREGS 18
110 #define PTRACE_SETFPXREGS 19
111 
112 #define PTRACE_ATTACH 16
113 #define PTRACE_DETACH 17
114 
115 #define PTRACE_SYSCALL 24
116 
117 
118 //
119 // Used for task_struct->flags
120 //
121 #define PF_EXITING 0x00000004 // getting shut down
122 #define PF_EXITPIDONE 0x00000008 // pi exit done on shut down
123 #define PF_VCPU 0x00000010 // I'm a virtual CPU
124 #define PF_WQ_WORKER 0x00000020 // I'm a workqueue worker
125 #define PF_FORKNOEXEC 0x00000040 // forked but didn't exec
126 #define PF_MCE_PROCESS 0x00000080 // process policy on mce errors
127 #define PF_SUPERPRIV 0x00000100 // used super-user privileges
128 #define PF_DUMPCORE 0x00000200 // dumped core
129 #define PF_SIGNALED 0x00000400 // killed by a signal
130 #define PF_MEMALLOC 0x00000800 // Allocating memory
131 #define PF_NPROC_EXCEEDED 0x00001000 // set_user noticed that RLIMIT_NPROC was exceeded
132 #define PF_USED_MATH 0x00002000 // if unset the fpu must be initialized before use
133 #define PF_USED_ASYNC 0x00004000 // used async_schedule*(), used by module init
134 #define PF_NOFREEZE 0x00008000 // this thread should not be frozen
135 #define PF_FROZEN 0x00010000 // frozen for system suspend
136 #define PF_FSTRANS 0x00020000 // inside a filesystem transaction
137 #define PF_KSWAPD 0x00040000 // I am kswapd
138 #define PF_MEMALLOC_NOIO 0x00080000 // Allocating memory without IO involved
139 #define PF_LESS_THROTTLE 0x00100000 // Throttle me less: I clean memory
140 #define PF_KTHREAD 0x00200000 // I am a kernel thread
141 #define PF_RANDOMIZE 0x00400000 // randomize virtual address space
142 #define PF_SWAPWRITE 0x00800000 // Allowed to write to swap
143 #define PF_NO_SETAFFINITY 0x04000000 // Userland is not allowed to meddle with cpus_allowed
144 #define PF_MCE_EARLY 0x08000000 // Early kill for mce process policy
145 #define PF_MUTEX_TESTER 0x20000000 // Thread belongs to the rt mutex tester
146 #define PF_FREEZER_SKIP 0x40000000 // Freezer should not count it as freezable
147 #define PF_SUSPEND_TASK 0x80000000 // this thread called freeze_processes and should not be frozen
148 
149 
150 //
151 // sizeof buf inside the linux_binprm
152 //
153 #define BINPRM_BUF_SIZE 128
154 
155 
156 //
157 // Some errno
158 //
159 #ifndef EACCES
160 #define EACCES 13
161 #endif
162 
163 
164 //
165 // This is the old-old version of the utsname().
166 // Does anybody ever compile with this ?!
167 //
168 typedef struct _LIX_UTSNAME_OLDOLD
169 {
176 
177 
178 //
179 // This is the old and the new version of the utsname().
180 // Don't ask why the old and the new are the same in every way...
181 //
182 typedef struct _LIX_UTSNAME
183 {
184  CHAR SysName[65]; // Always "Linux"...
185  CHAR NodeName[65]; // At init may be "(none)" or NULL
186  CHAR Release[65]; // ie. "3.10.0-123.6.3.el7.x86_64"
187  CHAR Version[65]; // ie. "#1 SMP Wed Aug 6 21:12:36 UTC 2014"
188  CHAR Machine[65]; // ie. "x86_64"
189 } LIX_UTSNAME;
190 
191 
192 #if !defined(NSIG) && !defined(SIGHUP)
193 #define NSIG 32
194 
195 #define SIGHUP 1
196 #define SIGINT 2
197 #define SIGQUIT 3
198 #define SIGILL 4
199 #define SIGTRAP 5
200 #define SIGABRT 6
201 #define SIGIOT 6
202 #define SIGBUS 7
203 #define SIGFPE 8
204 #define SIGKILL 9
205 #define SIGUSR1 10
206 #define SIGSEGV 11
207 #define SIGUSR2 12
208 #define SIGPIPE 13
209 #define SIGALRM 14
210 #define SIGTERM 15
211 #define SIGSTKFLT 16
212 #define SIGCHLD 17
213 #define SIGCONT 18
214 #define SIGSTOP 19
215 #define SIGTSTP 20
216 #define SIGTTIN 21
217 #define SIGTTOU 22
218 #define SIGURG 23
219 #define SIGXCPU 24
220 #define SIGXFSZ 25
221 #define SIGVTALRM 26
222 #define SIGPROF 27
223 #define SIGWINCH 28
224 #define SIGIO 29
225 #define SIGPOLL SIGIO
226 // #define SIGLOST 29
227 #define SIGPWR 30
228 #define SIGSYS 31
229 #define SIGUNUSED 31
230 // These should not be considered constants from userland.
231 #define SIGRTMIN 32
232 #define SIGRTMAX _NSIG
233 #endif
234 
235 #define S_IFMT 00170000
236 #define S_IFSOCK 0140000
237 #define S_IFLNK 0120000
238 #define S_IFREG 0100000
239 #define S_IFBLK 0060000
240 #define S_IFDIR 0040000
241 #define S_IFCHR 0020000
242 #define S_IFIFO 0010000
243 #define S_ISUID 0004000
244 #define S_ISGID 0002000
245 #define S_ISVTX 0001000
246 
247 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
248 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
249 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
250 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
251 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
252 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
253 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
254 
255 #define S_IRWXU 00700
256 #define S_IRUSR 00400
257 #define S_IWUSR 00200
258 #define S_IXUSR 00100
259 
260 #define S_IRWXG 00070
261 #define S_IRGRP 00040
262 #define S_IWGRP 00020
263 #define S_IXGRP 00010
264 
265 #define S_IRWXO 00007
266 #define S_IROTH 00004
267 #define S_IWOTH 00002
268 #define S_IXOTH 00001
269 
270 enum
271 {
272  UNAME26 = 0x0020000,
273  ADDR_NO_RANDOMIZE = 0x0040000,
274  FDPIC_FUNCPTRS = 0x0080000,
275  MMAP_PAGE_ZERO = 0x0100000,
276  ADDR_COMPAT_LAYOUT = 0x0200000,
277  READ_IMPLIES_EXEC = 0x0400000,
278  ADDR_LIMIT_32BIT = 0x0800000,
279  SHORT_INODE = 0x1000000,
280  WHOLE_SECONDS = 0x2000000,
281  STICKY_TIMEOUTS = 0x4000000,
282  ADDR_LIMIT_3GB = 0x8000000,
283 };
284 
285 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
286  ADDR_NO_RANDOMIZE | \
287  ADDR_COMPAT_LAYOUT | \
288  MMAP_PAGE_ZERO)
289 
290 #define LIX_PTI_PGTABLE_SWITCH_BIT 12
291 
292 #define MAX_ERRNO 4095
293 #define IS_ERR(x) ((UINT64)(void *)(x) >= (UINT64)-MAX_ERRNO)
294 
295 typedef enum _LIX_SOCK_STATE
296 {
307  LIX_TCP_CLOSING, // Not a valid state
309 
310  LIX_TCP_MAX_STATES // Leave at end
312 
313 typedef struct _LIX_RB_NODE
314 {
318 } LIX_RB_NODE;
319 
320 
321 typedef struct _LIX_TRAP_FRAME
322 {
323  // Don't trust these since they may not be saved
330 
331  // Always saved
341 
342  // Syscall number
344 
345  // Return frame
351 
353 
354 
355 #endif // _LIXDEFS_H_
QWORD Right
Definition: lixddefs.h:316
QWORD ParentColor
Definition: lixddefs.h:315
_LIX_SOCK_STATE
Definition: lixddefs.h:295
struct _LIX_RB_NODE LIX_RB_NODE
struct _LIX_UTSNAME LIX_UTSNAME
unsigned long long QWORD
Definition: intro_types.h:53
QWORD Left
Definition: lixddefs.h:317
enum _LIX_SOCK_STATE LIX_SOCK_STATE
struct _LIX_TRAP_FRAME LIX_TRAP_FRAME
struct _LIX_UTSNAME_OLDOLD LIX_UTSNAME_OLDOLD
char CHAR
Definition: intro_types.h:56