summaryrefstree
path: root/kernel/security/proca/proca_task_descr.c
blob: e9b090f35e11a3bf2c1f623efd3fda1e14747e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * PROCA task descriptor
 *
 * Copyright (C) 2018 Samsung Electronics, Inc.
 * Hryhorii Tur, <hryhorii.tur@partner.samsung.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 */

#include "proca_task_descr.h"
#include "proca_identity.h"
#include "proca_log.h"

#include <linux/slab.h>
#include <linux/string.h>

struct proca_task_descr *create_proca_task_descr(struct task_struct *task,
						 struct proca_identity *ident)
{
	struct proca_task_descr *task_descr = kzalloc(sizeof(*task_descr),
							GFP_KERNEL);
	if (unlikely(!task_descr))
		return NULL;

	task_descr->task = task;
	task_descr->proca_identity = *ident;

	PROCA_DEBUG_LOG("Task descriptor for task %d was created\n",
			task->pid);
	PROCA_DEBUG_LOG("Task %d has application name %s\n",
			task->pid, ident->parsed_cert.app_name);

	return task_descr;
}

void destroy_proca_task_descr(struct proca_task_descr *proca_task_descr)
{
	if (!proca_task_descr)
		return;

	PROCA_DEBUG_LOG("Destroying proca task descriptor for task %d\n",
			proca_task_descr->task->pid);
	deinit_proca_identity(&proca_task_descr->proca_identity);
	kfree(proca_task_descr);
}