在LSM钩子中获取到linux_binprm结构,从中获取到命令行参数。
-
static int get_argv_from_bprm(struct linux_binprm *bprm)
-
{
-
int ret = 0;
-
unsigned long offset, pos;
-
char *kaddr;
-
struct page *page;
-
char argv[PAGE_SIZE] = {0};
-
int i = 0;
-
int argc = 0;
-
int count = 0;
-
if (!bprm)
-
return 0;
-
-
argc = bprm->argc;
-
-
pos = bprm->p;
-
do {
-
offset = pos & ~PAGE_MASK;
-
page = get_arg_page(bprm, pos, 0);
-
if (!page) {
-
ret = 0;
-
goto out;
-
}
-
kaddr = kmap_atomic(page);
-
-
for (i = 0; offset < PAGE_SIZE && count < argc && i < PAGE_SIZE; offset++, pos++) {
-
if (kaddr[offset] == '\0') {
-
count++;
-
pos++;
-
printk("argv is %s\n", argv);
-
memset(argv, 0, sizeof(argv));
-
i = 0;
-
continue;
-
}
-
argv[i] = kaddr[offset];
-
i++;
-
}
-
-
kunmap_atomic(kaddr);
-
put_arg_page(page);
-
} while (offset == PAGE_SIZE);
-
-
ret = 0;
-
-
out:
-
return ret;
-
}
阅读(3930) | 评论(0) | 转发(0) |