#/** * @package Akismet */ /* Plugin Name: Akismet Anti-spam: Spam Protection Plugin URI: https://akismet.com/ Description: Used by millions, Akismet is quite possibly the best way in the world to protect your blog from spam. Akismet Anti-spam keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key. Version: 5.4 Requires at least: 5.8 Requires PHP: 7.2 Author: Automattic - Anti-spam Team Author URI: https://automattic.com/wordpress-plugins/ License: GPLv2 or later Text Domain: akismet */ /* 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Copyright 2005-2025 Automattic, Inc. */ // Make sure we don't expose any info if called directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
| Server IP : 62.109.13.187 / Your IP : 216.73.216.11 [ Web Server : Apache/2.4.6 (CentOS) mpm-itk/2.4.7-04 OpenSSL/1.0.2k-fips PHP/8.2.28 System : Linux robothost.ru 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : mosrembit ( 6064) PHP Version : 8.2.28 Disable Function : NONE Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/src/file_protector-1.1-1485/ |
Upload File : |
/**
@file
@brief Process (aka task) info storage
@details Copyright (c) 2017-2020 Acronis International GmbH
@author Ivan Matveev (ivan.matveev@acronis.com)
@since $Id: $
*/
#include "task_info_map.h"
#include "compat.h"
#include "debug.h"
#include "memory.h"
#include <linux/mm.h> // get_task_exe_file()
#include <linux/mutex.h>
// TODO: chenge lock for simultaneously reading
// for reading need lock spilock
// for writing need lock mutex, then spinlock
struct task_info_map {
spinlock_t spinlock;
struct mutex mutex;
struct rb_root root;
};
static struct task_info_map task_info_map;
const char *task_status_to_string(task_status_t status)
{
switch (status)
{
#define CASE_TS_RETURN(t) case TS_##t: return #t
CASE_TS_RETURN(UNKNOWN);
CASE_TS_RETURN(IGNORE);
CASE_TS_RETURN(WHITE);
CASE_TS_RETURN(BLACK);
CASE_TS_RETURN(GREY);
#undef CASE_TS_RETURN
default: return "?";
}
}
void task_info_map_lock(void) {
mutex_lock(&task_info_map.mutex);
}
void task_info_map_unlock(void) {
mutex_unlock(&task_info_map.mutex);
}
static task_info_t *task_info_init(task_info_t *task_info, pid_t pid)
{
DPRINTF("task_info=%p pid=%i", task_info, pid);
RB_CLEAR_NODE(&task_info->rb_node);
task_info->pid = pid;
atomic_set(&task_info->ref_cnt, 1);
spin_lock_init(&task_info->spinlock);
task_info->status = TS_UNKNOWN;
/*
struct path {
struct vfsmount *mnt;
struct dentry *dentry;
};
*/
task_info->exe_path = (struct path){};
return task_info;
}
static task_info_t *task_info_new(pid_t pid, task_status_t status, struct path exe_path)
{
task_info_t *task_info = mem_alloc0(sizeof(task_info_t));
if (task_info) {
task_info_init(task_info, pid);
task_info->status = status;
task_info->exe_path = exe_path;
path_get(&task_info->exe_path);
}
return task_info;
}
task_info_t *task_info_ref(task_info_t *task_info)
{
atomic_inc(&task_info->ref_cnt);
return task_info;
}
static void task_info_free(task_info_t *task_info)
{
DPRINTF("task_info=%p", task_info);
// Note: 'path_put(&path={})' is safe
path_put(&task_info->exe_path);
mem_free(task_info);
}
void task_info_unref(task_info_t *task_info)
{
DPRINTF("pid=%d ref_cnt=%d", task_info->pid, atomic_read(&task_info->ref_cnt));
if (atomic_dec_and_test(&task_info->ref_cnt)) {
task_info_free(task_info);
}
}
int task_info_map_init(void)
{
DPRINTF("");
task_info_map.root = RB_ROOT;
mutex_init(&task_info_map.mutex);
spin_lock_init(&task_info_map.spinlock);
return 0;
}
void task_info_map_down(void)
{
task_info_map_clear();
}
void task_info_map_clear(void)
{
struct rb_root root;
struct rb_node *node;
DPRINTF("");
mutex_lock(&task_info_map.mutex);
spin_lock(&task_info_map.spinlock);
root = task_info_map.root;
task_info_map.root = RB_ROOT;
spin_unlock(&task_info_map.spinlock);
mutex_unlock(&task_info_map.mutex);
node = rb_first_postorder(&root);
while (node) {
struct rb_node *next_node = rb_next_postorder(node);
task_info_t *task_info = rb_entry(node, task_info_t, rb_node);
rb_erase(&task_info->rb_node, &root);
task_info_unref(task_info);
node = next_node;
}
}
task_info_t *task_info_lookup(pid_t pid)
{
struct rb_node *node;
task_info_t *task_info = NULL;
DPRINTF("pid=%d", pid);
spin_lock(&task_info_map.spinlock);
node = task_info_map.root.rb_node;
while (node) {
task_info_t *node_task_info = rb_entry(node, task_info_t, rb_node);
pid_t node_pid = node_task_info->pid;
if (pid < node_pid) {
node = node->rb_left;
} else if (pid > node_pid) {
node = node->rb_right;
} else {
task_info = task_info_ref(node_task_info);
break;
}
}
spin_unlock(&task_info_map.spinlock);
return task_info;
}
// excpect task_info_map.mutex is locked
int task_info_map_add_impl(pid_t pid, task_status_t status, struct path exe_path)
{
struct rb_node **link, *parent = NULL;
task_info_t *task_info, *new;
DPRINTF("pid=%d status=%d", pid, status);
spin_lock(&task_info_map.spinlock);
link = &(task_info_map.root.rb_node);
while (*link) {
parent = *link;
task_info = rb_entry(parent, task_info_t, rb_node);
if (pid < task_info->pid) {
link = &(*link)->rb_left;
} else if (pid > task_info->pid) {
link = &(*link)->rb_right;
} else {
spin_unlock(&task_info_map.spinlock);
return -EINVAL;
}
}
spin_unlock(&task_info_map.spinlock);
new = task_info_new(pid, status, exe_path);
if (!new) {
return -ENOMEM;
}
spin_lock(&task_info_map.spinlock);
/* Put the new node there */
rb_link_node(&new->rb_node, parent, link);
rb_insert_color(&new->rb_node, &task_info_map.root);
spin_unlock(&task_info_map.spinlock);
return 0;
}
int task_info_map_add(pid_t pid, task_status_t status, struct path exe_path)
{
int ret;
mutex_lock(&task_info_map.mutex);
ret = task_info_map_add_impl(pid, status, exe_path);
mutex_unlock(&task_info_map.mutex);
return ret;
}
int task_info_map_del(pid_t pid)
{
task_info_t *task_info;
DPRINTF("pid=%d", pid);
mutex_lock(&task_info_map.mutex);
task_info = task_info_lookup(pid);
if (!task_info) {
mutex_unlock(&task_info_map.mutex);
return -EINVAL;
}
spin_lock(&task_info_map.spinlock);
rb_erase(&task_info->rb_node, &task_info_map.root);
spin_unlock(&task_info_map.spinlock);
mutex_unlock(&task_info_map.mutex);
task_info_unref(task_info);
task_info_unref(task_info);
DPRINTF("pid=%d", pid);
return 0;
}
task_status_t task_info_status_get(pid_t pid)
{
task_info_t *task_info;
task_status_t status;
task_info = task_info_lookup(pid);
if (!task_info) {
return TS_UNKNOWN;
}
spin_lock(&task_info->spinlock);
status = task_info->status;
spin_unlock(&task_info->spinlock);
task_info_unref(task_info);
return status;
}
int task_info_status_set(pid_t pid, task_status_t status)
{
task_info_t *task_info;
struct pid *struct_pid;
struct task_struct *task;
struct path exe_path;
struct file *exe_file;
int ret = 0;
mutex_lock(&task_info_map.mutex);
task_info = task_info_lookup(pid);
if (task_info) {
spin_lock(&task_info->spinlock);
task_info->status = status;
spin_unlock(&task_info->spinlock);
task_info_unref(task_info);
} else {
struct_pid = find_get_pid(pid);
task = get_pid_task(struct_pid, PIDTYPE_PID);
put_pid(struct_pid);
if (!task) {
WPRINTF("'%s(%i)' failure", "get_pid_task", pid);
ret = -ENOENT;
goto out;
}
exe_file = get_task_exe_file(task);
put_task_struct(task);
if (!exe_file) {
WPRINTF("'%s(0x%p)' failure", "get_task_exe_file", task);
ret = -ENOENT;
goto out;
}
exe_path = exe_file->f_path;
path_get(&exe_path);
ret = task_info_map_add_impl(pid, status, exe_path);
path_put(&exe_path);
if (ret) {
WPRINTF("task_info_map_add(%d) failed: %d", pid, ret);
goto out;
}
}
out:
mutex_unlock(&task_info_map.mutex);
return ret;
}