IMA: Update KBUILD_MODNAME for IMA files to ima
Subsystems (4)
PATCH v2 1/3 IMA: Update KBUILD_MODNAME for IMA files to ima
Log statements from ima_mok.c, ima_asymmetric_keys.c, and ima_queue_keys.c are prefixed with the respective file names and not with the string "ima".
This change fixes the log statement prefix to be consistent with the rest of the IMA files.
--- security/integrity/ima/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
security/integrity/ima/Makefile +3 -3
@@ -11,6 +11,6 @@ ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \ ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o ima-$(CONFIG_IMA_APPRAISE_MODSIG) += ima_modsig.o ima-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o -obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o -obj-$(CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS) += ima_asymmetric_keys.o -obj-$(CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS) += ima_queue_keys.o +ima-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o +ima-$(CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS) += ima_asymmetric_keys.o +ima-$(CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS) += ima_queue_keys.o
Signature · 1 line
2.17.1
PATCH v2 2/3 IMA: Add log statements for failure conditions.
process_buffer_measurement() and ima_alloc_key_entry() functions do not have log messages for failure conditions.
This change adds log statements in the above functions.
--- security/integrity/ima/ima_main.c | 3 +++ security/integrity/ima/ima_queue_keys.c | 1 + 2 files changed, 4 insertions(+)
security/integrity/ima/ima_main.c +3 -0
@@ -757,6 +757,9 @@ void process_buffer_measurement(const void *buf, int size,ima_free_template_entry (entry); out: +if (ret <0 ) +pr_err ("Process buffer measurement failed, result: %d\n" , ret); +return ; }
security/integrity/ima/ima_queue_keys.c +1 -0
@@ -90,6 +90,7 @@ static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring, out:if (rc) { +pr_err ("Key entry allocation failed, result: %d\n" , rc);ima_free_key_entry (entry); entry =NULL ; }
Signature · 1 line
2.17.1
Re: [PATCH v2 2/3] IMA: Add log statements for failure conditions.
Quoted 2 lines · Tushar Sugandhi
process_buffer_measurement()andima_alloc_key_entry()functions do not have log messages for failure conditions.
trivia:
security/integrity/ima/ima_main.c
Quoted 1 line
security/integrity/ima/ima_main.c +0
-0
[]
security/integrity/ima/ima_main.c void process_buffer_measurement(const void *buf, int size, · line 761
Quoted 6 lines
security/integrity/ima/ima_main.c +2
-0@@ -757,6 +757,9 @@ void process_buffer_measurement(const void *buf, int size,ima_free_template_entry (entry); out: +if (ret <0 ) +pr_err ("Process buffer measurement failed, result: %d\n" , ret);
perhaps use %s, __func__
pr_err("%s: failed, result: %d\n", __func__, ret);security/integrity/ima/ima_queue_keys.c
Quoted 1 line
security/integrity/ima/ima_queue_keys.c +0
-0
[]
security/integrity/ima/ima_queue_keys.c static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring, · line 96
Quoted 8 lines
security/integrity/ima/ima_queue_keys.c +1
-0@@ -90,6 +90,7 @@ static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring, out:if (rc) { +pr_err ("Key entry allocation failed, result: %d\n" , rc);ima_free_key_entry (entry); entry =NULL ; }
Likely the pr_err is unnecessary here as kmalloc, kstrdup and kmemdup all emit a dump_stack() on allocation failure.
Perhaps instead:
o Remove unnecessary indentation in ima_free_key_entry by returning early on NULL argument
o Remove unnecessary rc, tests and label in ima_alloc_key_entry
--- security/integrity/ima/ima_queue_keys.c | 37 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 22 deletions(-)
security/integrity/ima/ima_queue_keys.c +15 -22
@@ -58,42 +58,35 @@ void ima_init_key_queue(void)static void ima_free_key_entry (struct ima_key_entry *entry) { -if (entry) { -kfree (entry->payload); -kfree (entry->keyring_name); -kfree (entry); - } +if (!entry) +return ; + +kfree (entry->payload); +kfree (entry->keyring_name); +kfree (entry); }static struct ima_key_entry *ima_alloc_key_entry (struct key *keyring,const void *payload,size_t payload_len) { -int rc =0 ;struct ima_key_entry *entry; entry =kzalloc (sizeof (*entry),GFP_KERNEL ); -if (entry) { - entry->payload =kmemdup (payload, payload_len,GFP_KERNEL ); - entry->keyring_name =kstrdup (keyring->description, -GFP_KERNEL ); - entry->payload_len = payload_len; - } - -if ((entry ==NULL ) || (entry->payload ==NULL ) || - (entry->keyring_name ==NULL )) { - rc = -ENOMEM ; - goto out; - } +if (!entry) +return NULL ; -INIT_LIST_HEAD (&entry->list); + entry->payload =kmemdup (payload, payload_len,GFP_KERNEL ); + entry->payload_len = payload_len; + entry->keyring_name =kstrdup (keyring->description,GFP_KERNEL ); -out: -if (rc) { +if (!entry->payload || !entry->keyring_name) {ima_free_key_entry (entry); - entry =NULL ; +return NULL ; } +INIT_LIST_HEAD (&entry->list); +return entry; }
Re: [PATCH v2 2/3] IMA: Add log statements for failure conditions.
Hi Joe,
Quoted 11 lines · Joe Perches
Quoted 2 lines · Tushar Sugandhi
process_buffer_measurement()andima_alloc_key_entry()functions do not have log messages for failure conditions.trivia:
security/integrity/ima/ima_main.c
Quoted 1 line
security/integrity/ima/ima_main.c +0
-0[]
Quoted 3 lines
security/integrity/ima/ima_main.c +0
-0@@ -757,6 +757,9 @@ void process_buffer_measurement(const void *buf, int size,ima_free_template_entry (entry);
Quoted 8 lines
security/integrity/ima/ima_main.c void process_buffer_measurement(const void *buf, int size, · line 761
Quoted 3 lines
security/integrity/ima/ima_main.c +2
-0out: +if (ret <0 ) +pr_err ("Process buffer measurement failed, result: %d\n" , ret);perhaps use %s,
__func__pr_err("%s: failed, result: %d\n", __func__, ret);
Sounds good. Will make this change in the next update.
Quoted 4 lines
security/integrity/ima/ima_queue_keys.c
Quoted 1 line
security/integrity/ima/ima_queue_keys.c +0
-0[]
Quoted 2 lines
security/integrity/ima/ima_queue_keys.c +0
-0@@ -90,6 +90,7 @@ static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring,
Quoted 9 lines
security/integrity/ima/ima_queue_keys.c static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring, · line 96
Quoted 6 lines
security/integrity/ima/ima_queue_keys.c +1
-0out:if (rc) { +pr_err ("Key entry allocation failed, result: %d\n" , rc);ima_free_key_entry (entry); entry =NULL ; }Likely the
pr_erris unnecessary here as kmalloc, kstrdup and kmemdup all emit adump_stack()on allocation failure.
Thanks for pointing out kmalloc, kstrdup, and kmemdup emit a dump_stack(). But keeping the above pr_err() will help associate the failure with IMA. For instance - "dmesg | grep ima:" will include this error.
Perhaps I should add __func__ here as well.
And since we are redefining the pr_fmt to prefix module and base names, it will help further to pinpoint where exactly the failure is coming from.
Quoted 21 lines
Perhaps instead:
o Remove unnecessary indentation in
ima_free_key_entryby returning early on NULL argument
o Remove unnecessary rc, tests and label inima_alloc_key_entry--- security/integrity/ima/ima_queue_keys.c | 37 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 22 deletions(-)security/integrity/ima/ima_queue_keys.c +0
-3@@ -58,42 +58,35 @@ void ima_init_key_queue(void)static void ima_free_key_entry (struct ima_key_entry *entry) { -if (entry) { -kfree (entry->payload); -kfree (entry->keyring_name);
security/integrity/ima/ima_queue_keys.c void ima_init_key_queue(void) · line 68
Quoted 10 lines
security/integrity/ima/ima_queue_keys.c +6
-2-kfree (entry); - } +if (!entry) +return ; + +kfree (entry->payload); +kfree (entry->keyring_name); +kfree (entry); }
Thanks for the feedback. Appreciate it. I would like to make this fix.
But I am not sure if this patchset, which mainly focuses on improving logging in IMA, is the right patchset for this.
Quoted 32 lines
security/integrity/ima/ima_queue_keys.c +6
-16static struct ima_key_entry *ima_alloc_key_entry (struct key *keyring,const void *payload,size_t payload_len) { -int rc =0 ;struct ima_key_entry *entry; entry =kzalloc (sizeof (*entry),GFP_KERNEL ); -if (entry) { - entry->payload =kmemdup (payload, payload_len,GFP_KERNEL ); - entry->keyring_name =kstrdup (keyring->description, -GFP_KERNEL ); - entry->payload_len = payload_len; - } - -if ((entry ==NULL ) || (entry->payload ==NULL ) || - (entry->keyring_name ==NULL )) { - rc = -ENOMEM ; - goto out; - } +if (!entry) +return NULL ; -INIT_LIST_HEAD (&entry->list); + entry->payload =kmemdup (payload, payload_len,GFP_KERNEL ); + entry->payload_len = payload_len; + entry->keyring_name =kstrdup (keyring->description,GFP_KERNEL ); -out: -if (rc) { +if (!entry->payload || !entry->keyring_name) {
security/integrity/ima/ima_queue_keys.c void ima_init_key_queue(void) · line 92
Quoted 10 lines
security/integrity/ima/ima_queue_keys.c +3
-1ima_free_key_entry (entry); - entry =NULL ; +return NULL ; } +INIT_LIST_HEAD (&entry->list); +return entry; }
Thanks again. This recommended change certainly makes the code more readable. But again, I am not sure if this patchset is the right one for this proposed change. Perhaps I can create another patchset for the above two recommended changes, and only focus on improving logging in this patchset?
Thanks,
Tushar
Re: [PATCH v2 2/3] IMA: Add log statements for failure conditions.
Quoted 1 line · Tushar Sugandhi
Hi Joe,
Rehi Tushar.
Quoted 4 lines · Joe Perches
Quoted 3 lines · Tushar Sugandhi
Quoted 2 lines
process_buffer_measurement()andima_alloc_key_entry()functions do not have log messages for failure conditions.
[]
Quoted 13 lines
Quoted 4 lines
security/integrity/ima/ima_queue_keys.c
Quoted 1 line
security/integrity/ima/ima_queue_keys.c +0
-0[]
Quoted 2 lines
security/integrity/ima/ima_queue_keys.c +0
-0@@ -90,6 +90,7 @@ static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring,Quoted 9 lines
security/integrity/ima/ima_queue_keys.c static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring, · line 96
Quoted 6 lines
security/integrity/ima/ima_queue_keys.c +1
-0out:if (rc) { +pr_err ("Key entry allocation failed, result: %d\n" , rc);ima_free_key_entry (entry); entry =NULL ; }Likely the
pr_erris unnecessary here as kmalloc, kstrdup and kmemdup all emit adump_stack()on allocation failure.
Quoted 7 lines
Thanks for pointing out kmalloc, kstrdup, and kmemdup emit a
dump_stack(). But keeping the abovepr_err()will help associate the failure with IMA.
For instance - "dmesg | grep ima:" will include this error. Perhaps I should add__func__here as well.
And since we are redefining thepr_fmtto prefix module and base names, it will help further to pinpoint where exactly the failure is coming from.
The dump_stack is preferred over a single printk message and the association isn't particularly useful.
Quoted 5 lines
Thanks again. This recommended change certainly makes the code more readable. But again, I am not sure if this patchset is the right one for this proposed change.
Perhaps I can create another patchset for the above two recommended changes, and only focus on improving logging in this patchset?
Your choice.
PATCH v2 3/3 IMA: Add module name and base name prefix to log
In reply to Tushar SugandhiThe #define for formatting log messages, pr_fmt, is duplicated in the files under security/integrity.
This change moves the definition to security/integrity/integrity.h and removes the duplicate definitions in the other files under security/integrity. Also, it adds KBUILD_MODNAME and KBUILD_BASENAME prefix to the log messages.
--- security/integrity/digsig.c | 2 -- security/integrity/digsig_asymmetric.c | 2 -- security/integrity/evm/evm_crypto.c | 2 -- security/integrity/evm/evm_main.c | 2 -- security/integrity/evm/evm_secfs.c | 2 -- security/integrity/ima/ima_asymmetric_keys.c | 2 -- security/integrity/ima/ima_crypto.c | 2 -- security/integrity/ima/ima_fs.c | 2 -- security/integrity/ima/ima_init.c | 2 -- security/integrity/ima/ima_kexec.c | 1 - security/integrity/ima/ima_main.c | 2 -- security/integrity/ima/ima_policy.c | 2 -- security/integrity/ima/ima_queue.c | 2 -- security/integrity/ima/ima_queue_keys.c | 2 -- security/integrity/ima/ima_template.c | 2 -- security/integrity/ima/ima_template_lib.c | 2 -- security/integrity/integrity.h | 6 ++++++ 17 files changed, 6 insertions(+), 31 deletions(-)
security/integrity/digsig.c +0 -2
@@ -6,8 +6,6 @@* Dmitry Kasatkin <[email protected]> */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/err.h> #include <linux/sched.h> #include <linux/slab.h>
security/integrity/digsig_asymmetric.c +0 -2
@@ -6,8 +6,6 @@* Dmitry Kasatkin <[email protected]> */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/err.h> #include <linux/ratelimit.h> #include <linux/key-type.h>
security/integrity/evm/evm_crypto.c +0 -2
@@ -10,8 +10,6 @@* Using root's kernel master key (kmk), calculate the HMAC */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/export.h> #include <linux/crypto.h> #include <linux/xattr.h>
security/integrity/evm/evm_main.c +0 -2
@@ -11,8 +11,6 @@* evm_inode_removexattr, and evm_verifyxattr */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/init.h> #include <linux/crypto.h> #include <linux/audit.h>
security/integrity/evm/evm_secfs.c +0 -2
@@ -10,8 +10,6 @@* - Get the key and enable EVM */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/audit.h> #include <linux/uaccess.h> #include <linux/init.h>
security/integrity/ima/ima_asymmetric_keys.c +0 -2
@@ -9,8 +9,6 @@* create or update. */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <keys/asymmetric-type.h> #include "ima.h"
security/integrity/ima/ima_crypto.c +0 -2
@@ -10,8 +10,6 @@* Calculates md5/sha1 file hash, template hash, boot-aggreate hash */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/kernel.h> #include <linux/moduleparam.h> #include <linux/ratelimit.h>
security/integrity/ima/ima_fs.c +0 -2
@@ -12,8 +12,6 @@* current measurement list and IMA statistics */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/fcntl.h> #include <linux/slab.h> #include <linux/init.h>
security/integrity/ima/ima_init.c +0 -2
@@ -11,8 +11,6 @@* initialization and cleanup functions */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/init.h> #include <linux/scatterlist.h> #include <linux/slab.h>
security/integrity/ima/ima_kexec.c +0 -1
@@ -6,7 +6,6 @@* Thiago Jung Bauermann <[email protected]> * Mimi Zohar <[email protected]> */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/seq_file.h> #include <linux/vmalloc.h>
security/integrity/ima/ima_main.c +0 -2
@@ -15,8 +15,6 @@* and ima_file_check. */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/module.h> #include <linux/file.h> #include <linux/binfmts.h>
security/integrity/ima/ima_policy.c +0 -2
@@ -7,8 +7,6 @@* - initialize default measure policy rules */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/init.h> #include <linux/list.h> #include <linux/fs.h>
security/integrity/ima/ima_queue.c +0 -2
@@ -15,8 +15,6 @@* ever removed or changed during the boot-cycle. */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/rculist.h> #include <linux/slab.h> #include "ima.h"
security/integrity/ima/ima_queue_keys.c +0 -2
@@ -8,8 +8,6 @@* Enables deferred processing of keys */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/workqueue.h> #include <keys/asymmetric-type.h> #include "ima.h"
security/integrity/ima/ima_template.c +0 -2
@@ -9,8 +9,6 @@* Helpers to manage template descriptors. */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/rculist.h> #include "ima.h" #include "ima_template_lib.h"
security/integrity/ima/ima_template_lib.c +0 -2
@@ -9,8 +9,6 @@* Library of supported template fields. */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include "ima_template_lib.h" static bool ima_template_hash_algo_allowed (u8 algo)
security/integrity/integrity.h +6 -0
@@ -6,6 +6,12 @@* Mimi Zohar <[email protected]> */ +#ifdef pr_fmt +#undef pr_fmt +#endif + +#define pr_fmt (fmt) KBUILD_MODNAME ": " KBUILD_BASENAME ": " fmt +#include <linux/types.h> #include <linux/integrity.h> #include <crypto/sha.h>
Signature · 1 line
2.17.1
Quoted 3 lines · Tushar Sugandhi
Log statements from
ima_mok.c,ima_asymmetric_keys.c, andima_queue_keys.care prefixed with the respective file names and not with the string "ima".
Series seems sensible, thanks Tushar.
Next time you might choose to use
git format-patch --cover-letter
and write in the 0/n cover letter what the point
of the patch series is.
cheers and welcome... Joe
On 2/10/20 7:09 PM, Joe Perches wrote:
Hi Joe,
Quoted 9 lines
Series seems sensible, thanks Tushar.
Next time you might choose to use
git format-patch --cover-letterand write in the 0/n cover letter what the point
of the patch series is.
I was the one who suggested that we may not need a cover letter and instead provide the details in the patch description. We can include the cover letter in the next update.
thanks,
-lakshmi
Hi Joe,
Quoted 10 lines · Lakshmi Ramasubramanian
On 2/10/20 7:09 PM, Joe Perches wrote:
Hi Joe,
Quoted 6 lines
Series seems sensible, thanks Tushar.
Next time you might choose to use
git format-patch --cover-letter
Quoted 9 lines
Quoted 3 lines
and write in the 0/n cover letter what the point
of the patch series is.I was the one who suggested that we may not need a cover letter and instead provide the details in the patch description. We can include the cover letter in the next update.
thanks,
-lakshmi
I will include the cover letter in the next update.
Thanks,
Tushar