diff --git a/source/lib/internal/kernel_module/Makefile b/source/lib/internal/kernel_module/Makefile index 3fec106bbbaa4702def6b4967b77ec75f3ba9d09..61440ba2a41f24c813d9f1180a85ae02603ca53e 100644 --- a/source/lib/internal/kernel_module/Makefile +++ b/source/lib/internal/kernel_module/Makefile @@ -30,6 +30,9 @@ endif ifneq ($(findstring schedtrace,$(TARGET_LIST)),) sysak-objs += modules/schedtrace/schedtrace.o endif +ifneq ($(findstring mmaptrace,$(TARGET_LIST)),) +sysak-objs += modules/mmaptrace/mmaptrace.o +endif obj-m += sysak.o diff --git a/source/lib/internal/kernel_module/modules/mmaptrace/mmaptrace.c b/source/lib/internal/kernel_module/modules/mmaptrace/mmaptrace.c new file mode 100644 index 0000000000000000000000000000000000000000..6f01d8d96789625e41f593bdd1ab86250048232d --- /dev/null +++ b/source/lib/internal/kernel_module/modules/mmaptrace/mmaptrace.c @@ -0,0 +1,595 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "common/proc.h" + +#ifdef CONFIG_X86 +extern struct mm_struct *get_task_mm(struct task_struct *task); + +#define DEFINE_PROC_ATTRIBUTE(name, __write) \ + static int name##_open(struct inode *inode, struct file *file) \ + { \ + return single_open(file, name##_show, PDE_DATA(inode)); \ + } \ + \ + static const struct file_operations name##_fops = { \ + .owner = THIS_MODULE, \ + .open = name##_open, \ + .read = seq_read, \ + .write = __write, \ + .llseek = seq_lseek, \ + .release = single_release, \ + } + +#define DEFINE_PROC_ATTRIBUTE_RW(name) \ + static ssize_t name##_write(struct file *file, \ + const char __user *buf, \ + size_t count, loff_t *ppos) \ + { \ + return name##_store(PDE_DATA(file_inode(file)), buf, \ + count); \ + } \ + DEFINE_PROC_ATTRIBUTE(name, name##_write) + +#define DEFINE_PROC_ATTRIBUTE_RO(name) \ + DEFINE_PROC_ATTRIBUTE(name, NULL) + + +#define MAX_SYMBOL_LEN 64 +#define PATH_LEN 256 +#define STACK_DEPTH 100 +#define STACK_DETAIL_DEPTH 20 +#define PERTASK_STACK 10 +#define LIST_LEN 10 +#define PROC_NUMBUF 128 +#define REGISTER_FAILED 1 + +static bool enable_mmaptrace = false; +static unsigned long mmap_len = 246 << 10; +static pid_t mmap_pid; +static int brk; + +LIST_HEAD(threads_list); +LIST_HEAD(threadvma_list); + +DECLARE_RWSEM(threadslist_sem); +DECLARE_RWSEM(vmalist_sem); + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) +static struct kprobe kp_mmap = { + .symbol_name = "ksys_mmap_pgoff", +}; + +static struct kprobe kp_brk = { + .symbol_name = "do_brk_flags", +}; +#else +static struct kprobe kp_mmap = { + .symbol_name = "vm_mmap_pgoff", +}; + +static struct kprobe kp_brk = { + .symbol_name = "do_brk", +}; +#endif + +struct stack_info { + unsigned long bp; + char path[PATH_LEN]; +}; + +struct user_stack_detail { + struct list_head list; + int is_brk; +#if defined(DIAG_ARM64) + //struct user_pt_regs regs; +#else + //struct pt_regs regs; +#endif + //unsigned long ip; + //unsigned long bp; + //unsigned long sp; + struct stack_info stack[STACK_DETAIL_DEPTH]; +}; + +struct task_info{ + pid_t pid; + pid_t tgid; + struct list_head task_list; + unsigned long mmap_count; + struct list_head vma_list; + unsigned long userstack_list_len; + struct list_head userstack_list; + char comm[TASK_COMM_LEN]; +}; + +struct vma_info{ + struct list_head list; + pid_t pid; + unsigned long start; + unsigned long end; + int exectue; + char path[PATH_LEN]; +}; + +struct stack_frame_user { + const void __user *next_fp; + unsigned long ret_addr; +}; + + +static void save_mmapstack_trace_user(struct task_struct *task, struct task_info *tsk) +{ + struct list_head *vma_entry; + const struct pt_regs *regs = task_pt_regs(current); + const void __user *fp = (const void __user *)regs->sp; + int stack_len = 0 ; + int i; + + struct user_stack_detail *new_stack = kzalloc(sizeof(struct user_stack_detail),GFP_KERNEL); + if (!new_stack) + return; + new_stack->is_brk = brk; + for (i = 0; i < STACK_DEPTH; i++){ + if (stack_len > STACK_DETAIL_DEPTH) + break; + list_for_each(vma_entry, &threadvma_list){ + //struct vma_info *vma = (struct vma_info *)vma_entry; + struct vma_info *vma = container_of(vma_entry, struct vma_info, list); + unsigned long tmp; + + if (!copy_from_user(&tmp, fp+i*__SIZEOF_LONG__, __SIZEOF_LONG__)) { + if ((tmp >= vma->start) && (tmp <= vma->end)) { + new_stack->stack[stack_len].bp = tmp; + strcpy(new_stack->stack[stack_len].path,vma->path); + stack_len++; + } + } + } + } + list_add_tail(&new_stack->list, &tsk->userstack_list); +} + +static int save_calltrace(struct pt_regs *regs) +{ + struct list_head *tsk_entry; + struct task_info *new_tsk; + pid_t tgid = 0; + + //down_write(&threadslist_sem); + list_for_each(tsk_entry, &threads_list){ + struct task_info *tsk = container_of(tsk_entry, struct task_info, task_list); + tgid = tsk->tgid; + if (tsk->pid == current->pid){ + if (tsk->userstack_list_len > LIST_LEN){ + return 0; + } + save_mmapstack_trace_user(current,tsk); + return 0; + } + //save stack + } + if (tgid == current->tgid){ + new_tsk = kzalloc(sizeof(struct task_info),GFP_KERNEL); + if (!new_tsk) + return 0; + new_tsk->pid = current->pid; + new_tsk->tgid = tgid; + memcpy(new_tsk->comm,current->comm,sizeof(new_tsk->comm)); + new_tsk->mmap_count++; + INIT_LIST_HEAD(&new_tsk->userstack_list); + save_mmapstack_trace_user(current,new_tsk); + list_add_tail(&new_tsk->task_list,&threads_list); + } + //up_write(&threadslist_sem); + return 0; +} + +static int before_mmap_pgoff(struct kprobe *p, struct pt_regs *regs) +{ + int ret; + + brk = 0; + if (regs->si < mmap_len){ + return 0; + } + if (!current || !current->mm) + return 0; + + ret = save_calltrace(regs); + return 0; +} + +static void after_mmap_pgoff(struct kprobe *p, struct pt_regs *regs, + unsigned long flags) +{ + return; +} + +static void get_filename(char *buf, const struct path *path, size_t size) +{ + //int res = -1; + //char *end; + if (size) { + char *p = d_path(path, buf, size); + if (!IS_ERR(p)) { + strcpy(buf,p); + //end = mangle_path(buf, p, "\n"); + //if (end) + //res = end - buf; + } + } + return; +} + +static int mmaptrace_print_show(struct seq_file *m, void *v) +{ + struct list_head *tsk_entry; + struct list_head *stack_entry; + int loop_count = 0; + char *syscall_name; + int i; + + //down_read(&threadslist_sem); + if (list_empty(&threads_list)){ + //up_read(&threadslist_sem); + seq_printf(m, "task list is empty\n"); + return 0; + } + + list_for_each(tsk_entry, &threads_list){ + struct task_info *tsk = container_of(tsk_entry, struct task_info, task_list); + seq_printf(m, "pid[%d],name[%s],tgid[%d]\n", + tsk->pid, tsk->comm, tsk->tgid); + list_for_each(stack_entry, &tsk->userstack_list){ + struct user_stack_detail *user_stack = (struct user_stack_detail *)stack_entry; + loop_count++; + syscall_name = user_stack->is_brk ? "brk" : "mmap"; + seq_printf(m, "%s,用户态堆栈%d:\n", syscall_name,loop_count); + for (i = 0; i < STACK_DETAIL_DEPTH; i++) { + if (user_stack->stack[i].bp == 0) { + continue; + } + seq_printf(m,"#~ 0x%lx", user_stack->stack[i].bp); + seq_printf(m," %s\n",user_stack->stack[i].path); + } + } + } + //up_read(&threadslist_sem); + return 0; +} + +DEFINE_PROC_ATTRIBUTE_RO(mmaptrace_print); + +static int mmaptrace_pid_show(struct seq_file *m, void *v) +{ + seq_printf(m, "pid:%d, len:%ld\n", mmap_pid, mmap_len); + return 0; + +} + +static ssize_t mmaptrace_pid_store(void *priv, const char __user *buf, size_t count) +{ + struct task_struct *tsk; + struct task_info *new_tsk; + struct mm_struct *mm; + struct file *vma_file; + struct vm_area_struct *vma; + struct vma_info *new_vma; + struct pid *pid; + char buffer[PROC_NUMBUF]; + char buff[PATH_LEN]; + pid_t pid_i; + int err = -1; + + if (!enable_mmaptrace){ + pr_warn("mmaptrace disabled!"); + return count; + } + + + memset(buffer, 0, sizeof(buffer)); + if (count > sizeof(buffer) - 1) + count = sizeof(buffer) - 1; + if (copy_from_user(buffer, buf, count)) { + return -EFAULT; + } + + err = kstrtoint(strstrip(buffer), 0, &pid_i); + if (err) + return -EINVAL; + + if (!list_empty(&threads_list)){ + struct list_head *entry; + list_for_each(entry, &threads_list){ + struct task_info *pos = (struct task_info *)entry; + if (pos->pid == pid_i) + return count; + } + } + + rcu_read_lock(); + + pid= find_get_pid(pid_i); + tsk = pid_task(pid, PIDTYPE_PID); + if (!tsk || !(tsk->mm)){ + rcu_read_unlock(); + return -EINVAL; + } + mmap_pid = pid_i; + + if (mmap_pid != 0 ){ + new_tsk = kzalloc(sizeof(struct task_info),GFP_KERNEL); + if (!new_tsk) + goto failed_tsk; + new_tsk->pid = mmap_pid; + new_tsk->tgid = tsk->tgid; + memcpy(new_tsk->comm,tsk->comm,sizeof(tsk->comm)); + new_tsk->mmap_count++; + //INIT_LIST_HEAD(&new_tsk->vma_list); + INIT_LIST_HEAD(&new_tsk->userstack_list); + + mm = get_task_mm(tsk); + + if (IS_ERR_OR_NULL(mm)){ + rcu_read_unlock(); + return -EINVAL; + } + + if (!down_read_trylock(&mm->mmap_sem)){ + rcu_read_unlock(); + return -EINTR; + } + for (vma = mm->mmap; vma; vma = vma->vm_next){ + //if (vma->vm_file && vma->vm_flags & VM_EXEC && !inode_open_for_write(file_inode(vma->vm_file))){ + if (vma->vm_file && vma->vm_flags & VM_EXEC){ + new_vma = kzalloc(sizeof(struct vma_info),GFP_KERNEL); + if (!new_vma) + goto failed_vma; + new_vma->start = vma->vm_start; + new_vma->pid = current->pid; + new_vma->end = vma->vm_end; + vma_file = vma->vm_file; + + if (vma_file){ + get_filename(buff, &vma_file->f_path, PATH_LEN); + } + strcpy(new_vma->path, buff); + //(&vmalist_sem); + list_add_tail(&new_vma->list,&threadvma_list); + //up_write(&vmalist_sem); + } + } + up_read(&mm->mmap_sem); + //down_write(&threadslist_sem); + list_add_tail(&new_tsk->task_list, &threads_list); + //up_write(&threadslist_sem); + } + rcu_read_unlock(); + return count; +failed_vma: + kfree(new_tsk); +failed_tsk: + rcu_read_unlock(); + return -ENOMEM; +} + +DEFINE_PROC_ATTRIBUTE_RW(mmaptrace_pid); + +static ssize_t mmaptrace_len_store(void *priv, const char __user *buf, size_t count) +{ + char buffer[PROC_NUMBUF]; + unsigned long length; + int err = -1; + + memset(buffer, 0, sizeof(buffer)); + if (count > sizeof(buffer) - 1) + count = sizeof(buffer) - 1; + if (copy_from_user(buffer, buf, count)) { + return -EFAULT; + } + + err = _kstrtoul(strstrip(buffer), 0, &length); + if (err) + return -EINVAL; + mmap_len = length; + return count; +} + +static int mmaptrace_len_show(struct seq_file *m, void *v) +{ + seq_printf(m, "monitor len: %ld\n", mmap_len); + return 0; + +} + +DEFINE_PROC_ATTRIBUTE_RW(mmaptrace_len); + +static int before_do_brk(struct kprobe *p, struct pt_regs *regs) +{ + int ret; + + brk = 1; + if (regs->si < mmap_len){ + return 0; + } + + if (!current || !current->mm) + return 0; + ret = save_calltrace(regs); + return 0; +} + +static void after_do_brk(struct kprobe *p, struct pt_regs *regs, + unsigned long flags) +{ + return; +} + +static int handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr) +{ + pr_info("fault_handler: p->addr = 0x%p, trap #%dn", p->addr, trapnr); + return 0; +} + +static int mmaptrace_enable(void) +{ + int ret_mmap, ret_brk; + + kp_mmap.pre_handler = before_mmap_pgoff; + kp_mmap.post_handler = after_mmap_pgoff; + kp_mmap.fault_handler = handler_fault; + + kp_brk.pre_handler = before_do_brk; + kp_brk.post_handler = after_do_brk; + kp_brk.fault_handler = handler_fault; + + ret_mmap = register_kprobe(&kp_mmap); + if (ret_mmap < 0) { + pr_err("register_kprobe mmap failed, returned %d\n", ret_mmap); + return -REGISTER_FAILED; + } + + ret_brk = register_kprobe(&kp_brk); + if (ret_brk < 0) { + unregister_kprobe(&kp_mmap); + pr_err("register_kprobe brk failed, returned %d\n", ret_brk); + return -REGISTER_FAILED; + } + + pr_info("Planted kprobe at %p\n", kp_mmap.addr); + pr_info("Planted kprobe at %p\n", kp_brk.addr); + return 0; +} + +void mmaptrace_disable(void) +{ + unregister_kprobe(&kp_mmap); + unregister_kprobe(&kp_brk); + pr_info("kprobe at %p unregistered\n", kp_mmap.addr); + pr_info("kprobe at %p unregistered\n", kp_brk.addr); +} + +static int mmaptrace_enable_show(struct seq_file *m, void *v) +{ + seq_printf(m, "%d\n", (int)enable_mmaptrace); + return 0; +} + +static ssize_t mmaptrace_enable_store(void *priv, const char __user *buf, size_t count) +{ + char buffer[PROC_NUMBUF]; + int val; + int err = -1; + + memset(buffer, 0, sizeof(buffer)); + if (count > sizeof(buffer) - 1) + count = sizeof(buffer) - 1; + if (copy_from_user(buffer, buf, count)) { + return -EFAULT; + } + err = kstrtoint(strstrip(buffer), 0, &val); + + if (val == 1){ + if (!mmaptrace_enable()) + enable_mmaptrace = true; + }else if (val == 0){ + if (enable_mmaptrace){ + mmaptrace_disable(); + enable_mmaptrace = false; + } + } + return count; +} + +DEFINE_PROC_ATTRIBUTE_RW(mmaptrace_enable); + +int mmaptrace_init(void) +{ + struct proc_dir_entry *parent_dir; + struct proc_dir_entry *entry_print; + struct proc_dir_entry *entry_pid; + struct proc_dir_entry *entry_len; + struct proc_dir_entry *entry_enable; + + parent_dir = sysak_proc_mkdir("mmaptrace"); + if (!parent_dir) { + goto failed_root; + } + + entry_print = proc_create("mmaptrace_print", 0444, parent_dir, &mmaptrace_print_fops); + if(!entry_print) { + goto failed; + } + + entry_pid = proc_create("mmaptrace_pid", 0664, parent_dir, &mmaptrace_pid_fops); + if(!entry_pid) { + goto failed; + } + + entry_len = proc_create("mmaptrace_len", 0444, parent_dir, &mmaptrace_len_fops); + if(!entry_len) { + goto failed; + } + + entry_enable = proc_create("mmaptrace_enable", 0664, parent_dir, &mmaptrace_enable_fops); + if(!entry_enable) { + goto failed; + } + return 0; + +failed: + sysak_remove_proc_entry("mmaptrace"); +failed_root: + return -1; +} + +int mmaptrace_exit(void) +{ + struct list_head *tsk_entry; + struct list_head *vma_entry; + struct list_head *tsk_prev; + struct list_head *vma_prev; + + if (enable_mmaptrace){ + mmaptrace_disable(); + } + + list_for_each(tsk_entry, &threads_list){ + struct task_info *tsk = container_of(tsk_entry, struct task_info, task_list); + tsk_prev = tsk_entry->prev; + + list_del(tsk_entry); + kfree(tsk); + tsk_entry = tsk_prev; + } + + list_for_each(vma_entry, &threadvma_list){ + struct vma_info *vma = container_of(vma_entry, struct vma_info, list); + vma_prev = vma_entry->prev; + + list_del(vma_entry); + kfree(vma); + vma_entry = vma_prev; + } + return 0; +} +#endif diff --git a/source/lib/internal/kernel_module/sysak_mods.c b/source/lib/internal/kernel_module/sysak_mods.c index 021c9d1216caed0cfd22ee1815834de44ef861c7..5f9fd18f67550478f6877b4565230f0655fadd7c 100644 --- a/source/lib/internal/kernel_module/sysak_mods.c +++ b/source/lib/internal/kernel_module/sysak_mods.c @@ -49,6 +49,14 @@ int __attribute__((weak)) schedtrace_exit(void) { return 0; } +int __attribute__((weak)) mmaptrace_init(void) +{ + return 0; +} +int __attribute__((weak)) mmaptrace_exit(void) +{ + return 0; +} struct sysak_module sysak_modules[] = { { "trace_sig", trace_sig_init, trace_sig_exit}, @@ -56,6 +64,7 @@ struct sysak_module sysak_modules[] = { { "trace_irqoff", trace_irqoff_init, trace_irqoff_exit}, { "task_ctl", task_ctl_init, task_ctl_exit}, { "schedtrace", schedtrace_init, schedtrace_exit}, + { "mmap_trace", mmaptrace_init, mmaptrace_exit}, }; const int sysk_module_num = sizeof(sysak_modules) / sizeof(struct sysak_module); diff --git a/source/tools/detect/sysconf/Makefile b/source/tools/detect/sysconf/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..3327b9d82bc0b4cd5e939797fb44b02c62836966 --- /dev/null +++ b/source/tools/detect/sysconf/Makefile @@ -0,0 +1,3 @@ +target := sysconf + +include $(SRC)/mk/sh.mk diff --git a/source/tools/detect/sysconf/confcheck/Makefile b/source/tools/detect/sysconf/confcheck/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..859ba9aab33506d0bf65fe0aaa42e178c20aed03 --- /dev/null +++ b/source/tools/detect/sysconf/confcheck/Makefile @@ -0,0 +1,5 @@ +target := confcheck + +mods += $(target) + +include $(SRC)/mk/py.mk diff --git a/source/tools/detect/sysconf/confcheck/confcheck.py b/source/tools/detect/sysconf/confcheck/confcheck.py new file mode 100644 index 0000000000000000000000000000000000000000..772720fb1892c315de2485f8cae2f676097aeca2 --- /dev/null +++ b/source/tools/detect/sysconf/confcheck/confcheck.py @@ -0,0 +1,137 @@ +#!/usr/bin/python +#coding:utf-8 + +import re +import os.path + +uname_command = "uname -r" + +kernel_version = "" +kversion_7u_2016 = "3.10.0-327.ali2016.alios7.x86_64" + +kversion_alinux3 = "5.10.60-9.al8.x86_64" +alinux3_etc_sysctl = "/etc/sysctl.d/50-aliyun.conf" +dict_paraments = {'kernel.unprivileged_bpf_disabled': 1} + +file_max = "/proc/sys/fs/file-max" +nr_open = "/proc/sys/fs/nr_open" +etc_security_limit = "/etc/security/limits.conf" + +cgroup_cpu_cfs_quota_us = "/sys/fs/cgroup/cpuset,cpu,cpuacct/cpu.cfs_quota_us" + +pagecache_dirty_bytes = "/proc/sys/vm/dirty_bytes" +pagecache_dirty_ratio = "/proc/sys/vm/dirty_ratio" +pagecache_bk_dirty_bytes = "/proc/sys/vm/dirty_background_bytes" +pagecache_bk_dirty_ratio = "/proc/sys/vm/dirty_background_ratio" +meminfo = "/proc/meminfo" + +def exectue_cmd(command): + command=command.replace("\n", "") + command_fd = os.popen(command, "r") + ret = command_fd.read() + command_fd.close() + ret.strip('\n') + return ret + +def get_kernelversion(): + global kernel_version + kernel_version = exectue_cmd(uname_command) + +def check_pagecache_config(): + pagecache_watermask = 0 + mem_total_val = 0 + pagecache_bk_watermask = 0 + + dirty_bytes_fd = open(pagecache_dirty_bytes,"r") + dirty_bytes_val = dirty_bytes_fd.read(30) + dirty_bytes_fd.close() + + dirty_ratio_fd = open(pagecache_dirty_ratio,"r") + dirty_ratio_val = dirty_ratio_fd.read(30) + dirty_ratio_fd.close() + + bk_dirty_bytes_fd = open(pagecache_bk_dirty_bytes,"r") + bk_dirty_bytes_val = bk_dirty_bytes_fd.read(30) + bk_dirty_bytes_fd.close() + + bk_dirty_ratio_fd = open(pagecache_bk_dirty_ratio,"r") + bk_dirty_ratio_val = bk_dirty_ratio_fd.read(30) + bk_dirty_ratio_fd.close() + + meminfo_fd= open(meminfo,"r") + for line in meminfo_fd.readlines(): + mem_total= re.search(r'MemTotal: *(\d+) kB', line, re.I) + if mem_total: + mem_total_val = mem_total.group(1) + pagecache_watermask = int(mem_total_val)*1024*20/100 + + if dirty_bytes_val: + if int(dirty_ratio_val) < 20: + print("vm.dirty_ratio=%s 低于20,可能造成pagecache频繁回写,io拥塞" %(dirty_ratio_val)) + else: + if dirty_bytes_val <= pagecache_watermask: + print("vm.dirty_bytes=%s 低于20%Mem,可能造成pagecache频繁回写,io拥塞" %(dirty_bytes_val)) + meminfo_fd.close() + + pagecache_bk_watermask = int(mem_total_val)*1024*10/100 + + if bk_dirty_bytes_val: + if int(bk_dirty_ratio_val) < 10: + print("vm.dirty_background_bytes=%s 低于10,可能造成pagecache后台频繁回写,io拥塞" %(bk_dirty_ratio_val)) + else: + if bk_dirty_bytes_val <= pagecache_bk_watermask: + print("vm.dirty_bytes=%s 低于10%Mem,可能造成pagecache后台频繁回写,io拥塞" %(bk_dirty_bytes_val)) + return + +def check_bpf_config(): + return + +def check_cgroup_config(): + if kernel_version == kversion_7u_2016: + cgroup_cpu_cfs_fd = open(cgroup_cpu_cfs_quota_us,"r") + cgroup_cpu_cfs_val = cgroup_cpu_cfs_fd.read(30) + if int(cgroup_cpu_cfs_val) != -1: + print("内核版本低于3.10.0-327.ali2014.alios7.x86_64,不能配置cpu.cfs_quota_us参数") + return + +def check_etc_config(): + if kernel_version == kversion_alinux3: + alinux3_etc_fd = open(alinux3_etc_sysctl,"r") + for line in alinux3_etc_fd.readlines(): + match_parament= re.search( r'kernel.unprivileged_bpf_disabled = (\d+)', line, re.I) + if match_parament: + for parament in dict_paraments.keys(): + if dict_paraments[parament] == match_parament.group(1): + print("kernel.unprivileged_bpf_disabled应该配置成1") + alinux3_etc_fd.close() + return + +def check_file_config(): + file_max_fd = open(file_max,"r") + nr_open_fd = open(nr_open,"r") + file_max_val = file_max_fd.read(30) + nr_open_val = nr_open_fd.read(30) + + if int(file_max_val) <= int(nr_open_val): + print("fs.file-max应该大于fs.nr_open") + file_max_fd.close() + nr_open_fd.close() + + etc_security_limit_fd = open(etc_security_limit,"r") + for line in etc_security_limit_fd.readlines(): + match_parament = re.search( r'\* soft nofile (\d+)', line, re.I) + if match_parament: + if int(match_parament.group(1)) > int(nr_open_val): + print("soft nofile不能超过fs.nr_open" ) + etc_security_limit_fd.close() + + +def main(): + get_kernelversion() + check_file_config() + check_etc_config() + check_cgroup_config() + check_pagecache_config() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/source/tools/detect/sysconf/sysconf.sh b/source/tools/detect/sysconf/sysconf.sh new file mode 100644 index 0000000000000000000000000000000000000000..0f8f6e75420ea780e2cf4db0ff4cbe30555a30d7 --- /dev/null +++ b/source/tools/detect/sysconf/sysconf.sh @@ -0,0 +1,273 @@ +#!/bin/sh +#****************************************************************# +# ScriptName: sysconf.sh +# Author: zhao.hang@alibaba-inc.com +# Create Date: 2021-08-16 15:22 +# Modify Author: $SHTERM_REAL_USER@alibaba-inc.com +# Modify Date: 2021-08-16 15:22 +# Function: +#***************************************************************# + +#need modify RESULT_DIR on present system +RESULT_DIR="/var/log/sysak" +CURRENT_VERSION=`uname -r`"-"`date "+%Y%m%d-%H%M%S"` +SUBNAME="sysconf" +DIFF_RESULT="diff_result" +PID_MAX=`cat /proc/sys/kernel/pid_max` +CURRENT_TIME=`date "+%Y%m%d-%H%M%S"` + +CURRINFO_DIR="$RESULT_DIR/$SUBNAME/sysconf-$CURRENT_VERSION" +OLDINFO_DIR="$RESULT_DIR/$SUBNAME/sysconf-$OLD_VERSION" +DIFF_PATH="$RESULT_DIR/$SUBNAME/$DIFF_RESULT" +DIFF_CURR="$DIFF_PATH/sysconf-$CURRENT_VERSION" +#DIFF_OLD="$DIFF_PATH/sysconf-$OLD_VERSION" + +procname_arry=(async_load_calc cgroups dma fb mtrr misc partitions mount swaps) + +warn() { + echo "sysAK:$SUBNAME: $*" >&2 +} +die() { + warn "$*" + exit 0 +} + +usage() { + echo "usage: sys_conf