1419b0af8Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 2419b0af8Sopenharmony_ci/* 3419b0af8Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 4419b0af8Sopenharmony_ci */ 5419b0af8Sopenharmony_ci#ifndef _EXEC_SIGNATURE_INFO_H 6419b0af8Sopenharmony_ci#define _EXEC_SIGNATURE_INFO_H 7419b0af8Sopenharmony_ci 8419b0af8Sopenharmony_ci#include <linux/types.h> 9419b0af8Sopenharmony_ci#include <linux/fs.h> 10419b0af8Sopenharmony_ci#include <linux/rbtree.h> 11419b0af8Sopenharmony_ci#include <linux/list.h> 12419b0af8Sopenharmony_ci 13419b0af8Sopenharmony_cistruct exec_segment_info { 14419b0af8Sopenharmony_ci uintptr_t file_offset; 15419b0af8Sopenharmony_ci size_t size; 16419b0af8Sopenharmony_ci}; 17419b0af8Sopenharmony_ci 18419b0af8Sopenharmony_ci#define FILE_SIGNATURE_INVALID 0 19419b0af8Sopenharmony_ci#define FILE_SIGNATURE_FS_VERITY 1 20419b0af8Sopenharmony_ci#define FILE_SIGNATURE_DM_VERITY 2 21419b0af8Sopenharmony_ci#define FILE_SIGNATURE_MASK 0x0000000F 22419b0af8Sopenharmony_ci#define FILE_SIGNATURE_DELETE 0x80000000 23419b0af8Sopenharmony_ci 24419b0af8Sopenharmony_cistruct exec_file_signature_info { 25419b0af8Sopenharmony_ci struct rb_node rb_node; 26419b0af8Sopenharmony_ci atomic_t reference; 27419b0af8Sopenharmony_ci unsigned int type; 28419b0af8Sopenharmony_ci uintptr_t inode; 29419b0af8Sopenharmony_ci unsigned int code_segment_count; 30419b0af8Sopenharmony_ci struct exec_segment_info *code_segments; 31419b0af8Sopenharmony_ci}; 32419b0af8Sopenharmony_ci 33419b0af8Sopenharmony_cistatic inline bool exec_file_signature_is_fs_verity(const struct exec_file_signature_info *signature_info) 34419b0af8Sopenharmony_ci{ 35419b0af8Sopenharmony_ci return (signature_info->type & FILE_SIGNATURE_MASK) == FILE_SIGNATURE_FS_VERITY; 36419b0af8Sopenharmony_ci} 37419b0af8Sopenharmony_ci 38419b0af8Sopenharmony_cistatic inline bool exec_file_signature_is_dm_verity(const struct exec_file_signature_info *signature_info) 39419b0af8Sopenharmony_ci{ 40419b0af8Sopenharmony_ci return (signature_info->type & FILE_SIGNATURE_MASK) == FILE_SIGNATURE_DM_VERITY; 41419b0af8Sopenharmony_ci} 42419b0af8Sopenharmony_ci 43419b0af8Sopenharmony_cistatic inline bool exec_file_signature_is_verity(const struct exec_file_signature_info *signature_info) 44419b0af8Sopenharmony_ci{ 45419b0af8Sopenharmony_ci return (signature_info->type & FILE_SIGNATURE_MASK) == FILE_SIGNATURE_DM_VERITY || 46419b0af8Sopenharmony_ci (signature_info->type & FILE_SIGNATURE_MASK) == FILE_SIGNATURE_FS_VERITY; 47419b0af8Sopenharmony_ci} 48419b0af8Sopenharmony_ci 49419b0af8Sopenharmony_cistatic inline bool exec_file_signature_is_delete(const struct exec_file_signature_info *signature_info) 50419b0af8Sopenharmony_ci{ 51419b0af8Sopenharmony_ci return !!(signature_info->type & FILE_SIGNATURE_DELETE); 52419b0af8Sopenharmony_ci} 53419b0af8Sopenharmony_ci 54419b0af8Sopenharmony_ciint parse_elf_code_segment_info(struct file *file, struct exec_file_signature_info **code_segment_info); 55419b0af8Sopenharmony_ciint get_exec_file_signature_info(struct file *file, bool is_exec, struct exec_file_signature_info **info_ptr); 56419b0af8Sopenharmony_ciint put_exec_file_signature_info(struct exec_file_signature_info *exec_info); 57419b0af8Sopenharmony_civoid delete_exec_file_signature_info(struct inode *file_node); 58419b0af8Sopenharmony_ci#endif 59