Skip to content

Commit ce5bb5a

Browse files
robertosassumimizohar
authored andcommitted
ima: Return int in the functions to measure a buffer
ima_measure_critical_data() and process_buffer_measurement() currently don't return a result as, unlike appraisal-related functions, the result is not used by callers to deny an operation. Measurement-related functions instead rely on the audit subsystem to notify the system administrator when an error occurs. However, ima_measure_critical_data() and process_buffer_measurement() are a special case, as these are the only functions that can return a buffer measurement (for files, there is ima_file_hash()). In a subsequent patch, they will be modified to return the calculated digest. In preparation to return the result of the digest calculation, this patch modifies the return type from void to int, and returns 0 if the buffer has been successfully measured, a negative value otherwise. Given that the result of the measurement is still not necessary, this patch does not modify the behavior of existing callers by processing the returned value. For those, the return value is ignored. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Reviewed-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com> Acked-by: Paul Moore <paul@paul-moore.com> (for the SELinux bits) Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 5d1ef2c commit ce5bb5a

3 files changed

Lines changed: 37 additions & 28 deletions

File tree

include/linux/ima.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ extern void ima_post_path_mknod(struct user_namespace *mnt_userns,
3535
extern int ima_file_hash(struct file *file, char *buf, size_t buf_size);
3636
extern int ima_inode_hash(struct inode *inode, char *buf, size_t buf_size);
3737
extern void ima_kexec_cmdline(int kernel_fd, const void *buf, int size);
38-
extern void ima_measure_critical_data(const char *event_label,
39-
const char *event_name,
40-
const void *buf, size_t buf_len,
41-
bool hash);
38+
extern int ima_measure_critical_data(const char *event_label,
39+
const char *event_name,
40+
const void *buf, size_t buf_len,
41+
bool hash);
4242

4343
#ifdef CONFIG_IMA_APPRAISE_BOOTPARAM
4444
extern void ima_appraise_parse_cmdline(void);
@@ -144,10 +144,13 @@ static inline int ima_inode_hash(struct inode *inode, char *buf, size_t buf_size
144144

145145
static inline void ima_kexec_cmdline(int kernel_fd, const void *buf, int size) {}
146146

147-
static inline void ima_measure_critical_data(const char *event_label,
147+
static inline int ima_measure_critical_data(const char *event_label,
148148
const char *event_name,
149149
const void *buf, size_t buf_len,
150-
bool hash) {}
150+
bool hash)
151+
{
152+
return -ENOENT;
153+
}
151154

152155
#endif /* CONFIG_IMA */
153156

security/integrity/ima/ima.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file,
264264
struct evm_ima_xattr_data *xattr_value,
265265
int xattr_len, const struct modsig *modsig, int pcr,
266266
struct ima_template_desc *template_desc);
267-
void process_buffer_measurement(struct user_namespace *mnt_userns,
268-
struct inode *inode, const void *buf, int size,
269-
const char *eventname, enum ima_hooks func,
270-
int pcr, const char *func_data,
271-
bool buf_hash);
267+
int process_buffer_measurement(struct user_namespace *mnt_userns,
268+
struct inode *inode, const void *buf, int size,
269+
const char *eventname, enum ima_hooks func,
270+
int pcr, const char *func_data,
271+
bool buf_hash);
272272
void ima_audit_measurement(struct integrity_iint_cache *iint,
273273
const unsigned char *filename);
274274
int ima_alloc_init_template(struct ima_event_data *event_data,

security/integrity/ima/ima_main.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ int ima_post_load_data(char *buf, loff_t size,
827827
return 0;
828828
}
829829

830-
/*
830+
/**
831831
* process_buffer_measurement - Measure the buffer or the buffer data hash
832832
* @mnt_userns: user namespace of the mount the inode was found from
833833
* @inode: inode associated with the object being measured (NULL for KEY_CHECK)
@@ -840,12 +840,15 @@ int ima_post_load_data(char *buf, loff_t size,
840840
* @buf_hash: measure buffer data hash
841841
*
842842
* Based on policy, either the buffer data or buffer data hash is measured
843+
*
844+
* Return: 0 if the buffer has been successfully measured, a negative value
845+
* otherwise.
843846
*/
844-
void process_buffer_measurement(struct user_namespace *mnt_userns,
845-
struct inode *inode, const void *buf, int size,
846-
const char *eventname, enum ima_hooks func,
847-
int pcr, const char *func_data,
848-
bool buf_hash)
847+
int process_buffer_measurement(struct user_namespace *mnt_userns,
848+
struct inode *inode, const void *buf, int size,
849+
const char *eventname, enum ima_hooks func,
850+
int pcr, const char *func_data,
851+
bool buf_hash)
849852
{
850853
int ret = 0;
851854
const char *audit_cause = "ENOMEM";
@@ -867,7 +870,7 @@ void process_buffer_measurement(struct user_namespace *mnt_userns,
867870
u32 secid;
868871

869872
if (!ima_policy_flag)
870-
return;
873+
return -ENOENT;
871874

872875
template = ima_template_desc_buf();
873876
if (!template) {
@@ -889,7 +892,7 @@ void process_buffer_measurement(struct user_namespace *mnt_userns,
889892
secid, 0, func, &pcr, &template,
890893
func_data);
891894
if (!(action & IMA_MEASURE))
892-
return;
895+
return -ENOENT;
893896
}
894897

895898
if (!pcr)
@@ -937,7 +940,7 @@ void process_buffer_measurement(struct user_namespace *mnt_userns,
937940
func_measure_str(func),
938941
audit_cause, ret, 0, ret);
939942

940-
return;
943+
return ret;
941944
}
942945

943946
/**
@@ -977,18 +980,21 @@ void ima_kexec_cmdline(int kernel_fd, const void *buf, int size)
977980
* and extend the pcr. Examples of critical data could be various data
978981
* structures, policies, and states stored in kernel memory that can
979982
* impact the integrity of the system.
983+
*
984+
* Return: 0 if the buffer has been successfully measured, a negative value
985+
* otherwise.
980986
*/
981-
void ima_measure_critical_data(const char *event_label,
982-
const char *event_name,
983-
const void *buf, size_t buf_len,
984-
bool hash)
987+
int ima_measure_critical_data(const char *event_label,
988+
const char *event_name,
989+
const void *buf, size_t buf_len,
990+
bool hash)
985991
{
986992
if (!event_name || !event_label || !buf || !buf_len)
987-
return;
993+
return -ENOPARAM;
988994

989-
process_buffer_measurement(&init_user_ns, NULL, buf, buf_len, event_name,
990-
CRITICAL_DATA, 0, event_label,
991-
hash);
995+
return process_buffer_measurement(&init_user_ns, NULL, buf, buf_len,
996+
event_name, CRITICAL_DATA, 0,
997+
event_label, hash);
992998
}
993999

9941000
static int __init init_ima(void)

0 commit comments

Comments
 (0)