I am working on a project in which we have hooked the system open call. When a user attempts to open a file we want sys_open to check the given path against a file which contains file paths. If the given file path is contained in that file we want to stop them from opening the file. This is our module:
#include <linux/module.h> /* Needed by all kernel modules */
#include <linux/kernel.h> /* Needed for loglevels (KERN_WARNING, KERN_EMERG, KERN_INFO, etc.) */
#include <linux/init.h> /* Needed for __init and __exit macros. */
#include <linux/unistd.h> /* sys_call_table __NR_* system call function indices */
#include <linux/fs.h> /* filp_open */
#include <linux/slab.h> /* kmalloc */
#include <asm/paravirt.h> /* write_cr0 */
#include <asm/uaccess.h> /* get_fs, set_fs */
#include <linux/xattr.h>
#include <linux/dcache.h> /*dentry*/
#include <linux/namei.h>
#define PROC_V "/proc/version"
#define BOOT_PATH "/boot/System.map-"
#define CHECK_FILE "root/home/ben/Documents/project/module/test.txt"
#define MAX_VERSION_LEN 256
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Lots o ppl");
MODULE_DESCRIPTION("File Bunker");
//https://tnichols.org/2015/10/19/Hooking-the-Linux-System-Call-Table/
unsigned long *syscall_table = NULL;
//unsigned long *syscall_table = (unsigned long *)0xffffffff81801400;
asmlinkage int (*original_open)(const char*, int flags, mode_t);
static int find_sys_call_table (char *kern_ver) {
char system_map_entry[MAX_VERSION_LEN];
int i = 0;
/*
* Holds the /boot/System.map-<version> file name as we build it
*/
char *filename;
/*
* Length of the System.map filename, terminating NULL included
*/
size_t filename_length = strlen(kern_ver) + strlen(BOOT_PATH) + 1;
/*
* This will point to our /boot/System.map-<version> file
*/
struct file *f = NULL;
mm_segment_t oldfs;
oldfs = get_fs();
set_fs (KERNEL_DS);
printk(KERN_EMERG "Kernel version: %s\n", kern_ver);
filename = kmalloc(filename_length, GFP_KERNEL);
if (filename == NULL) {
printk(KERN_EMERG "kmalloc failed on System.map-<version> filename allocation");
return -1;
}
/*
* Zero out memory to be safe
*/
memset(filename, 0, filename_length);
/*
* Construct our /boot/System.map-<version> file name
*/
strncpy(filename, BOOT_PATH, strlen(BOOT_PATH));
strncat(filename, kern_ver, strlen(kern_ver));
/*
* Open the System.map file for reading
*/
f = filp_open(filename, O_RDONLY, 0);
if (IS_ERR(f) || (f == NULL)) {
printk(KERN_EMERG "Error opening System.map-<version> file: %s\n", filename);
return -1;
}
memset(system_map_entry, 0, MAX_VERSION_LEN);
/*
* Read one byte at a time from the file until we either max out
* out our buffer or read an entire line.
*/
while (vfs_read(f, system_map_entry + i, 1, &f->f_pos) == 1) {
/*
* If we've read an entire line or maxed out our buffer,
* check to see if we've just read the sys_call_table entry.
*/
if ( system_map_entry[i] == '\n' || i == MAX_VERSION_LEN ) {
// Reset the "column"/"character" counter for the row
i = 0;
if (strstr(system_map_entry, "sys_call_table") != NULL) {
char *sys_string;
char *system_map_entry_ptr = system_map_entry;
sys_string = kmalloc(MAX_VERSION_LEN, GFP_KERNEL);
if (sys_string == NULL) {
filp_close(f, 0);
set_fs(oldfs);
kfree(filename);
return -1;
}
memset(sys_string, 0, MAX_VERSION_LEN);
strncpy(sys_string, strsep(&system_map_entry_ptr, " "), MAX_VERSION_LEN);
//syscall_table = (unsigned long long *) kstrtoll(sys_string, NULL, 16);
//syscall_table = kmalloc(sizeof(unsigned long *), GFP_KERNEL);
//syscall_table = kmalloc(sizeof(syscall_table), GFP_KERNEL);
kstrtoul(sys_string, 16, &syscall_table);
printk(KERN_EMERG "syscall_table retrieved\n");
kfree(sys_string);
break;
}
memset(system_map_entry, 0, MAX_VERSION_LEN);
continue;
}
i++;
}
filp_close(f, 0);
set_fs(oldfs);
kfree(filename);
return 0;
}
/*
* We have to pass in a pointer to a buffer to store the parsed
* version information in. If we declare a pointer to the
* parsed version info on the stack of this function, the
* pointer will disappear when the function ends and the
* stack frame is removed.
*/
char *acquire_kernel_version (char *buf) {
struct file *proc_version;
char *kernel_version;
/*
* We use this to store the userspace perspective of the filesystem
* so we can switch back to it after we are done reading the file
* into kernel memory
*/
mm_segment_t oldfs;
/*
* Standard trick for reading a file into kernel space
* This is very bad practice. We're only doing it here because
* we're malicious and don't give a damn about best practices.
*/
oldfs = get_fs();
set_fs (KERNEL_DS);
/*
* Open the version file in the /proc virtual filesystem
*/
proc_version = filp_open(PROC_V, O_RDONLY, 0);
if (IS_ERR(proc_version) || (proc_version == NULL)) {
return NULL;
}
/*
* Zero out memory just to be safe
*/
memset(buf, 0, MAX_VERSION_LEN);
/*
* Read version info from /proc virtual filesystem
*/
vfs_read(proc_version, buf, MAX_VERSION_LEN, &(proc_version->f_pos));
/*
* Extract the third field from the full version string
*/
kernel_version = strsep(&buf, " ");
kernel_version = strsep(&buf, " ");
kernel_version = strsep(&buf, " ");
filp_close(proc_version, 0);
/*
* Switch filesystem context back to user space mode
*/
set_fs(oldfs);
return kernel_version;
}
asmlinkage int new_open (const char* path, int flags, mode_t mode) {
//printk(KERN_EMERG "[+] open() hooked.");
printk(KERN_EMERG "%s\n",path);
//allow this file to be opened, produces a security hole if they can find the
//file, but since this is just a surface level locking it doesnt violate the
//main idea of this module
if(strcmp(path,CHECK_FILE)) return original_open(path, flags, mode);
//need to check the masterfile to see if it is a restricted file
mm_segment_t oldfs;
oldfs = get_fs();
struct file *f;
set_fs (KERNEL_DS);
f = filp_open(CHECK_FILE,O_RDONLY,0);
if(f){
int i = 0;
int count = 0;
char *buf = kmalloc(sizeof(char)*256, GFP_KERNEL);
//reading a char at a time, if | appears we know it is the end of the path
while (vfs_read(f, buf + i, 1, &f->f_pos) == 1) {
//if it is a end character then it is the end of the file and we need to
//deal with the last path
//we need to get the length of the path
if(buf[count] == "|" || "\0"){
//if it is null char then we know that was the last path
if(buf[count] == "\0"){
kfree(buf);
return original_open(path, flags, mode);
}
buf[count + 1] = "\0";
char str[count+1];
memcpy(str,buf,sizeof(char)*count+1);
//if the path is in the file then do not open it
if(strcmp(path,str)){
kfree(buf);
return 0;
}
count = 0;
}
i++;
}
kfree(buf);
}
return original_open(path, flags, mode);
}
static int __init onload(void) {
char *kernel_version = kmalloc(MAX_VERSION_LEN, GFP_KERNEL);
printk(KERN_WARNING "Hello world!\n");
// printk(KERN_EMERG "Version: %s\n", acquire_kernel_version(kernel_version));
find_sys_call_table(acquire_kernel_version(kernel_version));
printk(KERN_EMERG "Syscall table address: %p\n", syscall_table);
printk(KERN_EMERG "sizeof(unsigned long *): %zx\n", sizeof(unsigned long*));
printk(KERN_EMERG "sizeof(sys_call_table) : %zx\n", sizeof(syscall_table));
if (syscall_table != NULL) {
write_cr0 (read_cr0 () & (~ 0x10000));
original_open = (void *)syscall_table[__NR_open];
syscall_table[__NR_open] = &new_open;
write_cr0 (read_cr0 () | 0x10000);
printk(KERN_EMERG "[+] onload: sys_call_table hooked\n");
} else {
printk(KERN_EMERG "[-] onload: syscall_table is NULL\n");
}
kfree(kernel_version);
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
static void __exit onunload(void) {
if (syscall_table != NULL) {
write_cr0 (read_cr0 () & (~ 0x10000));
syscall_table[__NR_open] = original_open;
write_cr0 (read_cr0 () | 0x10000);
printk(KERN_EMERG "[+] onunload: sys_call_table unhooked\n");
} else {
printk(KERN_EMERG "[-] onunload: syscall_table is NULL\n");
}
printk(KERN_INFO "Goodbye world!\n");
}
module_init(onload);
module_exit(onunload);
This is the output I am getting when I try to open a file then check with the dmsg shell command:
ben#ubuntu:~/Documents/project/module$ dmsg
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 27, in <module>
from CommandNotFound.util import crash_guard
File "/usr/lib/python3/dist-packages/CommandNotFound/__init__.py", line 3, in <module>
from CommandNotFound.CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 7, in <module>
import dbm.gnu as gdbm
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1467, in exec_module
File "<frozen importlib._bootstrap>", line 1579, in get_code
File "<frozen importlib._bootstrap>", line 1639, in _cache_bytecode
File "<frozen importlib._bootstrap>", line 1663, in set_data
File "<frozen importlib._bootstrap>", line 110, in _write_atomic
ValueError: Negative filedescriptor
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 15, in <module>
import xml.dom, xml.dom.minidom
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1467, in exec_module
File "<frozen importlib._bootstrap>", line 1579, in get_code
File "<frozen importlib._bootstrap>", line 1639, in _cache_bytecode
File "<frozen importlib._bootstrap>", line 1663, in set_data
File "<frozen importlib._bootstrap>", line 110, in _write_atomic
ValueError: Negative filedescriptor
Original exception was:
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 27, in <module>
from CommandNotFound.util import crash_guard
File "/usr/lib/python3/dist-packages/CommandNotFound/__init__.py", line 3, in <module>
from CommandNotFound.CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 7, in <module>
import dbm.gnu as gdbm
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1467, in exec_module
File "<frozen importlib._bootstrap>", line 1579, in get_code
File "<frozen importlib._bootstrap>", line 1639, in _cache_bytecode
File "<frozen importlib._bootstrap>", line 1663, in set_data
File "<frozen importlib._bootstrap>", line 110, in _write_atomic
ValueError: Negative filedescriptor
I am confused as to what exactly is going wrong here and would very much appreciate some input! Thanks.
When I run the dmesg command this is the output:
[ 273.571654] /dev/:0
[ 273.571656] /dev/:1
[ 273.571659] /dev/pts/0
[ 273.571696] /var/run/utmp
[ 273.571709] /dev/:0
[ 273.571712] /dev/:1
[ 273.571715] /dev/pts/0
[ 273.571719] /var/run/utmp
[ 273.571731] /dev/:0
[ 273.571734] /dev/:1
[ 273.571736] /dev/pts/0
[ 273.571740] /var/run/utmp
[ 273.571752] /dev/:0
[ 273.571755] /dev/:1
[ 273.571758] /dev/pts/0
[ 273.571761] /var/run/utmp
[ 273.571773] /dev/:0
[ 273.571776] /dev/:1
[ 273.571779] /dev/pts/0
[ 273.571782] /var/run/utmp
[ 273.571794] /dev/:0
[ 273.571797] /dev/:1
[ 273.571800] /dev/pts/0
[ 273.571803] /var/run/utmp
[ 273.571816] /dev/:0
[ 273.571818] /dev/:1
[ 273.571821] /dev/pts/0
[ 273.571825] /var/run/utmp
[ 273.571837] /dev/:0
[ 273.571840] /dev/:1
[ 273.571843] /dev/pts/0
[ 273.571846] /var/run/utmp
[ 273.571859] /dev/:0
[ 273.571861] /dev/:1
[ 273.571864] /dev/pts/0
[ 273.571868] /var/run/utmp
[ 273.571880] /dev/:0
[ 273.571883] /dev/:1
[ 273.571886] /dev/pts/0
[ 273.571889] /var/run/utmp
[ 273.571913] /dev/:0
[ 273.571917] /dev/:1
[ 273.571920] /dev/pts/0
[ 273.571925] /var/run/utmp
[ 273.571937] /dev/:0
[ 273.571940] /dev/:1
[ 273.571943] /dev/pts/0
[ 273.571946] /var/run/utmp
[ 273.571959] /dev/:0
[ 273.571961] /dev/:1
[ 273.571964] /dev/pts/0
[ 273.571967] /var/run/utmp
[ 273.571980] /dev/:0
[ 273.571982] /dev/:1
[ 273.571985] /dev/pts/0
[ 273.571989] /var/run/utmp
[ 273.572001] /dev/:0
[ 273.572004] /dev/:1
[ 273.572006] /dev/pts/0
[ 273.572010] /var/run/utmp
[ 273.572023] /dev/:0
[ 273.572025] /dev/:1
[ 273.572028] /dev/pts/0
[ 273.572032] /var/run/utmp
[ 273.572044] /dev/:0
[ 273.572047] /dev/:1
[ 273.572049] /dev/pts/0
[ 273.572053] /var/run/utmp
[ 273.572066] /dev/:0
[ 273.572068] /dev/:1
[ 273.572071] /dev/pts/0
[ 273.572074] /var/run/utmp
[ 273.572087] /dev/:0
[ 273.572090] /dev/:1
[ 273.572092] /dev/pts/0
[ 273.572096] /var/run/utmp
[ 273.572108] /dev/:0
[ 273.572111] /dev/:1
[ 273.572113] /dev/pts/0
[ 273.572117] /var/run/utmp
[ 273.572129] /dev/:0
[ 273.572132] /dev/:1
[ 273.572135] /dev/pts/0
[ 273.572139] /var/run/utmp
[ 273.572151] /dev/:0
[ 273.572154] /dev/:1
[ 273.572156] /dev/pts/0
[ 273.572160] /var/run/utmp
[ 273.572172] /dev/:0
[ 273.572175] /dev/:1
[ 273.572178] /dev/pts/0
[ 273.572181] /var/run/utmp
[ 273.572194] /dev/:0
[ 273.572197] /dev/:1
[ 273.572199] /dev/pts/0
[ 273.572203] /var/run/utmp
[ 273.572215] /dev/:0
[ 273.572218] /dev/:1
[ 273.572221] /dev/pts/0
[ 273.572224] /var/run/utmp
[ 273.572237] /dev/:0
[ 273.572239] /dev/:1
[ 273.572242] /dev/pts/0
[ 273.572245] /var/run/utmp
[ 273.572258] /dev/:0
[ 273.572261] /dev/:1
[ 273.572263] /dev/pts/0
[ 273.572267] /var/run/utmp
[ 273.572279] /dev/:0
[ 273.572282] /dev/:1
[ 273.572284] /dev/pts/0
[ 273.572288] /var/run/utmp
[ 273.572300] /dev/:0
[ 273.572303] /dev/:1
[ 273.572306] /dev/pts/0
[ 273.572309] /var/run/utmp
[ 273.572322] /dev/:0
[ 273.572324] /dev/:1
[ 273.572327] /dev/pts/0
[ 273.572330] /var/run/utmp
[ 273.572343] /dev/:0
[ 273.572345] /dev/:1
[ 273.572348] /dev/pts/0
[ 273.572352] /var/run/utmp
[ 273.572364] /dev/:0
[ 273.572367] /dev/:1
[ 273.572369] /dev/pts/0
[ 273.572373] /var/run/utmp
[ 273.572385] /dev/:0
[ 273.572388] /dev/:1
[ 273.572390] /dev/pts/0
[ 273.572436] /var/run/utmp
[ 273.572451] /dev/:0
[ 273.572454] /dev/:1
[ 273.572456] /dev/pts/0
[ 273.572460] /var/run/utmp
[ 273.572473] /dev/:0
[ 273.572475] /dev/:1
[ 273.572478] /dev/pts/0
[ 273.572482] /var/run/utmp
[ 273.572494] /dev/:0
[ 273.572497] /dev/:1
[ 273.572500] /dev/pts/0
[ 273.572504] /var/run/utmp
[ 273.572516] /dev/:0
[ 273.572519] /dev/:1
[ 273.572521] /dev/pts/0
[ 273.572525] /var/run/utmp
[ 273.572538] /dev/:0
[ 273.572540] /dev/:1
[ 273.572543] /dev/pts/0
[ 273.572547] /var/run/utmp
[ 273.572559] /dev/:0
[ 273.572563] /dev/:1
[ 273.572566] /dev/pts/0
[ 273.572570] /var/run/utmp
[ 273.572582] /dev/:0
[ 273.572585] /dev/:1
[ 273.572587] /dev/pts/0
[ 273.572591] /var/run/utmp
[ 273.572603] /dev/:0
[ 273.572606] /dev/:1
[ 273.572609] /dev/pts/0
[ 273.572612] /var/run/utmp
[ 273.572625] /dev/:0
[ 273.572627] /dev/:1
[ 273.572630] /dev/pts/0
[ 273.572634] /var/run/utmp
[ 273.572646] /dev/:0
[ 273.572649] /dev/:1
[ 273.572651] /dev/pts/0
[ 273.572655] /var/run/utmp
[ 273.572667] /dev/:0
[ 273.572670] /dev/:1
[ 273.572672] /dev/pts/0
[ 273.572676] /var/run/utmp
[ 273.572689] /dev/:0
[ 273.572691] /dev/:1
[ 273.572694] /dev/pts/0
[ 273.572697] /var/run/utmp
[ 273.572710] /dev/:0
[ 273.572712] /dev/:1
[ 273.572715] /dev/pts/0
[ 273.572719] /var/run/utmp
[ 273.572731] /dev/:0
[ 273.572734] /dev/:1
[ 273.572736] /dev/pts/0
[ 273.572740] /var/run/utmp
[ 273.572752] /dev/:0
[ 273.572755] /dev/:1
[ 273.572757] /dev/pts/0
[ 273.572761] /var/run/utmp
[ 273.572773] /dev/:0
[ 273.572776] /dev/:1
[ 273.572778] /dev/pts/0
[ 273.572782] /var/run/utmp
[ 273.572794] /dev/:0
[ 273.572797] /dev/:1
[ 273.572799] /dev/pts/0
[ 273.572803] /var/run/utmp
[ 273.572815] /dev/:0
[ 273.572818] /dev/:1
[ 273.572820] /dev/pts/0
[ 273.572824] /var/run/utmp
[ 273.572836] /dev/:0
[ 273.572839] /dev/:1
[ 273.572842] /dev/pts/0
[ 273.572845] /var/run/utmp
[ 273.572857] /dev/:0
[ 273.572860] /dev/:1
[ 273.572863] /dev/pts/0
[ 273.572866] /var/run/utmp
[ 273.572879] /dev/:0
[ 273.572881] /dev/:1
[ 273.572884] /dev/pts/0
[ 273.572887] /var/run/utmp
[ 273.573006] /dev/:0
[ 273.573010] /dev/:1
[ 273.573013] /dev/pts/0
[ 273.573018] /var/run/utmp
[ 273.573031] /dev/:0
[ 273.573034] /dev/:1
[ 273.573037] /dev/pts/0
[ 273.573040] /var/run/utmp
[ 273.573053] /dev/:0
[ 273.573055] /dev/:1
[ 273.573058] /dev/pts/0
[ 273.573061] /var/run/utmp
[ 273.573074] /dev/:0
[ 273.573076] /dev/:1
[ 273.573079] /dev/pts/0
[ 273.573082] /var/run/utmp
[ 273.573095] /dev/:0
[ 273.573097] /dev/:1
[ 273.573100] /dev/pts/0
[ 273.573104] /var/run/utmp
[ 273.573116] /dev/:0
[ 273.573119] /dev/:1
[ 273.573121] /dev/pts/0
[ 273.573125] /var/run/utmp
[ 273.573137] /dev/:0
[ 273.573140] /dev/:1
[ 273.573143] /dev/pts/0
[ 273.573146] /var/run/utmp
[ 273.573159] /dev/:0
[ 273.573161] /dev/:1
[ 273.573164] /dev/pts/0
[ 273.573167] /var/run/utmp
[ 273.573180] /dev/:0
[ 273.573183] /dev/:1
[ 273.573185] /dev/pts/0
[ 273.573189] /var/run/utmp
[ 273.573201] /dev/:0
[ 273.573204] /dev/:1
[ 273.573206] /dev/pts/0
[ 273.573210] /var/run/utmp
[ 273.573222] /dev/:0
[ 273.573225] /dev/:1
[ 273.573228] /dev/pts/0
[ 273.573268] /var/run/utmp
[ 273.573281] /dev/:0
[ 273.573284] /dev/:1
[ 273.573287] /dev/pts/0
[ 273.573291] /var/run/utmp
[ 273.573303] /dev/:0
[ 273.573306] /dev/:1
[ 273.573309] /dev/pts/0
[ 273.573312] /var/run/utmp
[ 273.573325] /dev/:0
[ 273.573327] /dev/:1
[ 273.573330] /dev/pts/0
[ 273.573334] /var/run/utmp
[ 273.573346] /dev/:0
[ 273.573349] /dev/:1
[ 273.573352] /dev/pts/0
[ 273.573355] /var/run/utmp
[ 273.573368] /dev/:0
[ 273.573370] /dev/:1
[ 273.573373] /dev/pts/0
[ 273.573377] /var/run/utmp
[ 273.573389] /dev/:0
[ 273.573392] /dev/:1
[ 273.573407] /dev/pts/0
[ 273.573412] /var/run/utmp
[ 273.573425] /dev/:0
[ 273.573428] /dev/:1
[ 273.573431] /dev/pts/0
[ 273.573434] /var/run/utmp
[ 273.573447] /dev/:0
[ 273.573449] /dev/:1
[ 273.573452] /dev/pts/0
[ 273.573456] /var/run/utmp
[ 273.573468] /dev/:0
[ 273.573471] /dev/:1
[ 273.573474] /dev/pts/0
[ 273.573477] /var/run/utmp
[ 273.573490] /dev/:0
[ 273.573493] /dev/:1
[ 273.573495] /dev/pts/0
[ 273.573499] /var/run/utmp
[ 273.573511] /dev/:0
[ 273.573514] /dev/:1
[ 273.573517] /dev/pts/0
[ 273.573520] /var/run/utmp
[ 273.573533] /dev/:0
[ 273.573535] /dev/:1
[ 273.573538] /dev/pts/0
[ 273.573542] /var/run/utmp
[ 273.573554] /dev/:0
[ 273.573557] /dev/:1
[ 273.573560] /dev/pts/0
[ 273.573563] /var/run/utmp
[ 273.573576] /dev/:0
[ 273.573578] /dev/:1
[ 273.573581] /dev/pts/0
[ 273.573585] /var/run/utmp
[ 273.573597] /dev/:0
[ 273.573600] /dev/:1
[ 273.573602] /dev/pts/0
[ 273.573606] /var/run/utmp
[ 273.573618] /dev/:0
[ 273.573621] /dev/:1
[ 273.573624] /dev/pts/0
[ 273.573627] /var/run/utmp
[ 273.573640] /dev/:0
[ 273.573643] /dev/:1
[ 273.573645] /dev/pts/0
[ 273.573649] /var/run/utmp
[ 273.573661] /dev/:0
[ 273.573664] /dev/:1
[ 273.573667] /dev/pts/0
[ 273.573670] /var/run/utmp
[ 273.573683] /dev/:0
[ 273.573686] /dev/:1
[ 273.573688] /dev/pts/0
[ 273.573692] /var/run/utmp
[ 273.573704] /dev/:0
[ 273.573707] /dev/:1
[ 273.573710] /dev/pts/0
[ 273.573713] /var/run/utmp
[ 273.573726] /dev/:0
[ 273.573728] /dev/:1
[ 273.573731] /dev/pts/0
[ 273.573735] /var/run/utmp
[ 273.573747] /dev/:0
[ 273.573750] /dev/:1
[ 273.573752] /dev/pts/0
[ 273.573756] /var/run/utmp
[ 273.573769] /dev/:0
[ 273.573771] /dev/:1
[ 273.573774] /dev/pts/0
[ 273.573778] /var/run/utmp
[ 273.573790] /dev/:0
[ 273.573793] /dev/:1
[ 273.573795] /dev/pts/0
[ 273.573799] /var/run/utmp
[ 273.573811] /dev/:0
[ 273.573814] /dev/:1
[ 273.573817] /dev/pts/0
[ 273.573820] /var/run/utmp
[ 273.573833] /dev/:0
[ 273.573835] /dev/:1
[ 273.573838] /dev/pts/0
[ 273.573841] /var/run/utmp
[ 273.573862] /dev/:0
[ 273.573865] /dev/:1
[ 273.573867] /dev/pts/0
[ 273.573871] /var/run/utmp
[ 273.573883] /dev/:0
[ 273.573885] /dev/:1
[ 273.573888] /dev/pts/0
[ 273.573891] /var/run/utmp
[ 273.573924] /dev/:0
[ 273.573930] /dev/:1
[ 273.573934] /dev/pts/0
[ 273.573940] /var/run/utmp
[ 273.573953] /dev/:0
[ 273.573956] /dev/:1
[ 273.573968] /dev/pts/0
[ 273.573971] /var/run/utmp
[ 273.574003] /dev/:0
[ 273.574006] /dev/:1
[ 273.574008] /dev/pts/0
[ 273.574022] /var/run/utmp
[ 273.574044] /dev/:0
[ 273.574046] /dev/:1
[ 273.574049] /dev/pts/0
[ 273.574136] /var/run/utmp
[ 273.574159] /dev/:0
[ 273.574172] /dev/:1
[ 273.574175] /dev/pts/0
[ 273.574179] /var/run/utmp
[ 273.574211] /dev/:0
[ 273.574213] /dev/:1
[ 273.574216] /dev/pts/0
[ 273.574229] /var/run/utmp
[ 273.574252] /dev/:0
[ 273.574264] /dev/:1
[ 273.574266] /dev/pts/0
[ 273.574270] /var/run/utmp
[ 273.574304] /dev/:0
[ 273.574306] /dev/:1
[ 273.574309] /dev/pts/0
[ 273.574322] /var/run/utmp
[ 273.574344] /dev/:0
[ 273.574347] /dev/:1
[ 273.574359] /dev/pts/0
[ 273.574363] /var/run/utmp
[ 273.574385] /dev/:0
[ 273.574398] /dev/:1
[ 273.574400] /dev/pts/0
[ 273.574404] /var/run/utmp
[ 273.574427] /dev/:0
[ 273.574432] /dev/:1
[ 273.574434] /dev/pts/0
[ 273.574439] /var/run/utmp
[ 273.574452] /dev/:0
[ 273.574454] /dev/:1
[ 273.574457] /dev/pts/0
[ 273.574460] /var/run/utmp
[ 273.574473] /dev/:0
[ 273.574475] /dev/:1
[ 273.574478] /dev/pts/0
[ 273.574482] /var/run/utmp
[ 273.574494] /dev/:0
[ 273.574497] /dev/:1
[ 273.574499] /dev/pts/0
[ 273.574503] /var/run/utmp
[ 273.574515] /dev/:0
[ 273.574518] /dev/:1
[ 273.574520] /dev/pts/0
[ 273.574524] /var/run/utmp
[ 273.574536] /dev/:0
[ 273.574539] /dev/:1
[ 273.574542] /dev/pts/0
[ 273.574545] /var/run/utmp
[ 273.574558] /dev/:0
[ 273.574560] /dev/:1
[ 273.574563] /dev/pts/0
[ 273.574566] /var/run/utmp
[ 273.574579] /dev/:0
[ 273.574581] /dev/:1
[ 273.574584] /dev/pts/0
[ 273.574587] /var/run/utmp
[ 273.574600] /dev/:0
[ 273.574603] /dev/:1
[ 273.574605] /dev/pts/0
[ 273.574609] /var/run/utmp
[ 273.574621] /dev/:0
//part omitted due to character restriction
[ 273.574733] /dev/pts/0
[ 273.574737] /var/run/utmp
[ 273.574749] /dev/:0
[ 273.574752] /dev/:1
[ 273.574754] /dev/pts/0
[ 273.574758] /var/run/utmp
[ 273.574770] /dev/:0
[ 273.574773] /dev/:1
[ 273.574775] /dev/pts/0
[ 273.574779] /var/run/utmp
[ 273.574791] /dev/:0
[ 273.574794] /dev/:1
[ 273.574797] /dev/pts/0
[ 273.574800] /var/run/utmp
[ 273.574813] /dev/:0
[ 273.574815] /dev/:1
[ 273.574818] /dev/pts/0
[ 273.574821] /var/run/utmp
[ 273.574834] /dev/:0
[ 273.574836] /dev/:1
[ 273.574839] /dev/pts/0
[ 273.574843] /var/run/utmp
[ 273.574855] /dev/:0
[ 273.574858] /dev/:1
[ 273.574860] /dev/pts/0
[ 273.574864] /var/run/utmp
[ 273.574876] /dev/:0
[ 273.574879] /dev/:1
[ 273.574881] /dev/pts/0
[ 273.574894] /var/run/utmp
[ 273.574910] /dev/:0
[ 273.574913] /dev/:1
[ 273.574915] /dev/pts/0
[ 273.574920] /var/run/utmp
[ 273.574932] /dev/:0
[ 273.574935] /dev/:1
[ 273.574937] /dev/pts/0
[ 273.574941] /var/run/utmp
[ 273.577004] /etc/ld.so.cache
[ 273.577018] /lib/x86_64-linux-gnu/libc.so.6
[ 273.577182] /usr/lib/locale/locale-archive
Related
This question already has answers here:
Error "RangeError: minimumFractionDigits value is out of range" with ChartJS in Next.js app
(3 answers)
Closed 4 months ago.
everthing is working fine in development on my local machine,
but when I deploy my site to netlify, I get this wierd error in console.
the page data is gotten using getStaticProps function and then passed to the page as props.
here is how the data looks like
[
[ 17671, 19856, 37527 ], [ 4887, 5418, 10305 ],
[ 2803, 2303, 5106 ], [ 8617, 9403, 18020 ],
[ 12664, 15722, 28386 ], [ 4227, 3359, 7586 ],
[ 1371, 1545, 2916 ], [ 17526, 14297, 31823 ],
[ 6883, 4781, 11664 ], [ 9805, 10000, 19805 ],
[ 11068, 12888, 23956 ], [ 4570, 4722, 9292 ],
[ 15428, 17309, 32737 ], [ 3565, 3656, 7221 ],
[ 8750, 10443, 19193 ], [ 1771, 1432, 3203 ],
[ 8495, 9979, 18474 ], [ 288, 265, 553 ],
[ 21130, 19321, 40451 ], [ 6867, 6556, 13423 ],
[ 2656, 2092, 4748 ], [ 967, 656, 1623 ],
[ 4540, 4505, 9045 ], [ 7025, 7108, 14133 ],
[ 53134, 59829, 112963 ], [ 8640, 9028, 17668 ],
[ 6759, 7119, 13878 ], [ 28803, 31362, 60165 ],
[ 7346, 7630, 14976 ], [ 9771, 10963, 20734 ],
[ 15783, 17397, 33180 ], [ 9847, 9706, 19553 ],
[ 15154, 17577, 32731 ], [ 1056, 874, 1930 ],
[ 3260, 2476, 5736 ], [ 1488, 1424, 2912 ],
[ 1656, 1154, 2810 ]
]
it is an array of arrays of 3 numbers.
please how do I solve this?
You need to set swcMinify: false false in your next.confug.js. This is currently a bug in the swcMinifier and you will need to wait until they have fixed it before you can enable it again.
I am using a petalinux / yocto on a evaluation board with a MpSoc and a FPGA. I am new to this whole Embedded Linux and gereeted with this error message when I try to run a precompiled example. Any pointers on what's going wrong is appreciated.
[ 91.171070] rcu: INFO: rcu_sched self-detected stall on CPU
[ 91.176642] rcu: 0-....: (5249 ticks this GP) idle=66a/1/0x4000000000000002 softirq=1286/1286 fqs=2625
[ 91.186107] (t=5252 jiffies g=1737 q=5)
[ 91.190013] Task dump for CPU 0:
[ 91.193225] resnet50 R running task 0 740 608 0x00000002
[ 91.200265] Call trace:
[ 91.202701] dump_backtrace+0x0/0x140
[ 91.206352] show_stack+0x14/0x20
[ 91.209652] sched_show_task+0xf4/0x120
[ 91.213479] dump_cpu_task+0x40/0x50
[ 91.217038] rcu_dump_cpu_stacks+0xa0/0xe0
[ 91.221118] rcu_sched_clock_irq+0x52c/0x780
[ 91.225372] update_process_times+0x2c/0x68
[ 91.229539] tick_sched_handle.isra.0+0x30/0x50
[ 91.234052] tick_sched_timer+0x48/0x98
[ 91.237872] __hrtimer_run_queues+0xec/0x1e8
[ 91.242125] hrtimer_interrupt+0x110/0x2c0
[ 91.246207] arch_timer_handler_phys+0x30/0x40
[ 91.250633] handle_percpu_devid_irq+0x80/0x140
[ 91.255147] generic_handle_irq+0x24/0x38
[ 91.259140] __handle_domain_irq+0x60/0xb8
[ 91.263220] gic_handle_irq+0x5c/0xb8
[ 91.266866] el1_irq+0xb8/0x140
[ 91.269992] misc_open+0x50/0x1a0
[ 91.273291] chrdev_open+0xc4/0x200
[ 91.276763] do_dentry_open+0x104/0x398
[ 91.280581] vfs_open+0x28/0x30
[ 91.283708] path_openat+0x4a0/0x1248
[ 91.287353] do_filp_open+0x74/0xf8
[ 91.290825] do_sys_open+0x168/0x218
[ 91.294384] __arm64_sys_openat+0x20/0x28
[ 91.298381] el0_svc_common.constprop.0+0x68/0x160
[ 91.303161] el0_svc_handler+0x6c/0x88
[ 91.306893] el0_svc+0x8/0xc
I am trying to reverse an array of coordinates. I have this array:
[
[
9.211615025997162,
44.30419567985762
],
[
9.21164184808731,
44.30412081929745
],
[
9.21165257692337,
44.304053636662175
],
[
9.211606979370117,
44.3038789614507
],
[
9.211572110652924,
44.30381945658962
],
[
9.211539924144745,
44.30378874437967
],
[
9.211507737636566,
44.30376187118276
],
[
9.211564064025879,
44.30377530778277
],
[
9.211574792861937,
44.30374075651943
],
[
9.211574792861937,
44.30371388330059
],
[
9.211574792861937,
44.30369852717
],
[
9.21154797077179,
44.303665895379176
],
[
9.211513102054596,
44.303650539236024
],
[
9.211429953575134,
44.30358911462331
],
[
9.211349487304688,
44.30355840229286
],
[
9.211271703243256,
44.303537287556324
],
[
9.21117514371872,
44.30349505806051
],
[
9.211151003837585,
44.303473943301235
],
[
9.211126863956451,
44.30342979423452
],
[
9.211145639419556,
44.30339908182071
],
[
9.211183190345764,
44.303368369390846
],
[
9.211223423480988,
44.30331846165803
],
[
9.211242198944092,
44.30327623200479
],
[
9.211177825927734,
44.30325895622883
],
[
9.211030304431915,
44.303228243725634
],
[
9.210925698280334,
44.30321096793552
],
[
9.210874736309052,
44.303197531206386
],
[
9.210831820964813,
44.303197531206386
],
[
9.21075403690338,
44.303197531206386
],
[
9.21068161725998,
44.3031994507393
],
[
9.210577011108398,
44.3031994507393
],
[
9.210509955883026,
44.303207128870355
],
[
9.210440218448639,
44.303207128870355
],
[
9.210370481014252,
44.30322632419366
],
[
9.2102712392807,
44.30324743904202
],
[
9.210190773010254,
44.30328199059568
],
[
9.210112988948822,
44.30328391012582
],
[
9.210059344768524,
44.303297346835215
],
[
9.209954738616943,
44.30332422024474
],
[
9.209901094436646,
44.303339576473235
],
[
9.209868907928467,
44.303349174114
],
[
9.209858179092407,
44.30338372560779
],
[
9.209791123867035,
44.30340292087333
],
[
9.209697246551514,
44.30342595518367
],
[
9.209648966789246,
44.3034509090097
],
[
9.209606051445007,
44.30351809233474
],
[
9.209579229354858,
44.30355840229286
],
[
9.209581911563873,
44.3035852755829
],
[
9.209622144699097,
44.30355840229286
],
[
9.20967847108841,
44.30355648277167
],
[
9.209697246551514,
44.30354112659989
]
]
And I would like to reverse the coordinates, which are right now in Long-Lat to Lat-Long thus reversing the whole array or each item in the array would do the job here. I have been stuck trying to make it work, trying things like arrayOfCoords.reversed() and .reverse() to no avail. So how can I do this?
There may be a more elegant/efficient way to do this, but I'd look at using compactMap:
let testArray = [[1.123,2.22], [3.11, 4.0], [5.21, 6.19]]
print(testArray)
[[1.123, 2.22], [3.11, 4.0], [5.21, 6.19]]
let flippedElementArray = testArray.compactMap { $0.count > 1 ? [$0[1], $0[0]] : nil }
print(flippedElementArray)
[[2.22, 1.123], [4.0, 3.11], [6.19, 5.21]]
The $0.count > 1 check just makes sure you have at least 2 elements so you don't get a bounds error. If not, the closure returns nil for that element, which will be filtered out by compactMap. Otherwise, it returns a new array element consisting of the second element followed by the first element. All of those elements are stored in the final mapped array (flippedElementArray).
arrayOfCoords.map{ Array($0.reversed()) }
I'm assuming you want to reverse each coordinate pair, but keep the pairs themselves in the original order. Since you have an array of arrays, you have to do the operation on each sub-array separately. And reversed() returns a ReversedCollection instead of an Array so you have to re-initialize it into an array to use it properly.
I have file that contains different values in each line and I would like to count the occurrence of numbers that occurs after a specific keyword. For example;
"fields" : {
"referer" : [ "-" ],
"#timestamp" : [ "2017-01-08T19:50:19.000Z" ],
"uri_path" : [ "test" ],
"method" : [ "GET" ],
"servername" : [ "INMESPWEB03" ],
"useragent" : [ "Mediapartners-Google" ],
"querystring" : [ "test" ],
"bytes-sent" : [ "227905" ],
"cshost" : [ "www.test.com" ],
"scstatus" : [ "200" ],
"time-taken" : [ "15468" ]
}
"fields" : {
"referer" : [ "-" ],
"#timestamp" : [ "2017-01-08T19:50:19.000Z" ],
"uri_path" : [ "test" ],
"method" : [ "GET" ],
"servername" : [ "INMESPWEB03" ],
"useragent" : [ "Mediapartners-Google" ],
"querystring" : [ "test" ],
"bytes-sent" : [ "227905" ],
"cshost" : [ "www.test.com" ],
"scstatus" : [ "300" ],
"time-taken" : [ "15468" ]
}
"fields" : {
"referer" : [ "-" ],
"#timestamp" : [ "2017-01-08T19:50:19.000Z" ],
"uri_path" : [ "test" ],
"method" : [ "GET" ],
"servername" : [ "INMESPWEB03" ],
"useragent" : [ "Mediapartners-Google" ],
"querystring" : [ "test" ],
"bytes-sent" : [ "227905" ],
"cshost" : [ "www.test.com" ],
"scstatus" : [ "200" ],
"time-taken" : [ "15468" ]
}
So the result should be like
200 : 2
300 : 1
... : .
and goes like this
I would like to check every number after "scstatus" and count them and print in ascending or descending order. Here is the code I wrote so far, this script gives me the data above
curl -XPOST 'webpage.name.abc' -d { "query": { "filtered": { "query": { "query_string": {
"analyze_wildcard": true,
"query": "useragent: \"googlebot\"|\"mediapartners-google\"|\"adsbot-google\""}
}}},"size": 4000000, "fields": ["#timestamp","servername","uri_path","scstatus","method","cshost","useragent","time-taken","referer","bytes-sent","querystring"]}
If your file format is fixed, this awk one-liner may help:
awk -F'"' '$2=="scstatus"{a[$4]++}END{for(x in a)print x,a[x]}' file
200 2
300 1
I have implemented a mechanism to migrate TCP socket between different severs in Linux OS. The migration mechanism works perfectly, except when the importing server needs to close the server the whole machine freezes. I was able to dump the log file of the machine using serial connection as explained in this article Debugging Linux Kernel. From the reading of the log file, I saw that NULL pointer dereference problem is occurring in the tcp_time_wait function. So my current problem now I need to know how to figure out which data member or macro inside the tcp_time_wait is causing the problem?
Should I recompile the Kernel with some printk to detect the exact source of error?
Linux Kernel Dump:
[ 225.717049] BUG: unable to handle kernel NULL pointer dereference at 0000000000000020
[ 225.720544] IP: [<ffffffff8162056c>] __inet_twsk_hashdance+0x8c/0x160
[ 225.720544] PGD 7bbf9067 PUD 7b7fc067 PMD 0
[ 225.720544] Oops: 0000 [#1] SMP
[ 225.720544] Modules linked in: sockmi(OF) nf_conntrack(F) vesafb(F) vboxsf(OF) snd_int)
[ 225.720544] CPU 0
[ 225.720544] Pid: 0, comm: swapper/0 Tainted: GF W O 3.8.0-29-generic #42~precisx
[ 225.720544] RIP: 0010:[<ffffffff8162056c>] [<ffffffff8162056c>] __inet_twsk_hashdance0
[ 225.720544] RSP: 0018:ffff88007fc039d0 EFLAGS: 00010282
[ 225.720544] RAX: 0000000000000000 RBX: ffff88005cbd5000 RCX: ffffffff81e304c0
[ 225.720544] RDX: 0000000000001c37 RSI: 0000000000000082 RDI: 0000000000000009
[ 225.720544] RBP: ffff88007fc03a00 R08: 000000000000000a R09: 0000000000000000
[ 225.720544] R10: 000000000000021a R11: 0000000000000219 R12: ffff88007ba4b800
[ 225.720544] R13: ffffc9000035a7d0 R14: ffffc90000322500 R15: ffff88007c1e3d40
[ 225.720544] FS: 0000000000000000(0000) GS:ffff88007fc00000(0000) knlGS:000000000000000
[ 225.720544] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[ 225.720544] CR2: 0000000000000020 CR3: 000000007965f000 CR4: 00000000000006f0
[ 225.720544] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 225.720544] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[ 225.720544] Process swapper/0 (pid: 0, threadinfo ffffffff81c00000, task ffffffff81c15)
[ 225.720544] Stack:
[ 225.720544] ffff88007ba4b800 ffff88007ba4b800 ffff88005cbd5000 0000000000000000
[ 225.720544] 000000000000001f 0000000000000000 ffff88007fc03a50 ffffffff8163de3c
[ 225.720544] ffff8800000000d9 000000065cb8b300 ffff88003652e262 ffff88007ba4b800
[ 225.720544] Call Trace:
[ 225.720544] <IRQ>
[ 225.720544] [<ffffffff8163de3c>] tcp_time_wait+0x1bc/0x290
[ 225.720544] [<ffffffff8162d4fe>] tcp_fin+0x10e/0x1c0
[ 225.720544] [<ffffffff8162e078>] tcp_data_queue+0x3e8/0x580
[ 225.720544] [<ffffffff81631bb5>] tcp_rcv_state_process+0x2b5/0x6b0
[ 225.720544] [<ffffffff8163abc7>] tcp_v4_do_rcv+0xc7/0x220
[ 225.720544] [<ffffffff8163c829>] tcp_v4_rcv+0x569/0x830
[ 225.720544] [<ffffffff81616366>] ip_local_deliver_finish+0xe6/0x280
[ 225.720544] [<ffffffff8161668a>] ip_local_deliver+0x4a/0x90
[ 225.720544] [<ffffffff81616039>] ip_rcv_finish+0x119/0x360
[ 225.720544] [<ffffffff816168ed>] ip_rcv+0x21d/0x300
[ 225.720544] [<ffffffff815e355a>] __netif_receive_skb+0x5fa/0x760
[ 225.720544] [<ffffffff8163cbae>] ? tcp4_gro_receive+0x9e/0x110
[ 225.720544] [<ffffffff815e36e3>] netif_receive_skb+0x23/0x90
[ 225.720544] [<ffffffff815e3e28>] napi_gro_receive+0xe8/0x140
[ 225.906423] [<ffffffffa0002f98>] e1000_clean_rx_irq+0x2b8/0x520 [e1000]
[ 225.906423] [<ffffffff8144df56>] ? credit_entropy_bits.part.7+0x176/0x1d0
[ 225.906423] [<ffffffffa0004801>] e1000_clean+0x51/0xc0 [e1000]
[ 225.906423] [<ffffffff815e4cd4>] net_rx_action+0x134/0x260
[ 225.906423] [<ffffffff81045136>] ? native_safe_halt+0x6/0x10
[ 225.906423] [<ffffffff81062620>] __do_softirq+0xc0/0x240
[ 225.906423] [<ffffffff8103cca2>] ? ack_apic_level+0x72/0x130
[ 225.906423] [<ffffffff816fdd5c>] call_softirq+0x1c/0x30
[ 225.906423] [<ffffffff81016775>] do_softirq+0x65/0xa0
[ 225.906423] [<ffffffff810628fe>] irq_exit+0x8e/0xb0
[ 225.906423] [<ffffffff816fe5f3>] do_IRQ+0x63/0xe0
[ 225.906423] [<ffffffff816f406d>] common_interrupt+0x6d/0x6d
[ 225.906423] <EOI>
[ 225.906423] [<ffffffff81084008>] ? hrtimer_start+0x18/0x20
[ 225.906423] [<ffffffff81045136>] ? native_safe_halt+0x6/0x10
[ 225.906423] [<ffffffff8101cc33>] default_idle+0x53/0x1f0
[ 225.906423] [<ffffffff8101dad9>] cpu_idle+0xd9/0x120
[ 225.906423] [<ffffffff816c6db2>] rest_init+0x72/0x80
[ 225.906423] [<ffffffff81d05c4f>] start_kernel+0x3d1/0x3de
[ 225.906423] [<ffffffff81d057ff>] ? pass_bootoption.constprop.2+0xd3/0xd3
[ 225.906423] [<ffffffff81d05397>] x86_64_start_reservations+0x131/0x135
[ 225.906423] [<ffffffff81d05120>] ? early_idt_handlers+0x120/0x120
[ 225.906423] [<ffffffff81d05468>] x86_64_start_kernel+0xcd/0xdc
[ 225.906423] Code: 49 c1 e5 04 4c 03 6a 18 4c 89 ef e8 2f 35 0d 00 49 8b 84 24 60 03 00
[ 225.906423] RIP [<ffffffff8162056c>] __inet_twsk_hashdance+0x8c/0x160
[ 225.906423] RSP <ffff88007fc039d0>
[ 225.906423] CR2: 0000000000000020
[ 226.111238] ---[ end trace 18ecfe1006daa681 ]---
[ 226.111817] Kernel panic - not syncing: Fatal exception in interrupt