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/ewap/eset_wap/ |
Upload File : |
| Current File : /var/opt/eset/efs/ewap/eset_wap/ewap_dev.c |
/*
* eset_wap (ESET Web Access 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 "ewap_dev.h"
#include "eset_wap.h"
#include "ewap_connect_data.h"
#include "ewap_helpers.h"
#include <linux/device.h>
#include <linux/export.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/version.h>
static struct class *ewap_device_class;
static struct device *ewap_device;
static dev_t ewap_dev;
static long ewap_dev_ioctl(struct file *file, unsigned int cmd,
unsigned long arg);
static struct file_operations ewap_ioctl_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = ewap_dev_ioctl,
};
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
#if defined(RHEL_RELEASE_CODE) && defined(RHEL_RELEASE_VERSION)
#if (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(8, 1))
#define ewap_access_ok(addr, size) access_ok(addr, size)
#else
#define ewap_access_ok(addr, size) access_ok(VERIFY_WRITE, addr, size)
#endif
#else
#define ewap_access_ok(addr, size) access_ok(VERIFY_WRITE, addr, size)
#endif
#else
#define ewap_access_ok(addr, size) access_ok(addr, size)
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
#if defined(RHEL_RELEASE_CODE) && defined(RHEL_RELEASE_VERSION)
#if (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 4))
#define ewap_class_create(name) class_create(name)
#else
#define ewap_class_create(name) class_create(THIS_MODULE, name)
#endif
#else
#define ewap_class_create(name) class_create(THIS_MODULE, name)
#endif
#else
#define ewap_class_create(name) class_create(name)
#endif
static long ewap_dev_handle_get_connection_info_query(
struct eset_wap_get_connection_info __user *arg) {
struct eset_wap_get_connection_info query;
struct ewap_connect_data data;
unsigned long n;
long err = 0;
bool ok;
n = copy_from_user(&query, arg, sizeof(struct eset_wap_get_connection_info));
if (unlikely(n != 0)) {
ewap_pr_log(EWAP_LOG_ERRORS,
"EWAP_GET_CONNECTION_INFO_QUERY failed: copy_from_user of "
"query failed");
return -EFAULT;
}
if (unlikely(
query.result.path.buffer == NULL ||
!ewap_access_ok(query.result.path.buffer, query.result.path.size))) {
ewap_pr_log(
EWAP_LOG_ERRORS,
"EWAP_GET_CONNECTION_INFO_QUERY failed: invalid pointer for path");
return -EFAULT;
}
switch (query.type) {
case EWAP_ADDRESS_TYPE_V4:
ok = ewap_connect_data_get_v4_connection(&query.address.v4, &data);
break;
case EWAP_ADDRESS_TYPE_V6:
ok = ewap_connect_data_get_v6_connection(&query.address.v6, &data);
break;
default:
ewap_pr_log(
EWAP_LOG_ERRORS,
"EWAP_GET_CONNECTION_INFO_QUERY failed: unknown address type");
return -EFAULT;
}
if (!ok) {
ewap_pr_log(EWAP_LOG_IOCTL,
"EWAP_GET_CONNECTION_INFO_QUERY: process not found");
return -ENODATA;
}
query.result.pid = (int32_t)data.pid;
query.result.uid = (uint32_t)data.uid;
ewap_pr_log(EWAP_LOG_IOCTL,
"EWAP_GET_CONNECTION_INFO_QUERY: process found (pid: %d, uid: "
"%u, path: %s)",
query.result.pid, query.result.uid,
data.path ? data.path->ptr : "-");
if (data.path) {
if (data.path->size > query.result.path.size) {
ewap_pr_log(EWAP_LOG_IOCTL,
"EWAP_GET_CONNECTION_INFO_QUERY: provided buffer for path "
"was too small");
err = -ENOBUFS;
goto end;
}
n = copy_to_user(query.result.path.buffer, data.path->ptr, data.path->size);
if (unlikely(n != 0)) {
ewap_pr_log(
EWAP_LOG_ERRORS,
"EWAP_GET_CONNECTION_INFO_QUERY failed: copy_to_user of path failed");
err = -EFAULT;
goto end;
}
}
n = copy_to_user(arg, &query, sizeof(struct eset_wap_get_connection_info));
if (unlikely(n != 0)) {
ewap_pr_log(
EWAP_LOG_ERRORS,
"EWAP_GET_CONNECTION_INFO_QUERY failed: copy_to_user of query failed");
err = -EFAULT;
goto end;
}
end:
ewap_path_unref(data.path);
return err;
}
static long ewap_dev_ioctl(struct file *file, unsigned int cmd,
unsigned long arg) {
switch (cmd) {
case EWAP_GET_CONNECTION_INFO_QUERY:
return ewap_dev_handle_get_connection_info_query(
(struct eset_wap_get_connection_info __user *)arg);
default:
ewap_pr_log(EWAP_LOG_ERRORS, "unknown ioctl call");
break;
}
return -EINVAL;
}
int ewap_dev_init(void) {
int major;
major = register_chrdev(0, EWAP_DEVICE_NAME, &ewap_ioctl_fops);
if (major < 0) {
return major;
}
ewap_dev = MKDEV(major, 0);
ewap_device_class = ewap_class_create(EWAP_DEVICE_NAME);
if (IS_ERR(ewap_device_class)) {
unregister_chrdev(major, EWAP_DEVICE_NAME);
return PTR_ERR(ewap_device_class);
}
ewap_device =
device_create(ewap_device_class, NULL, ewap_dev, NULL, EWAP_DEVICE_NAME);
if (IS_ERR(ewap_device)) {
class_destroy(ewap_device_class);
unregister_chrdev(major, EWAP_DEVICE_NAME);
return PTR_ERR(ewap_device);
}
return 0;
}
void ewap_dev_deinit(void) {
device_destroy(ewap_device_class, ewap_dev);
class_destroy(ewap_device_class);
unregister_chrdev(MAJOR(ewap_dev), EWAP_DEVICE_NAME);
}