Skip to content

Commit b2724d5

Browse files
ebiggersmimizohar
authored andcommitted
security/integrity: constify some read-only data
Constify some static data that is never modified, so that it is placed in .rodata. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 691115c commit b2724d5

8 files changed

Lines changed: 16 additions & 13 deletions

File tree

‎security/integrity/digsig.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
static struct key *keyring[INTEGRITY_KEYRING_MAX];
2828

29-
static const char *keyring_name[INTEGRITY_KEYRING_MAX] = {
29+
static const char * const keyring_name[INTEGRITY_KEYRING_MAX] = {
3030
#ifndef CONFIG_INTEGRITY_TRUSTED_KEYRING
3131
"_evm",
3232
"_ima",

‎security/integrity/evm/evm_crypto.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#define EVMKEY "evm-key"
2828
#define MAX_KEY_SIZE 128
2929
static unsigned char evmkey[MAX_KEY_SIZE];
30-
static int evmkey_len = MAX_KEY_SIZE;
30+
static const int evmkey_len = MAX_KEY_SIZE;
3131

3232
struct crypto_shash *hmac_tfm;
3333
static struct crypto_shash *evm_tfm[HASH_ALGO__LAST];
@@ -38,7 +38,7 @@ static DEFINE_MUTEX(mutex);
3838

3939
static unsigned long evm_set_key_flags;
4040

41-
static char * const evm_hmac = "hmac(sha1)";
41+
static const char evm_hmac[] = "hmac(sha1)";
4242

4343
/**
4444
* evm_set_key() - set EVM HMAC key from the kernel

‎security/integrity/ima/ima.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct ima_template_desc {
8888
char *name;
8989
char *fmt;
9090
int num_fields;
91-
struct ima_template_field **fields;
91+
const struct ima_template_field **fields;
9292
};
9393

9494
struct ima_template_entry {

‎security/integrity/ima/ima_api.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ int ima_alloc_init_template(struct ima_event_data *event_data,
5151

5252
(*entry)->template_desc = template_desc;
5353
for (i = 0; i < template_desc->num_fields; i++) {
54-
struct ima_template_field *field = template_desc->fields[i];
54+
const struct ima_template_field *field =
55+
template_desc->fields[i];
5556
u32 len;
5657

5758
result = field->field_init(event_data,

‎security/integrity/ima/ima_fs.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ int ima_measurements_show(struct seq_file *m, void *v)
179179
/* 6th: template specific data */
180180
for (i = 0; i < e->template_desc->num_fields; i++) {
181181
enum ima_show_type show = IMA_SHOW_BINARY;
182-
struct ima_template_field *field = e->template_desc->fields[i];
182+
const struct ima_template_field *field =
183+
e->template_desc->fields[i];
183184

184185
if (is_ima_template && strcmp(field->field_id, "d") == 0)
185186
show = IMA_SHOW_BINARY_NO_FIELD_LEN;

‎security/integrity/ima/ima_init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "ima.h"
2626

2727
/* name for boot aggregate entry */
28-
static const char *boot_aggregate_name = "boot_aggregate";
28+
static const char boot_aggregate_name[] = "boot_aggregate";
2929
struct tpm_chip *ima_tpm_chip;
3030

3131
/* Add the boot aggregate to the IMA measurement list and extend

‎security/integrity/ima/ima_main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ int ima_read_file(struct file *file, enum kernel_read_file_id read_id)
440440
return 0;
441441
}
442442

443-
static int read_idmap[READING_MAX_ID] = {
443+
static const int read_idmap[READING_MAX_ID] = {
444444
[READING_FIRMWARE] = FIRMWARE_CHECK,
445445
[READING_FIRMWARE_PREALLOC_BUFFER] = FIRMWARE_CHECK,
446446
[READING_MODULE] = MODULE_CHECK,

‎security/integrity/ima/ima_template.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static struct ima_template_desc builtin_templates[] = {
3232
static LIST_HEAD(defined_templates);
3333
static DEFINE_SPINLOCK(template_list);
3434

35-
static struct ima_template_field supported_fields[] = {
35+
static const struct ima_template_field supported_fields[] = {
3636
{.field_id = "d", .field_init = ima_eventdigest_init,
3737
.field_show = ima_show_template_digest},
3838
{.field_id = "n", .field_init = ima_eventname_init,
@@ -49,7 +49,7 @@ static struct ima_template_field supported_fields[] = {
4949
static struct ima_template_desc *ima_template;
5050
static struct ima_template_desc *lookup_template_desc(const char *name);
5151
static int template_desc_init_fields(const char *template_fmt,
52-
struct ima_template_field ***fields,
52+
const struct ima_template_field ***fields,
5353
int *num_fields);
5454

5555
static int __init ima_template_setup(char *str)
@@ -125,7 +125,8 @@ static struct ima_template_desc *lookup_template_desc(const char *name)
125125
return found ? template_desc : NULL;
126126
}
127127

128-
static struct ima_template_field *lookup_template_field(const char *field_id)
128+
static const struct ima_template_field *
129+
lookup_template_field(const char *field_id)
129130
{
130131
int i;
131132

@@ -153,11 +154,11 @@ static int template_fmt_size(const char *template_fmt)
153154
}
154155

155156
static int template_desc_init_fields(const char *template_fmt,
156-
struct ima_template_field ***fields,
157+
const struct ima_template_field ***fields,
157158
int *num_fields)
158159
{
159160
const char *template_fmt_ptr;
160-
struct ima_template_field *found_fields[IMA_TEMPLATE_NUM_FIELDS_MAX];
161+
const struct ima_template_field *found_fields[IMA_TEMPLATE_NUM_FIELDS_MAX];
161162
int template_num_fields;
162163
int i, len;
163164

0 commit comments

Comments
 (0)