提交 e36e2d76 编写于 作者: R Roberto Sassu

Revert "convert tabs to spaces"

This reverts commit 2b716291.
上级 320cf280
2020-07-14 Roberto Sassu <roberto.sassu@huawei.com>
version 0.3.93
* Add support for PGP signatures
* Add support for user space parsers
* Bug fixes
version 0.3.93
* Add support for PGP signatures
* Add support for user space parsers
* Bug fixes
2020-07-02 Roberto Sassu <roberto.sassu@huawei.com>
version 0.3.92
* Bug fixes
* Change format of file list for compact/unknown generators
version 0.3.92
* Bug fixes
* Change format of file list for compact/unknown generators
2020-06-02 Roberto Sassu <roberto.sassu@huawei.com>
version 0.3.91
* Bug fixes
version 0.3.91
* Bug fixes
2020-04-17 Roberto Sassu <roberto.sassu@huawei.com>
version 0.3.90
* TLV compact list
* unknown generator
* digest list of metadata
version 0.3.90
* TLV compact list
* unknown generator
* digest list of metadata
2019-03-19 Roberto Sassu <roberto.sassu@huawei.com>
version 0.3
* refactored code
* tests
version 0.3
* refactored code
* tests
2018-04-05 Roberto Sassu <roberto.sassu@huawei.com>
version 0.2
* PGP signatures
* Multiple digest algorithms
* User space digest list parser
* DEB package format
version 0.2
* PGP signatures
* Multiple digest algorithms
* User space digest list parser
* DEB package format
2017-11-15 Roberto Sassu <roberto.sassu@huawei.com>
version 0.1
* first public release
version 0.1
* first public release
SUBDIRS = docs \
include \
initrd \
lib \
generators \
parsers \
scripts \
src \
systemd \
tests
include \
initrd \
lib \
generators \
parsers \
scripts \
src \
systemd \
tests
EXTRA_DIST = AUTHORS \
CHANGES
CHANGES
dist_pkgdata_DATA = README.md
......
dist_pkgdata_DATA = gen_digest_lists.txt \
setup_ima_digest_lists.txt \
setup_ima_digest_lists_demo.txt \
manage_digest_lists.txt \
upload_digest_lists.txt \
verify_digest_lists.txt \
write_rpm_pgp_sig.txt
setup_ima_digest_lists.txt \
setup_ima_digest_lists_demo.txt \
manage_digest_lists.txt \
upload_digest_lists.txt \
verify_digest_lists.txt \
write_rpm_pgp_sig.txt
man1_MANS = gen_digest_lists.1 \
setup_ima_digest_lists.1 \
setup_ima_digest_lists_demo.1 \
manage_digest_lists.1 \
upload_digest_lists.1 \
verify_digest_lists.1 \
write_rpm_pgp_sig.1
setup_ima_digest_lists.1 \
setup_ima_digest_lists_demo.1 \
manage_digest_lists.1 \
upload_digest_lists.1 \
verify_digest_lists.1 \
write_rpm_pgp_sig.1
......@@ -19,10 +19,10 @@ OPTIONS
-i <path>: path of the input file
-o <operation>: operation to do:
- add: insert a new digest list at the position specified
- append: add a new digest list after the existing ones
- remove: remove a digest list at the position specified
- sign: sign a digest list
- add: insert a new digest list at the position specified
- append: add a new digest list after the existing ones
- remove: remove a digest list at the position specified
- sign: sign a digest list
-p <position>: position of the file in the directory to add/remove
......
......@@ -19,18 +19,18 @@ OPTIONS
-o <file>: write converted digest list to a file
-p <op>: specify parser operation:
add-digest: add IMA digest to output file
add-meta-digest: add EVM digest to output file
add-ima-xattr: set IMA xattr for files in the digest lists
rm-ima-xattr: remove IMA xattr for files in the digest lists
add-evm-xattr: set EVM xattr for files in the digest lists
rm-evm-xattr: remove EVM xattr for files in the digest lists
rm-infoflow-xattr: remove Infoflow xattr for files in the digest lists
dump: display content of digest lists
gen-ima-list: generate IMA digest list with digest list measurement
check-meta: compare metadata between digest lists and filesystem
repair-meta: set metadata from the digest lists to the filesystem
repair-meta-digest-lists: set digest lists metadata
add-digest: add IMA digest to output file
add-meta-digest: add EVM digest to output file
add-ima-xattr: set IMA xattr for files in the digest lists
rm-ima-xattr: remove IMA xattr for files in the digest lists
add-evm-xattr: set EVM xattr for files in the digest lists
rm-evm-xattr: remove EVM xattr for files in the digest lists
rm-infoflow-xattr: remove Infoflow xattr for files in the digest lists
dump: display content of digest lists
gen-ima-list: generate IMA digest list with digest list measurement
check-meta: compare metadata between digest lists and filesystem
repair-meta: set metadata from the digest lists to the filesystem
repair-meta-digest-lists: set digest lists metadata
-v: verbose mode
......@@ -42,7 +42,7 @@ Convert all digest lists in /etc/ima/digest_lists to the compact format and
save the converted lists to converted_lists.
# manage_digest_lists -d /etc/ima/digest_lists -p add-digest \
-o converted_lists
-o converted_lists
AUTHOR
......
digestlistdir=$(libdir)/digestlist
digestlist_LTLIBRARIES=libgenerator-copy.la libgenerator-compact.la \
libgenerator-unknown.la
libgenerator-unknown.la
libgenerator_LDFLAGS=-no-undefined -avoid-version -L$(top_srcdir)/lib/.libs
libgenerator_LIBADD=$(top_srcdir)/lib/libdigestlist-base.la
......@@ -32,10 +32,10 @@ libgenerator_unknown_la_SOURCES=unknown.c
if CMOCKA
check_LTLIBRARIES=libgenerator-copy-test.la libgenerator-compact-test.la \
libgenerator-unknown-test.la
libgenerator-unknown-test.la
libgenerator_test_LDFLAGS=-no-undefined -avoid-version \
-L$(top_srcdir)/lib/.libs -rpath /dev/null
-L$(top_srcdir)/lib/.libs -rpath /dev/null
libgenerator_test_LIBADD=$(top_srcdir)/lib/libdigestlist-base-test.la -lcmocka
libgenerator_test_CFLAGS=-I$(top_srcdir)/include -DUNIT_TESTING
......
此差异已折叠。
......@@ -21,60 +21,61 @@
int generator(int dirfd, int pos, struct list_head *head_in,
struct list_head *head_out, enum compact_types type,
u16 modifiers, enum hash_algo algo, enum hash_algo ima_algo,
bool tlv, char *alt_root)
struct list_head *head_out, enum compact_types type,
u16 modifiers, enum hash_algo algo, enum hash_algo ima_algo,
bool tlv, char *alt_root)
{
struct path_struct *cur;
char filename[NAME_MAX + 1];
char *basename;
void *buf;
loff_t size;
int ret = 0, fd;
struct path_struct *cur;
char filename[NAME_MAX + 1];
char *basename;
void *buf;
loff_t size;
int ret = 0, fd;
if (list_empty(head_in)) {
printf("Input path not specified\n");
return -EINVAL;
}
if (list_empty(head_in)) {
printf("Input path not specified\n");
return -EINVAL;
}
list_for_each_entry(cur, head_in, list) {
basename = strrchr(cur->path, '/');
if (!basename)
basename = cur->path;
else
basename++;
list_for_each_entry(cur, head_in, list) {
basename = strrchr(cur->path, '/');
if (!basename)
basename = cur->path;
else
basename++;
snprintf(filename, sizeof(filename), "%d-%s_list-%s", pos,
compact_types_str[type], basename);
snprintf(filename, sizeof(filename), "%d-%s_list-%s", pos,
compact_types_str[type], basename);
ret = read_file_from_path(-1, cur->path, &buf, &size);
if (ret < 0)
goto out;
ret = read_file_from_path(-1, cur->path, &buf, &size);
if (ret < 0)
goto out;
fd = openat(dirfd, filename, O_WRONLY | O_CREAT, DIGEST_LIST_MODE);
if (fd < 0) {
munmap(buf, size);
ret = fd;
goto out;
}
fd = openat(dirfd, filename, O_WRONLY | O_CREAT,
DIGEST_LIST_MODE);
if (fd < 0) {
munmap(buf, size);
ret = fd;
goto out;
}
ret = write_check(fd, buf, size);
munmap(buf, size);
close(fd);
ret = write_check(fd, buf, size);
munmap(buf, size);
close(fd);
if (ret < 0)
goto out;
if (ret < 0)
goto out;
ret = add_path_struct(filename, NULL, head_out);
if (ret < 0)
goto out;
ret = add_path_struct(filename, NULL, head_out);
if (ret < 0)
goto out;
if (pos >= 0)
pos++;
}
if (pos >= 0)
pos++;
}
out:
if (ret < 0)
unlinkat(dirfd, filename, 0);
if (ret < 0)
unlinkat(dirfd, filename, 0);
return ret;
return ret;
}
此差异已折叠。
此差异已折叠。
digest_lists_includedir=$(includedir)/digestlist
digest_lists_include_HEADERS = kernel_lib.h \
list.h \
lib.h \
compact_list.h \
crypto.h \
xattr.h \
evm.h \
selinux.h \
cap.h \
ima_list.h \
parser_lib.h \
pgp.h
list.h \
lib.h \
compact_list.h \
crypto.h \
xattr.h \
evm.h \
selinux.h \
cap.h \
ima_list.h \
parser_lib.h \
pgp.h
......@@ -22,56 +22,56 @@
#define DIGEST_LIST_MODE 0644
enum parser_ops { PARSER_OP_ADD_DIGEST, PARSER_OP_ADD_DIGEST_TO_HTABLE,
PARSER_OP_ADD_META_DIGEST,
PARSER_OP_ADD_META_DIGEST_TO_HTABLE,
PARSER_OP_ADD_IMA_XATTR, PARSER_OP_REMOVE_IMA_XATTR,
PARSER_OP_ADD_EVM_XATTR, PARSER_OP_REMOVE_EVM_XATTR,
PARSER_OP_REMOVE_INFOFLOW_XATTR, PARSER_OP_VERIFY,
PARSER_OP_DUMP, PARSER_OP_GEN_IMA_LIST, PARSER_OP_CHECK_META,
PARSER_OP_REPAIR_META, PARSER_OP_REPAIR_META_DIGEST_LISTS,
PARSER_OP__LAST };
PARSER_OP_ADD_META_DIGEST,
PARSER_OP_ADD_META_DIGEST_TO_HTABLE,
PARSER_OP_ADD_IMA_XATTR, PARSER_OP_REMOVE_IMA_XATTR,
PARSER_OP_ADD_EVM_XATTR, PARSER_OP_REMOVE_EVM_XATTR,
PARSER_OP_REMOVE_INFOFLOW_XATTR, PARSER_OP_VERIFY,
PARSER_OP_DUMP, PARSER_OP_GEN_IMA_LIST, PARSER_OP_CHECK_META,
PARSER_OP_REPAIR_META, PARSER_OP_REPAIR_META_DIGEST_LISTS,
PARSER_OP__LAST };
enum tlv_ids { ID_DIGEST, ID_EVM_DIGEST, ID_PATH, ID_INODE_UID, ID_INODE_GID,
ID_INODE_MODE, ID_INODE_SIZE, ID_FSMAGIC, ID_OBJ_LABEL, ID_CAPS,
ID__LAST };
ID_INODE_MODE, ID_INODE_SIZE, ID_FSMAGIC, ID_OBJ_LABEL, ID_CAPS,
ID__LAST };
struct _tlv_item {
u8 id;
u32 len;
u8 data[];
u8 id;
u32 len;
u8 data[];
} __attribute__((packed));
struct tlv_item {
struct list_head list;
struct _tlv_item *item;
struct list_head list;
struct _tlv_item *item;
};
extern char *compact_types_str[COMPACT__LAST];
extern char *compact_modifiers_str[COMPACT_MOD__LAST];
struct list_struct {
struct list_head list;
struct compact_list_hdr *hdr;
struct list_head list;
struct compact_list_hdr *hdr;
};
struct list_struct *compact_list_init(struct list_head *head,
enum compact_types type, u16 modifiers,
enum hash_algo algo, bool tlv);
enum compact_types type, u16 modifiers,
enum hash_algo algo, bool tlv);
int compact_list_add_digest(int fd, struct list_struct *list, u8 *digest);
int compact_list_tlv_add_digest(int fd, struct list_struct *list,
struct list_head *head, u8 *digest,
enum tlv_ids id);
struct list_head *head, u8 *digest,
enum tlv_ids id);
int compact_list_tlv_add_metadata(int fd, struct list_struct *list,
struct list_head *head, char *path,
char *alt_root, struct stat *stat,
char *obj_label, int obj_label_len,
u8 *caps_bin, int caps_bin_len);
struct list_head *head, char *path,
char *alt_root, struct stat *stat,
char *obj_label, int obj_label_len,
u8 *caps_bin, int caps_bin_len);
int compact_list_tlv_add_item(int fd, struct list_struct *list,
struct list_head *head, enum tlv_ids id,
size_t len, u8 *data);
struct list_head *head, enum tlv_ids id,
size_t len, u8 *data);
int compact_list_tlv_add_items(int fd, struct list_struct *list,
struct list_head *head);
struct list_head *head);
void compact_list_tlv_dump_items(struct _tlv_item **items);
void compact_list_tlv_free_items(struct list_head *head);
......@@ -79,34 +79,34 @@ int compact_list_upload(int fd, struct list_struct *list);
int compact_list_flush_all(int fd, struct list_head *list_head);
typedef int (*generator_func)(int dirfd, int pos, struct list_head *head_in,
struct list_head *head_out,
enum compact_types type, u16 modifiers,
enum hash_algo algo, enum hash_algo ima_algo,
bool tlv, char *alt_root);
struct list_head *head_out,
enum compact_types type, u16 modifiers,
enum hash_algo algo, enum hash_algo ima_algo,
bool tlv, char *alt_root);
typedef int (*parser_func)(int imafd, struct list_head *head,
loff_t size, void *buf, enum parser_ops op);
loff_t size, void *buf, enum parser_ops op);
int gen_filename_prefix(char *filename, int filename_len, int pos,
const char *format, enum compact_types type);
const char *format, enum compact_types type);
typedef int (*filter_lists)(const struct dirent *file);
int filter_parser_list_symlink(const struct dirent *file);
extern filter_lists filter[COMPACT__LAST];
int get_digest_lists(int dirfd, enum compact_types type,
struct list_head *head);
struct list_head *head);
int compare_lists(const struct dirent **e1, const struct dirent **e2);
int digest_list_add_metadata(int dirfd, int fd, char *digest_list_filename,
char *digest_list_dir, struct list_head *head,
u8 *digest_list_buf, size_t digest_list_buf_len);
char *digest_list_dir, struct list_head *head,
u8 *digest_list_buf, size_t digest_list_buf_len);
int digest_list_upload(int dirfd, int fd, struct list_head *head,
struct list_head *parser_lib_head,
char *digest_list_filename, enum parser_ops op,
char *digest_lists_dir);
struct list_head *parser_lib_head,
char *digest_list_filename, enum parser_ops op,
char *digest_lists_dir);
int process_lists(int dirfd, int fd, int save, int verbose,
struct list_head *head, enum compact_types type,
enum parser_ops op, char *digest_lists_dir,
char *filename);
struct list_head *head, enum compact_types type,
enum parser_ops op, char *digest_lists_dir,
char *filename);
#endif /*_COMPACT_LIST_H*/
......@@ -35,19 +35,19 @@
int calc_digest(u8 *digest, void *data, u64 len, enum hash_algo algo);
int calc_file_digest(u8 *digest, int dirfd, char *path, enum hash_algo algo);
int sign_files(int dirfd, struct list_head *head, char *key_path,
char *keypass, enum hash_algo algo);
char *keypass, enum hash_algo algo);
struct key_struct {
struct list_head list;
RSA *key;
u8 keyid[4];
struct list_head list;
RSA *key;
u8 keyid[4];
};
void free_keys(struct list_head *head);
struct key_struct *new_key(struct list_head *head, int dirfd, char *key_path,
char *keypass, bool private);
char *keypass, bool private);
struct key_struct *lookup_key(struct list_head *head, int dirfd, char *key_path,
u8 *keyid);
u8 *keyid);
int verify_file(struct list_head *head, int dirfd, char *filename);
int verify_sig(struct list_head *head, int dirfd, u8 *sig, int sig_len,
u8 *digest, enum hash_algo algo);
......
......@@ -19,9 +19,9 @@
#include "compact_list.h"
int evm_calc_hmac_or_hash(enum hash_algo algo, u8 *digest,
int lsm_label_len, char *lsm_label,
int ima_digest_len, u8 *ima_digest,
int caps_bin_len, u8 *caps_bin,
uid_t uid, gid_t gid, mode_t mode);
int lsm_label_len, char *lsm_label,
int ima_digest_len, u8 *ima_digest,
int caps_bin_len, u8 *caps_bin,
uid_t uid, gid_t gid, mode_t mode);
#endif /*_EVM_H*/
......@@ -17,6 +17,6 @@
int ima_copy_boot_aggregate(int fd);
int ima_generate_entry(int dirfd, int fd, char *digest_list_dir,
char *digest_list_filename);
char *digest_list_filename);
#endif /*_IMA_LIST_H*/
......@@ -48,7 +48,7 @@ typedef unsigned long atomic_long_t;
static inline void atomic_long_inc(atomic_long_t *x)
{
(*x)++;
(*x)++;
}
#define true 1
......@@ -114,25 +114,25 @@ static inline void pr_debug(const char *__restrict __format, ...)
#define SM3256_DIGEST_SIZE 32
enum hash_algo {
HASH_ALGO_MD4,
HASH_ALGO_MD5,
HASH_ALGO_SHA1,
HASH_ALGO_RIPE_MD_160,
HASH_ALGO_SHA256,
HASH_ALGO_SHA384,
HASH_ALGO_SHA512,
HASH_ALGO_SHA224,
HASH_ALGO_RIPE_MD_128,
HASH_ALGO_RIPE_MD_256,
HASH_ALGO_RIPE_MD_320,
HASH_ALGO_WP_256,
HASH_ALGO_WP_384,
HASH_ALGO_WP_512,
HASH_ALGO_TGR_128,
HASH_ALGO_TGR_160,
HASH_ALGO_TGR_192,
HASH_ALGO_SM3_256,
HASH_ALGO__LAST
HASH_ALGO_MD4,
HASH_ALGO_MD5,
HASH_ALGO_SHA1,
HASH_ALGO_RIPE_MD_160,
HASH_ALGO_SHA256,
HASH_ALGO_SHA384,
HASH_ALGO_SHA512,
HASH_ALGO_SHA224,
HASH_ALGO_RIPE_MD_128,
HASH_ALGO_RIPE_MD_256,
HASH_ALGO_RIPE_MD_320,
HASH_ALGO_WP_256,
HASH_ALGO_WP_384,
HASH_ALGO_WP_512,
HASH_ALGO_TGR_128,
HASH_ALGO_TGR_160,
HASH_ALGO_TGR_192,
HASH_ALGO_SM3_256,
HASH_ALGO__LAST
};
/* from crypto/hash_info.c */
......@@ -158,7 +158,7 @@ extern const int hash_digest_size[HASH_ALGO__LAST];
#endif
static inline u32 __hash_32_generic(u32 val)
{
return val * GOLDEN_RATIO_32;
return val * GOLDEN_RATIO_32;
}
#ifndef HAVE_ARCH_HASH_32
......@@ -166,8 +166,8 @@ static inline u32 __hash_32_generic(u32 val)
#endif
static inline u32 hash_32_generic(u32 val, unsigned int bits)
{
/* High bits are more random, so use them. */
return __hash_32(val) >> (32 - bits);
/* High bits are more random, so use them. */
return __hash_32(val) >> (32 - bits);
}
#ifndef HAVE_ARCH_HASH_64
......@@ -176,28 +176,28 @@ static inline u32 hash_32_generic(u32 val, unsigned int bits)
static __always_inline u32 hash_64_generic(u64 val, unsigned int bits)
{
#if BITS_PER_LONG == 64
/* 64x64-bit multiply is efficient on all 64-bit processors */
return val * GOLDEN_RATIO_64 >> (64 - bits);
/* 64x64-bit multiply is efficient on all 64-bit processors */
return val * GOLDEN_RATIO_64 >> (64 - bits);
#else
/* Hash 64 bits using only 32x32-bit multiply. */
return hash_32((u32)val ^ __hash_32(val >> 32), bits);
/* Hash 64 bits using only 32x32-bit multiply. */
return hash_32((u32)val ^ __hash_32(val >> 32), bits);
#endif
}
static inline u32 hash_ptr(const void *ptr, unsigned int bits)
{
return hash_long((unsigned long)ptr, bits);
return hash_long((unsigned long)ptr, bits);
}
/* This really should be called fold32_ptr; it does no hashing to speak of. */
static inline u32 hash32_ptr(const void *ptr)
{
unsigned long val = (unsigned long)ptr;
unsigned long val = (unsigned long)ptr;
#if __BITS_PER_LONG == 64
val ^= (val >> 32);
val ^= (val >> 32);
#endif
return (u32)val;
return (u32)val;
}
/* from kernel.h */
......@@ -215,83 +215,83 @@ extern bool ima_canonical_fmt;
static inline unsigned long ima_hash_key(u8 *digest)
{
return hash_long(*digest, IMA_HASH_BITS);
return hash_long(*digest, IMA_HASH_BITS);
}
struct ima_h_table {
atomic_long_t len; /* number of stored measurements in the list */
atomic_long_t violations;
struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
atomic_long_t len; /* number of stored measurements in the list */
atomic_long_t violations;
struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
};
/* from integrity.h */
enum evm_ima_xattr_type {
IMA_XATTR_DIGEST = 0x01,
EVM_XATTR_HMAC,
EVM_IMA_XATTR_DIGSIG,
IMA_XATTR_DIGEST_NG,
EVM_XATTR_PORTABLE_DIGSIG,
EVM_IMA_XATTR_DIGEST_LIST,
IMA_XATTR_LAST
IMA_XATTR_DIGEST = 0x01,
EVM_XATTR_HMAC,
EVM_IMA_XATTR_DIGSIG,
IMA_XATTR_DIGEST_NG,
EVM_XATTR_PORTABLE_DIGSIG,
EVM_IMA_XATTR_DIGEST_LIST,
IMA_XATTR_LAST
};
enum evm_ima_sig_fmt {
SIG_FMT_IMA,
SIG_FMT_PGP,
SIG_FMT__LAST,
SIG_FMT_IMA,
SIG_FMT_PGP,
SIG_FMT__LAST,
};
struct signature_v2_hdr {
uint8_t type; /* xattr type */
uint8_t version; /* signature format version */
uint8_t hash_algo; /* Digest algorithm [enum hash_algo] */
__be32 keyid; /* IMA key identifier - not X509/PGP specific */
__be16 sig_size; /* signature size */
uint8_t sig[0]; /* signature payload */
uint8_t type; /* xattr type */
uint8_t version; /* signature format version */
uint8_t hash_algo; /* Digest algorithm [enum hash_algo] */
__be32 keyid; /* IMA key identifier - not X509/PGP specific */
__be16 sig_size; /* signature size */
uint8_t sig[0]; /* signature payload */
} __attribute__((packed));
struct evm_ima_xattr_data {
uint8_t type;
uint8_t digest[SHA512_DIGEST_SIZE + 1];
uint8_t type;
uint8_t digest[SHA512_DIGEST_SIZE + 1];
} __attribute__((packed));
/* from integrity.h */
enum compact_types { COMPACT_KEY, COMPACT_PARSER, COMPACT_FILE,
COMPACT_METADATA, COMPACT__LAST };
COMPACT_METADATA, COMPACT__LAST };
enum compact_modifiers { COMPACT_MOD_IMMUTABLE, COMPACT_MOD__LAST };
struct ima_digest {
struct hlist_node hnext;
struct list_head list;
enum hash_algo algo;
enum compact_types type;
u16 modifiers;
u8 digest[0];
struct hlist_node hnext;
struct list_head list;
enum hash_algo algo;
enum compact_types type;
u16 modifiers;
u8 digest[0];
};
/* from ima_digest_list.c */
struct compact_list_hdr {
u8 version;
u8 _reserved;
u16 type;
u16 modifiers;
u16 algo;
u32 count;
u32 datalen;
u8 version;
u8 _reserved;
u16 type;
u16 modifiers;
u16 algo;
u32 count;
u32 datalen;
} __attribute__((packed));
typedef int (*add_digest_func)(u8 *digest, enum hash_algo algo,
enum compact_types type, u16 modifiers);
enum compact_types type, u16 modifiers);
int default_func(u8 *digest, enum hash_algo algo, enum compact_types type,
u16 modifiers);
int ima_parse_compact_list(loff_t size, void *buf,
add_digest_func ima_add_digest_data_entry,
enum hash_algo *algo);
add_digest_func ima_add_digest_data_entry,
enum hash_algo *algo);
struct ima_digest *ima_lookup_digest(u8 *digest, enum hash_algo algo);
int ima_add_digest_data_entry_kernel(u8 *digest, enum hash_algo algo,
enum compact_types type, u16 modifiers);
enum compact_types type, u16 modifiers);
#endif /* _KERNEL_LIB_H */
......@@ -34,42 +34,42 @@
#define IMA_SECURITYFS_PATH SECURITYFS_PATH "/ima"
enum pgp_hash_algo {
PGP_HASH_MD5 = 1,
PGP_HASH_SHA1 = 2,
PGP_HASH_RIPE_MD_160 = 3,
PGP_HASH_SHA256 = 8,
PGP_HASH_SHA384 = 9,
PGP_HASH_SHA512 = 10,
PGP_HASH_SHA224 = 11,
PGP_HASH__LAST
PGP_HASH_MD5 = 1,
PGP_HASH_SHA1 = 2,
PGP_HASH_RIPE_MD_160 = 3,
PGP_HASH_SHA256 = 8,
PGP_HASH_SHA384 = 9,
PGP_HASH_SHA512 = 10,
PGP_HASH_SHA224 = 11,
PGP_HASH__LAST
};
enum hash_algo pgp_algo_mapping[PGP_HASH__LAST];
int read_file_from_path(int dirfd, const char *path, void **buf, loff_t *size);
int read_write_file_from_path(int dirfd, const char *path, void **buf,
loff_t *size);
loff_t *size);
ssize_t write_check(int fd, const void *buf, size_t count);
int copy_file(char *src, char *dest);
struct lib {
struct list_head list;
char *format;
void *handle;
void *func;
struct list_head list;
char *format;
void *handle;
void *func;
};
struct lib *lookup_lib(struct list_head *head, const char *lib_type,
const char *format, int format_len);
const char *format, int format_len);
void free_libs(struct list_head *head);
enum file_attrs { ATTR_PATH, ATTR_DIGESTALGO, ATTR_DIGESTALGOPGP, ATTR_DIGEST,
ATTR_MODE, ATTR_UNAME, ATTR_GNAME, ATTR_CAPS, ATTR__LAST };
ATTR_MODE, ATTR_UNAME, ATTR_GNAME, ATTR_CAPS, ATTR__LAST };
struct path_struct {
struct list_head list;
char *attrs[ATTR__LAST];
char *path;
struct list_head list;
char *attrs[ATTR__LAST];
char *path;
};
int add_path_struct(char *path, char **attrs, struct list_head *head);
......
......@@ -27,34 +27,34 @@
*
*/
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
struct list_head name = LIST_HEAD_INIT(name)
#define HLIST_HEAD_INIT { .first = NULL }
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
struct list_head {
struct list_head *next, *prev;
struct list_head *next, *prev;
};
struct hlist_head {
struct hlist_node *first;
struct hlist_node *first;
};
struct hlist_node {
struct hlist_node *next, **pprev;
struct hlist_node *next, **pprev;
};
static inline void INIT_LIST_HEAD(struct list_head *list)
{
list->next = list;
list->prev = list;
list->next = list;
list->prev = list;
}
/*
......@@ -64,13 +64,13 @@ static inline void INIT_LIST_HEAD(struct list_head *list)
* the prev/next entries already!
*/
static inline void __list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next)
struct list_head *prev,
struct list_head *next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
/**
......@@ -83,7 +83,7 @@ static inline void __list_add(struct list_head *new,
*/
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
__list_add(new, head, head->next);
}
/**
......@@ -96,7 +96,7 @@ static inline void list_add(struct list_head *new, struct list_head *head)
*/
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
__list_add(new, head->prev, head);
}
/*
......@@ -108,8 +108,8 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head)
*/
static inline void __list_del(struct list_head * prev, struct list_head * next)
{
next->prev = prev;
prev->next = next;
next->prev = prev;
prev->next = next;
}
/**
......@@ -120,14 +120,14 @@ static inline void __list_del(struct list_head * prev, struct list_head * next)
*/
static inline void __list_del_entry(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
__list_del(entry->prev, entry->next);
}
static inline void list_del(struct list_head *entry)
{
__list_del_entry(entry);
entry->next = LIST_POISON1;
entry->prev = LIST_POISON2;
__list_del_entry(entry);
entry->next = LIST_POISON1;
entry->prev = LIST_POISON2;
}
/**
......@@ -136,7 +136,7 @@ static inline void list_del(struct list_head *entry)
*/
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
return head->next == head;
}
/**
......@@ -146,7 +146,7 @@ static inline int list_empty(const struct list_head *head)
* @member: the name of the list_head within the struct.
*/
#define list_entry(ptr, type, member) \
container_of(ptr, type, member)
container_of(ptr, type, member)
/**
* list_first_entry - get the first element from a list
......@@ -157,7 +157,7 @@ static inline int list_empty(const struct list_head *head)
* Note, that list is expected to be not empty.
*/
#define list_first_entry(ptr, type, member) \
list_entry((ptr)->next, type, member)
list_entry((ptr)->next, type, member)
/**
* list_last_entry - get the last element from a list
......@@ -168,7 +168,7 @@ static inline int list_empty(const struct list_head *head)
* Note, that list is expected to be not empty.
*/
#define list_last_entry(ptr, type, member) \
list_entry((ptr)->prev, type, member)
list_entry((ptr)->prev, type, member)
/**
* list_first_entry_or_null - get the first element from a list
......@@ -179,9 +179,9 @@ static inline int list_empty(const struct list_head *head)
* Note that if the list is empty, it returns NULL.
*/
#define list_first_entry_or_null(ptr, type, member) ({ \
struct list_head *head__ = (ptr); \
struct list_head *pos__ = READ_ONCE(head__->next); \
pos__ != head__ ? list_entry(pos__, type, member) : NULL; \
struct list_head *head__ = (ptr); \
struct list_head *pos__ = READ_ONCE(head__->next); \
pos__ != head__ ? list_entry(pos__, type, member) : NULL; \
})
/**
......@@ -190,7 +190,7 @@ static inline int list_empty(const struct list_head *head)
* @member: the name of the list_head within the struct.
*/
#define list_next_entry(pos, member) \
list_entry((pos)->member.next, typeof(*(pos)), member)
list_entry((pos)->member.next, typeof(*(pos)), member)
/**
* list_prev_entry - get the prev element in list
......@@ -198,7 +198,7 @@ static inline int list_empty(const struct list_head *head)
* @member: the name of the list_head within the struct.
*/
#define list_prev_entry(pos, member) \
list_entry((pos)->member.prev, typeof(*(pos)), member)
list_entry((pos)->member.prev, typeof(*(pos)), member)
/**
* list_for_each_entry - iterate over list of given type
......@@ -207,9 +207,9 @@ static inline int list_empty(const struct list_head *head)
* @member: the name of the list_head within the struct.
*/
#define list_for_each_entry(pos, head, member) \
for (pos = list_first_entry(head, typeof(*pos), member); \
&pos->member != (head); \
pos = list_next_entry(pos, member))
for (pos = list_first_entry(head, typeof(*pos), member); \
&pos->member != (head); \
pos = list_next_entry(pos, member))
/**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
......@@ -219,34 +219,34 @@ static inline int list_empty(const struct list_head *head)
* @member: the name of the list_head within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_first_entry(head, typeof(*pos), member), \
n = list_next_entry(pos, member); \
&pos->member != (head); \
pos = n, n = list_next_entry(n, member))
for (pos = list_first_entry(head, typeof(*pos), member), \
n = list_next_entry(pos, member); \
&pos->member != (head); \
pos = n, n = list_next_entry(n, member))
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{
struct hlist_node *first = h->first;
n->next = first;
if (first)
first->pprev = &n->next;
h->first = n;
n->pprev = &h->first;
struct hlist_node *first = h->first;
n->next = first;
if (first)
first->pprev = &n->next;
h->first = n;
n->pprev = &h->first;
}
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
#define hlist_for_each(pos, head) \
for (pos = (head)->first; pos ; pos = pos->next)
for (pos = (head)->first; pos ; pos = pos->next)
#define hlist_for_each_safe(pos, n, head) \
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
pos = n)
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
pos = n)
#define hlist_entry_safe(ptr, type, member) \
({ typeof(ptr) ____ptr = (ptr); \
____ptr ? hlist_entry(____ptr, type, member) : NULL; \
})
({ typeof(ptr) ____ptr = (ptr); \
____ptr ? hlist_entry(____ptr, type, member) : NULL; \
})
/**
* hlist_for_each_entry - iterate over list of given type
......@@ -255,9 +255,9 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry(pos, head, member) \
for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
pos; \
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
pos; \
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
#define hlist_for_each_entry_rcu hlist_for_each_entry
#define hlist_add_head_rcu hlist_add_head
......
......@@ -18,19 +18,19 @@
#include "compact_list.h"
int add_digest(int fd, struct list_head *head, u16 type, u16 modifiers,
u16 algo, u8 *digest);
u16 algo, u8 *digest);
int calc_metadata_digest(int fd, struct list_head *head, u16 type,
u16 modifiers, u16 algo, u8 *digest, u8 *evm_digest,
char *path, uid_t uid, gid_t gid, mode_t mode,
char *obj_label, char *caps);
u16 modifiers, u16 algo, u8 *digest, u8 *evm_digest,
char *path, uid_t uid, gid_t gid, mode_t mode,
char *obj_label, char *caps);
int add_metadata_digest(int fd, struct list_head *head, u16 modifiers,
u8 *evm_digest);
u8 *evm_digest);
int add_ima_xattr(int fd, struct list_head *head, u16 type, u16 modifiers,
u16 algo, u8 *digest, char *path);
u16 algo, u8 *digest, char *path);
int check_repair_xattr(char *path, char *xattr_name, void *xattr_value,
int xattr_value_len, int ima_algo, int modifiers,
int repair);
int xattr_value_len, int ima_algo, int modifiers,
int repair);
int check_repair_attr(char *path, uid_t uid, gid_t gid, mode_t mode,
int repair);
int repair);
#endif /*_PARSER_LIB_H*/
......@@ -24,101 +24,101 @@
#include "lib.h"
struct pgp_key_ID {
u8 id[8];
u8 id[8];
} __attribute__((packed));
struct pgp_time {
u8 time[4];
u8 time[4];
} __attribute__((packed));
/*
* PGP public-key algorithm identifiers [RFC4880: 9.1]
*/
enum pgp_pubkey_algo {
PGP_PUBKEY_RSA_ENC_OR_SIG = 1,
PGP_PUBKEY_RSA_ENC_ONLY = 2,
PGP_PUBKEY_RSA_SIG_ONLY = 3,
PGP_PUBKEY_ELGAMAL = 16,
PGP_PUBKEY_DSA = 17,
PGP_PUBKEY__LAST
PGP_PUBKEY_RSA_ENC_OR_SIG = 1,
PGP_PUBKEY_RSA_ENC_ONLY = 2,
PGP_PUBKEY_RSA_SIG_ONLY = 3,
PGP_PUBKEY_ELGAMAL = 16,
PGP_PUBKEY_DSA = 17,
PGP_PUBKEY__LAST
};
/*
* PGP symmetric-key algorithm identifiers [RFC4880: 9.2]
*/
enum pgp_symkey_algo {
PGP_SYMKEY_PLAINTEXT = 0,
PGP_SYMKEY_IDEA = 1,
PGP_SYMKEY_3DES = 2,
PGP_SYMKEY_CAST5 = 3,
PGP_SYMKEY_BLOWFISH = 4,
PGP_SYMKEY_AES_128KEY = 7,
PGP_SYMKEY_AES_192KEY = 8,
PGP_SYMKEY_AES_256KEY = 9,
PGP_SYMKEY_TWOFISH_256KEY = 10,
PGP_SYMKEY_PLAINTEXT = 0,
PGP_SYMKEY_IDEA = 1,
PGP_SYMKEY_3DES = 2,
PGP_SYMKEY_CAST5 = 3,
PGP_SYMKEY_BLOWFISH = 4,
PGP_SYMKEY_AES_128KEY = 7,
PGP_SYMKEY_AES_192KEY = 8,
PGP_SYMKEY_AES_256KEY = 9,
PGP_SYMKEY_TWOFISH_256KEY = 10,
};
/*
* PGP compression algorithm identifiers [RFC4880: 9.3]
*/
enum pgp_compr_algo {
PGP_COMPR_UNCOMPRESSED = 0,
PGP_COMPR_ZIP = 1,
PGP_COMPR_ZLIB = 2,
PGP_COMPR_BZIP2 = 3,
PGP_COMPR_UNCOMPRESSED = 0,
PGP_COMPR_ZIP = 1,
PGP_COMPR_ZLIB = 2,
PGP_COMPR_BZIP2 = 3,
};
/*
* PGP packet type tags [RFC4880: 4.3].
*/
enum pgp_packet_tag {
PGP_PKT_RESERVED = 0,
PGP_PKT_PUBKEY_ENC_SESSION_KEY = 1,
PGP_PKT_SIGNATURE = 2,
PGP_PKT_SYMKEY_ENC_SESSION_KEY = 3,
PGP_PKT_ONEPASS_SIGNATURE = 4,
PGP_PKT_SECRET_KEY = 5,
PGP_PKT_PUBLIC_KEY = 6,
PGP_PKT_SECRET_SUBKEY = 7,
PGP_PKT_COMPRESSED_DATA = 8,
PGP_PKT_SYM_ENC_DATA = 9,
PGP_PKT_MARKER = 10,
PGP_PKT_LITERAL_DATA = 11,
PGP_PKT_TRUST = 12,
PGP_PKT_USER_ID = 13,
PGP_PKT_PUBLIC_SUBKEY = 14,
PGP_PKT_USER_ATTRIBUTE = 17,
PGP_PKT_SYM_ENC_AND_INTEG_DATA = 18,
PGP_PKT_MODIFY_DETECT_CODE = 19,
PGP_PKT_PRIVATE_0 = 60,
PGP_PKT_PRIVATE_3 = 63,
PGP_PKT__HIGHEST = 63
PGP_PKT_RESERVED = 0,
PGP_PKT_PUBKEY_ENC_SESSION_KEY = 1,
PGP_PKT_SIGNATURE = 2,
PGP_PKT_SYMKEY_ENC_SESSION_KEY = 3,
PGP_PKT_ONEPASS_SIGNATURE = 4,
PGP_PKT_SECRET_KEY = 5,
PGP_PKT_PUBLIC_KEY = 6,
PGP_PKT_SECRET_SUBKEY = 7,
PGP_PKT_COMPRESSED_DATA = 8,
PGP_PKT_SYM_ENC_DATA = 9,
PGP_PKT_MARKER = 10,
PGP_PKT_LITERAL_DATA = 11,
PGP_PKT_TRUST = 12,
PGP_PKT_USER_ID = 13,
PGP_PKT_PUBLIC_SUBKEY = 14,
PGP_PKT_USER_ATTRIBUTE = 17,
PGP_PKT_SYM_ENC_AND_INTEG_DATA = 18,
PGP_PKT_MODIFY_DETECT_CODE = 19,
PGP_PKT_PRIVATE_0 = 60,
PGP_PKT_PRIVATE_3 = 63,
PGP_PKT__HIGHEST = 63
};
/*
* Signature (tag 2) packet [RFC4880: 5.2].
*/
enum pgp_signature_version {
PGP_SIG_VERSION_3 = 3,
PGP_SIG_VERSION_4 = 4,
PGP_SIG_VERSION_3 = 3,
PGP_SIG_VERSION_4 = 4,
};
enum pgp_signature_type {
PGP_SIG_BINARY_DOCUMENT_SIG = 0x00,
PGP_SIG_CANONICAL_TEXT_DOCUMENT_SIG = 0x01,
PGP_SIG_STANDALONE_SIG = 0x02,
PGP_SIG_GENERAL_CERT_OF_UID_PUBKEY = 0x10,
PGP_SIG_PERSONAL_CERT_OF_UID_PUBKEY = 0x11,
PGP_SIG_CASUAL_CERT_OF_UID_PUBKEY = 0x12,
PGP_SIG_POSTITIVE_CERT_OF_UID_PUBKEY = 0x13,
PGP_SIG_SUBKEY_BINDING_SIG = 0x18,
PGP_SIG_PRIMARY_KEY_BINDING_SIG = 0x19,
PGP_SIG_DIRECTLY_ON_KEY = 0x1F,
PGP_SIG_KEY_REVOCATION_SIG = 0x20,
PGP_SIG_SUBKEY_REVOCATION_SIG = 0x28,
PGP_SIG_CERT_REVOCATION_SIG = 0x30,
PGP_SIG_TIMESTAMP_SIG = 0x40,
PGP_SIG_THIRD_PARTY_CONFIRM_SIG = 0x50,
PGP_SIG_BINARY_DOCUMENT_SIG = 0x00,
PGP_SIG_CANONICAL_TEXT_DOCUMENT_SIG = 0x01,
PGP_SIG_STANDALONE_SIG = 0x02,
PGP_SIG_GENERAL_CERT_OF_UID_PUBKEY = 0x10,
PGP_SIG_PERSONAL_CERT_OF_UID_PUBKEY = 0x11,
PGP_SIG_CASUAL_CERT_OF_UID_PUBKEY = 0x12,
PGP_SIG_POSTITIVE_CERT_OF_UID_PUBKEY = 0x13,
PGP_SIG_SUBKEY_BINDING_SIG = 0x18,
PGP_SIG_PRIMARY_KEY_BINDING_SIG = 0x19,
PGP_SIG_DIRECTLY_ON_KEY = 0x1F,
PGP_SIG_KEY_REVOCATION_SIG = 0x20,
PGP_SIG_SUBKEY_REVOCATION_SIG = 0x28,
PGP_SIG_CERT_REVOCATION_SIG = 0x30,
PGP_SIG_TIMESTAMP_SIG = 0x40,
PGP_SIG_THIRD_PARTY_CONFIRM_SIG = 0x50,
};
#define PGP_SIG_SUBPKT_TYPE_CRITICAL_MASK 0x80
......@@ -127,72 +127,72 @@ enum pgp_signature_type {
* V4 signature subpacket types [RFC4880: 5.2.3.1].
*/
enum pgp_sig_subpkt_type {
PGP_SIG_CREATION_TIME = 2,
PGP_SIG_EXPIRATION_TIME = 3,
PGP_SIG_EXPORTABLE_CERT = 4,
PGP_SIG_TRUST_SIG = 5,
PGP_SIG_REGEXP = 6,
PGP_SIG_REVOCABLE = 7,
PGP_SIG_KEY_EXPIRATION_TIME = 9,
PGP_SIG_PREF_SYM_ALGO = 11,
PGP_SIG_REVOCATION_KEY = 12,
PGP_SIG_ISSUER = 16,
PGP_SIG_NOTATION_DATA = 20,
PGP_SIG_PREF_HASH_ALGO = 21,
PGP_SIG_PREF_COMPR_ALGO = 22,
PGP_SIG_KEY_SERVER_PREFS = 23,
PGP_SIG_PREF_KEY_SERVER = 24,
PGP_SIG_PRIMARY_USER_ID = 25,
PGP_SIG_POLICY_URI = 26,
PGP_SIG_KEY_FLAGS = 27,
PGP_SIG_SIGNERS_USER_ID = 28,
PGP_SIG_REASON_FOR_REVOCATION = 29,
PGP_SIG_FEATURES = 30,
PGP_SIG_TARGET = 31,
PGP_SIG_EMBEDDED_SIG = 32,
PGP_SIG__LAST
PGP_SIG_CREATION_TIME = 2,
PGP_SIG_EXPIRATION_TIME = 3,
PGP_SIG_EXPORTABLE_CERT = 4,
PGP_SIG_TRUST_SIG = 5,
PGP_SIG_REGEXP = 6,
PGP_SIG_REVOCABLE = 7,
PGP_SIG_KEY_EXPIRATION_TIME = 9,
PGP_SIG_PREF_SYM_ALGO = 11,
PGP_SIG_REVOCATION_KEY = 12,
PGP_SIG_ISSUER = 16,
PGP_SIG_NOTATION_DATA = 20,
PGP_SIG_PREF_HASH_ALGO = 21,
PGP_SIG_PREF_COMPR_ALGO = 22,
PGP_SIG_KEY_SERVER_PREFS = 23,
PGP_SIG_PREF_KEY_SERVER = 24,
PGP_SIG_PRIMARY_USER_ID = 25,
PGP_SIG_POLICY_URI = 26,
PGP_SIG_KEY_FLAGS = 27,
PGP_SIG_SIGNERS_USER_ID = 28,
PGP_SIG_REASON_FOR_REVOCATION = 29,
PGP_SIG_FEATURES = 30,
PGP_SIG_TARGET = 31,
PGP_SIG_EMBEDDED_SIG = 32,
PGP_SIG__LAST
};
struct pgp_parse_sig_context {
unsigned long types_of_interest[128 / __BITS_PER_LONG];
int (*process_packet)(struct pgp_parse_sig_context *context,
enum pgp_sig_subpkt_type type,
const u8 *data,
size_t datalen);
unsigned long types_of_interest[128 / __BITS_PER_LONG];
int (*process_packet)(struct pgp_parse_sig_context *context,
enum pgp_sig_subpkt_type type,
const u8 *data,
size_t datalen);
};
struct pgp_sig_parameters {
enum pgp_signature_version version : 8;
enum pgp_signature_type signature_type : 8;
enum pgp_pubkey_algo pubkey_algo : 8;
enum pgp_hash_algo hash_algo : 8;
union {
struct pgp_key_ID issuer;
__be32 issuer32[2];
};
enum pgp_signature_version version : 8;
enum pgp_signature_type signature_type : 8;
enum pgp_pubkey_algo pubkey_algo : 8;
enum pgp_hash_algo hash_algo : 8;
union {
struct pgp_key_ID issuer;
__be32 issuer32[2];
};
};
struct pgp_signature_v3_packet {
enum pgp_signature_version version : 8; /* == PGP_SIG_VERSION_3 */
u8 length_of_hashed; /* == 5 */
struct {
enum pgp_signature_type signature_type : 8;
struct pgp_time creation_time;
} __attribute__((packed)) hashed;
struct pgp_key_ID issuer;
enum pgp_pubkey_algo pubkey_algo : 8;
enum pgp_hash_algo hash_algo : 8;
enum pgp_signature_version version : 8; /* == PGP_SIG_VERSION_3 */
u8 length_of_hashed; /* == 5 */
struct {
enum pgp_signature_type signature_type : 8;
struct pgp_time creation_time;
} __attribute__((packed)) hashed;
struct pgp_key_ID issuer;
enum pgp_pubkey_algo pubkey_algo : 8;
enum pgp_hash_algo hash_algo : 8;
} __attribute__((packed));
struct pgp_signature_v4_packet {
enum pgp_signature_version version : 8; /* == PGP_SIG_VERSION_4 */
enum pgp_signature_type signature_type : 8;
enum pgp_pubkey_algo pubkey_algo : 8;
enum pgp_hash_algo hash_algo : 8;
enum pgp_signature_version version : 8; /* == PGP_SIG_VERSION_4 */
enum pgp_signature_type signature_type : 8;
enum pgp_pubkey_algo pubkey_algo : 8;
enum pgp_hash_algo hash_algo : 8;
} __attribute__((packed));
int pgp_get_signature_data(const u8 *signature, size_t signature_len,
u8 **data, size_t *data_len, u8 **sig,
size_t *sig_len, u8 **issuer, u16 *algo);
u8 **data, size_t *data_len, u8 **sig,
size_t *sig_len, u8 **issuer, u16 *algo);
#endif /* _PGP_H */
......@@ -18,14 +18,14 @@
#include "lib.h"
int write_ima_xattr(int dirfd, char *path, u8 *keyid, size_t keyid_len,
u8 *sig, size_t sig_len, enum hash_algo algo);
u8 *sig, size_t sig_len, enum hash_algo algo);
int write_evm_xattr(char *path, enum hash_algo algo);
int parse_ima_xattr(u8 *buf, size_t buf_len, u8 **keyid, size_t *keyid_len,
u8 **sig, size_t *sig_len, enum hash_algo *algo);
u8 **sig, size_t *sig_len, enum hash_algo *algo);
int read_ima_xattr(int dirfd, char *path, u8 **buf, size_t *buf_len,
u8 **keyid, size_t *keyid_len, u8 **sig, size_t *sig_len,
enum hash_algo *algo);
u8 **keyid, size_t *keyid_len, u8 **sig, size_t *sig_len,
enum hash_algo *algo);
int gen_write_ima_xattr(u8 *buf, int *buf_len, char *path, u8 algo, u8 *digest,
bool immutable, bool write);
bool immutable, bool write);
#endif /*_XATTR_H*/
#! /bin/bash
if [ ! -f /sys/kernel/security/ima/digest_list_data ]; then
exit 0
exit 0
fi
digests_count=$(cat /sys/kernel/security/ima/digests_count)
if [ "$digests_count" = "0" ]; then
exit 0
exit 0
fi
for f in $(find $NEWROOT/etc/ima/digest_lists -type f); do
if [ ! -f /etc/ima/digest_lists/$(basename $f) ]; then
process_digest_list=$(getfattr -m - -e hex -d $f \
2> /dev/null | awk '{ if ($1 ~ /security.evm/) evm=1;
if ($1 ~ /security.ima=0x03/) ima=1; }
END{ if (evm || ima) print "1" }')
if [ -z "$process_digest_list" ]; then
continue
fi
if [ ! -f /etc/ima/digest_lists/$(basename $f) ]; then
process_digest_list=$(getfattr -m - -e hex -d $f \
2> /dev/null | awk '{ if ($1 ~ /security.evm/) evm=1;
if ($1 ~ /security.ima=0x03/) ima=1; }
END{ if (evm || ima) print "1" }')
if [ -z "$process_digest_list" ]; then
continue
fi
format=$(echo $f | cut -d - -f 3)
if [ "$format" = "compact" ]; then
echo $f > /sys/kernel/security/ima/digest_list_data
else
upload_digest_lists add $f
fi
fi
format=$(echo $f | cut -d - -f 3)
if [ "$format" = "compact" ]; then
echo $f > /sys/kernel/security/ima/digest_list_data
else
upload_digest_lists add $f
fi
fi
done
......@@ -3,7 +3,7 @@
attr -S -g evm /sysroot/bin/cat &> /dev/null
if [ $? -eq 0 ]; then
exit 0
exit 0
fi
manage_digest_lists -p add-meta-digest
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -31,30 +31,30 @@
* protection.)
*/
static int hmac_add_misc(EVP_MD_CTX *mdctx, uid_t uid, gid_t gid, mode_t mode,
u8 *digest)
u8 *digest)
{
struct h_misc {
unsigned long ino;
u32 generation;
uid_t uid;
gid_t gid;
mode_t mode;
} hmac_misc;
struct h_misc {
unsigned long ino;
u32 generation;
uid_t uid;
gid_t gid;
mode_t mode;
} hmac_misc;
memset(&hmac_misc, 0, sizeof(hmac_misc));
memset(&hmac_misc, 0, sizeof(hmac_misc));
hmac_misc.uid = uid;
hmac_misc.gid = gid;
hmac_misc.mode = mode;
hmac_misc.uid = uid;
hmac_misc.gid = gid;
hmac_misc.mode = mode;
if (EVP_DigestUpdate(mdctx, (const u8 *)&hmac_misc,
sizeof(hmac_misc)) != 1)
return -EINVAL;
if (EVP_DigestUpdate(mdctx, (const u8 *)&hmac_misc,
sizeof(hmac_misc)) != 1)
return -EINVAL;
if (EVP_DigestFinal_ex(mdctx, digest, NULL) != 1)
return -EINVAL;
if (EVP_DigestFinal_ex(mdctx, digest, NULL) != 1)
return -EINVAL;
return 0;
return 0;
}
/*
......@@ -65,46 +65,46 @@ static int hmac_add_misc(EVP_MD_CTX *mdctx, uid_t uid, gid_t gid, mode_t mode,
* each xattr, but attempt to re-use the previously allocated memory.
*/
int evm_calc_hmac_or_hash(enum hash_algo algo, u8 *digest,
int lsm_label_len, char *lsm_label,
int ima_digest_len, u8 *ima_digest,
int caps_bin_len, u8 *caps_bin,
uid_t uid, gid_t gid, mode_t mode)
int lsm_label_len, char *lsm_label,
int ima_digest_len, u8 *ima_digest,
int caps_bin_len, u8 *caps_bin,
uid_t uid, gid_t gid, mode_t mode)
{
EVP_MD_CTX *mdctx;
const EVP_MD *md;
int ret = -EINVAL;
EVP_MD_CTX *mdctx;
const EVP_MD *md;
int ret = -EINVAL;
OpenSSL_add_all_algorithms();
OpenSSL_add_all_algorithms();
md = EVP_get_digestbyname(hash_algo_name[algo]);
if (!md)
goto out;
md = EVP_get_digestbyname(hash_algo_name[algo]);
if (!md)
goto out;
mdctx = EVP_MD_CTX_create();
if (!mdctx)
goto out;
mdctx = EVP_MD_CTX_create();
if (!mdctx)
goto out;
if (EVP_DigestInit_ex(mdctx, md, NULL) != 1)
goto out_mdctx;
if (EVP_DigestInit_ex(mdctx, md, NULL) != 1)
goto out_mdctx;
if (lsm_label &&
EVP_DigestUpdate(mdctx, (const u8 *)lsm_label, lsm_label_len) != 1)
goto out_mdctx;
if (lsm_label &&
EVP_DigestUpdate(mdctx, (const u8 *)lsm_label, lsm_label_len) != 1)
goto out_mdctx;
if (EVP_DigestUpdate(mdctx, (const u8 *)ima_digest,
ima_digest_len) != 1)
goto out_mdctx;
if (EVP_DigestUpdate(mdctx, (const u8 *)ima_digest,
ima_digest_len) != 1)
goto out_mdctx;
if (EVP_DigestUpdate(mdctx, caps_bin, caps_bin_len) != 1)
goto out_mdctx;
if (EVP_DigestUpdate(mdctx, caps_bin, caps_bin_len) != 1)
goto out_mdctx;
if (hmac_add_misc(mdctx, uid, gid, mode, digest) < 0)
goto out_mdctx;
if (hmac_add_misc(mdctx, uid, gid, mode, digest) < 0)
goto out_mdctx;
ret = 0;
ret = 0;
out_mdctx:
EVP_MD_CTX_destroy(mdctx);
EVP_MD_CTX_destroy(mdctx);
out:
EVP_cleanup();
return ret;
EVP_cleanup();
return ret;
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -23,39 +23,39 @@ static struct selabel_handle *h;
int selinux_init_setup(void)
{
int rc = 0;
int rc = 0;
h = selabel_open(SELABEL_CTX_FILE, NULL, 0);
if (!h) {
pr_err("Cannot initialize libselinux\n");
return -EPERM;
}
h = selabel_open(SELABEL_CTX_FILE, NULL, 0);
if (!h) {
pr_err("Cannot initialize libselinux\n");
return -EPERM;
}
selinux_restorecon_set_sehandle(h);
selinux_restorecon_set_sehandle(h);
return rc;
return rc;
}
void selinux_end_setup(void)
{
if (h) {
selabel_close(h);
h = NULL;
}
if (h) {
selabel_close(h);
h = NULL;
}
}
int get_selinux_label(char *path, char *alt_root, char **label, mode_t mode)
{
int offset = alt_root ? strlen(alt_root) : 0;
int ret;
if (!h) {
ret = selinux_init_setup();
if (ret < 0) {
*label = NULL;
return 0;
}
}
return selabel_lookup_raw(h, label, path + offset, mode);
int offset = alt_root ? strlen(alt_root) : 0;
int ret;
if (!h) {
ret = selinux_init_setup();
if (ret < 0) {
*label = NULL;
return 0;
}
}
return selabel_lookup_raw(h, label, path + offset, mode);
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -18,35 +18,35 @@
static void test_lib_lookup(void **state)
{
LIST_HEAD(lib_head);
struct lib *first_lib, *second_lib, *third_lib;
const char parser_str[] = "parser";
const char rpm_str[] = "rpm-test";
const char rpm_db_str[] = "rpm-test+db";
const char ima_ng_str[] = "compact_tlv-test";
LIST_HEAD(lib_head);
struct lib *first_lib, *second_lib, *third_lib;
const char parser_str[] = "parser";
const char rpm_str[] = "rpm-test";
const char rpm_db_str[] = "rpm-test+db";
const char ima_ng_str[] = "compact_tlv-test";
first_lib = lookup_lib(&lib_head, parser_str, rpm_str,
sizeof(rpm_str) - 1);
assert_non_null(first_lib);
assert_memory_equal(first_lib->format, rpm_str, sizeof(rpm_str) - 1);
first_lib = lookup_lib(&lib_head, parser_str, rpm_str,
sizeof(rpm_str) - 1);
assert_non_null(first_lib);
assert_memory_equal(first_lib->format, rpm_str, sizeof(rpm_str) - 1);
second_lib = lookup_lib(&lib_head, parser_str, rpm_db_str,
sizeof(rpm_db_str) - 1);
assert_non_null(second_lib);
second_lib = lookup_lib(&lib_head, parser_str, rpm_db_str,
sizeof(rpm_db_str) - 1);
assert_non_null(second_lib);
assert_ptr_equal(first_lib, second_lib);
assert_ptr_equal(first_lib, second_lib);
third_lib = lookup_lib(&lib_head, parser_str, ima_ng_str,
sizeof(ima_ng_str) - 1);
assert_non_null(third_lib);
third_lib = lookup_lib(&lib_head, parser_str, ima_ng_str,
sizeof(ima_ng_str) - 1);
assert_non_null(third_lib);
free_libs(&lib_head);
free_libs(&lib_head);
}
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_lib_lookup),
};
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_lib_lookup),
};
return cmocka_run_group_tests(tests, NULL, NULL);
return cmocka_run_group_tests(tests, NULL, NULL);
}
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册