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_path.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 "ertp.h"
#include "ertp_path.h"
#include <linux/cred.h>
#include <linux/mm.h>
#include <linux/slab.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0)
#define ertp_mm_lock(m) down_read(&(m)->mmap_sem)
#define ertp_mm_unlock(m) up_read(&(m)->mmap_sem)
#else
#define ertp_mm_lock(m) mmap_read_lock(m)
#define ertp_mm_unlock(m) mmap_read_unlock(m)
#endif
static struct kmem_cache *ertp_path_allocator = NULL;
int ertp_path_allocator_init(void) {
ertp_path_allocator = kmem_cache_create(
"ertp_path_allocator", sizeof(struct ertp_path),
__alignof__(struct ertp_path), SLAB_RECLAIM_ACCOUNT, NULL);
if (!ertp_path_allocator) {
return -ENOMEM;
}
return 0;
}
void ertp_path_allocator_deinit(void) {
if (ertp_path_allocator) {
kmem_cache_destroy(ertp_path_allocator);
}
}
static inline struct ertp_path *ertp_path_alloc(void) {
struct ertp_path *result = kmem_cache_zalloc(ertp_path_allocator, GFP_KERNEL);
if (unlikely(!result)) {
return NULL;
}
result->size = PATH_MAX;
result->buf = kzalloc(result->size, GFP_KERNEL);
if (unlikely(!result->buf)) {
kmem_cache_free(ertp_path_allocator, result);
return NULL;
}
atomic_set(&result->count, 1);
return result;
}
static inline void ertp_path_free(struct ertp_path *path) {
kfree(path->buf);
kmem_cache_free(ertp_path_allocator, path);
}
struct ertp_path *ertp_path_ref(struct ertp_path *path) {
if (!path || IS_ERR(path)) return NULL;
BUG_ON(!atomic_read(&path->count));
atomic_inc(&path->count);
return path;
}
void ertp_path_unref(struct ertp_path *path) {
if (!path || IS_ERR(path)) return;
BUG_ON(!atomic_read(&path->count));
if (!atomic_dec_and_test(&path->count)) return;
ertp_path_free(path);
}
static inline struct ertp_path *process_path_result(struct ertp_path *result,
char *d_path_result) {
if (IS_ERR(d_path_result)) {
int err = PTR_ERR(d_path_result);
ertp_path_unref(result);
return ERR_PTR(err);
}
result->ptr = d_path_result;
result->size = strlen(d_path_result) + 1;
return result;
}
struct ertp_path *ertp_path_file_new(const struct path *path) {
char *tmp;
struct ertp_path *result = ertp_path_alloc();
if (unlikely(!result)) {
return ERR_PTR(-ENOMEM);
}
tmp = d_path(path, result->buf, result->size);
return process_path_result(result, tmp);
}
struct ertp_path *ertp_path_process_new(void) {
char *tmp;
struct ertp_path *result;
struct mm_struct *mm = current->mm;
if (unlikely(!mm)) {
return ERR_PTR(-ENODATA);
}
result = ertp_path_alloc();
if (unlikely(!result)) {
return ERR_PTR(-ENOMEM);
}
ertp_mm_lock(mm);
if (likely(mm->exe_file)) {
tmp = d_path(&mm->exe_file->f_path, result->buf, result->size);
} else {
tmp = ERR_PTR(-ENODATA);
}
ertp_mm_unlock(mm);
return process_path_result(result, tmp);
}