Server IP : 103.169.32.36 / Your IP : 216.73.217.13 Web Server : Apache System : Linux web.dpmptsp 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : apache ( 48) PHP Version : 5.6.40 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/opt/eset/efs/eventd/eset_rtp/ |
Upload File : |
| Current File : /var/opt/eset/efs/eventd/eset_rtp/ertp_handlers_unlink.c |
/*
* eset_rtp (ESET Real-time file system protection module)
* Copyright (C) 1992-2023 ESET, spol. s r.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* In case of any questions, you can contact us at ESET, spol. s r.o., Einsteinova 24, 851 01 Bratislava, Slovakia.
*/
#include <linux/file.h>
#include <linux/namei.h>
#include "ertp.h"
#include "ertp_event_check.h"
#include "ertp_ftrace_utils.h"
#include "ertp_handlers_unlink.h"
#include "ertp_logs.h"
#ifdef ERTP_KERNEL_USES_SYSCALL_WRAPPER
sys_regs_t ertp_original_native_64_unlink;
sys_regs_t ertp_original_native_32_unlink;
sys_regs_t ertp_original_native_64_unlinkat;
sys_regs_t ertp_original_native_32_unlinkat;
#else
sys_unlink_t ertp_original_native_64_unlink;
sys_unlinkat_t ertp_original_native_64_unlinkat;
#endif
#ifdef ERTP_KERNEL_USES_SYSCALL_WRAPPER
static long ertp_unlink_handler_int(int dfd, const char __user *pathname,
sys_regs_t original_call,
struct pt_regs *regs) {
int error;
long ret;
struct path path;
struct ertp_path *file_path = NULL;
error = user_path_at(dfd, pathname, 0, &path);
if (!error) {
file_path = ertp_path_file_new(&path);
}
ret = original_call(regs);
if (error) {
goto exit;
}
if (!ret) {
ertp_check_remove(file_path, &path);
}
ertp_path_unref(file_path);
path_put(&path);
exit:
ertp_handler_end();
return ret;
}
asmlinkage long notrace ertp_handler_native_64_unlink(struct pt_regs *regs) {
const char __user *pathname = ERTP_SYSCALL64_ARG0(const char __user *, regs);
return ertp_unlink_handler_int(AT_FDCWD, pathname,
ertp_original_native_64_unlink, regs);
}
asmlinkage long notrace ertp_handler_native_32_unlink(struct pt_regs *regs) {
const char __user *pathname = ERTP_SYSCALL32_ARG0(const char __user *, regs);
return ertp_unlink_handler_int(AT_FDCWD, pathname,
ertp_original_native_32_unlink, regs);
}
asmlinkage long notrace ertp_handler_native_64_unlinkat(struct pt_regs *regs) {
int dfd = ERTP_SYSCALL64_ARG0(int, regs);
const char __user *pathname = ERTP_SYSCALL64_ARG1(const char __user *, regs);
int flag = ERTP_SYSCALL64_ARG2(int, regs);
if (flag == AT_REMOVEDIR) {
long ret = ertp_original_native_64_unlinkat(regs);
ertp_handler_end();
return ret;
}
return ertp_unlink_handler_int(dfd, pathname,
ertp_original_native_64_unlinkat, regs);
}
asmlinkage long notrace ertp_handler_native_32_unlinkat(struct pt_regs *regs) {
int dfd = ERTP_SYSCALL32_ARG0(int, regs);
const char __user *pathname = ERTP_SYSCALL32_ARG1(const char __user *, regs);
int flag = ERTP_SYSCALL32_ARG2(int, regs);
if (flag == AT_REMOVEDIR) {
long ret = ertp_original_native_32_unlinkat(regs);
ertp_handler_end();
return ret;
}
return ertp_unlink_handler_int(dfd, pathname,
ertp_original_native_32_unlinkat, regs);
}
#else
asmlinkage long notrace
ertp_handler_native_64_unlink(const char __user *pathname) {
int error;
long ret;
struct path path;
struct ertp_path *file_path = NULL;
error = user_path_at(AT_FDCWD, pathname, 0, &path);
if (!error) {
file_path = ertp_path_file_new(&path);
}
ret = ertp_original_native_64_unlink(pathname);
if (error) {
goto exit;
}
if (!ret) {
ertp_check_remove(file_path, &path);
}
ertp_path_unref(file_path);
path_put(&path);
exit:
ertp_handler_end();
return ret;
}
asmlinkage long notrace ertp_handler_native_64_unlinkat(
int dfd, const char __user *pathname, int flag) {
int error;
long ret;
struct path path;
struct ertp_path *file_path = NULL;
if (flag == AT_REMOVEDIR) {
ret = ertp_original_native_64_unlinkat(dfd, pathname, flag);
goto exit;
}
error = user_path_at(dfd, pathname, 0, &path);
if (!error) {
file_path = ertp_path_file_new(&path);
}
ret = ertp_original_native_64_unlinkat(dfd, pathname, flag);
if (error) {
goto exit;
}
if (!ret) {
ertp_check_remove(file_path, &path);
}
ertp_path_unref(file_path);
path_put(&path);
exit:
ertp_handler_end();
return ret;
}
#endif