ima-evm-utils: Namespace some too generic function names
PATCH 1/1 ima-evm-utils: Namespace some too generic function names
Prefix dump', do_dump', and params' with ima_' to avoid colliding with other global symbols.
`params' is prefixed with a #define trick to avoid change in half hundred places.
---
I think all other exported functions (good example is verify_hash) should be prefixed too.
src/evmctl.c | 6 +++--- src/imaevm.h | 9 ++++++--- src/libimaevm.c | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-)
src/evmctl.c +3 -3
@@ -565,7 +565,7 @@ static int sign_evm(const char *file, const char *key) sig[1 ] =3 ;/* immutable signature version */ if (sigdump || params.verbose >=LOG_INFO ) -dump (sig, len); +ima_dump (sig, len);if (xattr) { err =lsetxattr (file, xattr_evm, sig, len,0 );
@@ -604,7 +604,7 @@ static int hash_ima(const char *file)log_info ("hash: " );if (sigdump || params.verbose >=LOG_INFO ) -dump (hash, len); +ima_dump (hash, len);if (xattr) { err =lsetxattr (file, xattr_ima, hash, len,0 );
@@ -638,7 +638,7 @@ static int sign_ima(const char *file, const char *key) sig[0 ] =EVM_IMA_XATTR_DIGSIG ;if (sigdump || params.verbose >=LOG_INFO ) -dump (sig, len); +ima_dump (sig, len);if (sigfile)bin2file (file,"sig" , sig, len);
src/imaevm.h +6 -3
@@ -49,9 +49,12 @@#include <openssl/rsa.h> +/* Namespace some internal symbols */ +#define params ima_params +#ifdef USE_FPRINTF #define do_log(level, fmt, args...) ({ if (level <= params.verbose) fprintf(stderr, fmt, ##args); }) -#define do_log_dump (level, p, len, cr) ({ if (level <= params.verbose) do_dump(stderr, p, len, cr); }) +#define do_log_dump (level, p, len, cr) ({ if (level <= params.verbose) ima_do_dump(stderr, p, len, cr); })#else #define do_log(level, fmt, args...) syslog(level, fmt, ##args)#define do_log_dump (level, p, len, cr)
@@ -206,8 +209,8 @@ struct RSA_ASN1_template {extern struct libevm_params params; -void do_dump (FILE *fp,const void *ptr,int len,bool cr); -void dump (const void *ptr,int len); +void ima_do_dump (FILE *fp,const void *ptr,int len,bool cr); +void ima_dump (const void *ptr,int len);int ima_calc_hash (const char *file,uint8_t *hash);int get_hash_algo (const char *algo);RSA *read_pub_key (const char *keyfile,int x509);
src/libimaevm.c +3 -3
@@ -89,7 +89,7 @@ struct libevm_params params = {static void __attribute__ ((constructor))libinit (void ); -void do_dump (FILE *fp,const void *ptr,int len,bool cr) +void ima_do_dump (FILE *fp,const void *ptr,int len,bool cr) {int i;uint8_t *data = (uint8_t *) ptr;
@@ -100,9 +100,9 @@ void do_dump(FILE *fp, const void *ptr, int len, bool cr)fprintf (fp,"\n" ); } -void dump (const void *ptr,int len) +void ima_dump (const void *ptr,int len) { -do_dump (stdout, ptr, len, true); +ima_do_dump (stdout, ptr, len, true); }const char *get_hash_algo_by_id (int algo)
Signature · 1 line
2.11.0
Hi Vitaly,
Quoted 6 lines · Vitaly Chikunov
Prefix
dump',do_dump', andparams' withima_' to avoid colliding with other global symbols.`params' is prefixed with a #define trick to avoid change in half hundred places.
I understand your point and as a short-term fix I'm fine with that, but IMO it would be better to actually rename the object in near future, mainly to avoid possible confusions.
Perhaps we can use Mimi's suggestions of a patch to standardize all return codes and also rework the naming with some convention.
Just thoughts... :)
Quoted 1 line
Signed-off-by Vitaly Chikunov <[email protected]>
Anyway.. thanks Vitaly!
Quoted 98 lines
---
I think all other exported functions (good example is
verify_hash) should be prefixed too.src/evmctl.c | 6 +++--- src/imaevm.h | 9 ++++++--- src/libimaevm.c | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-)src/evmctl.c +3
-3@@ -565,7 +565,7 @@ static int sign_evm(const char *file, const char *key) sig[1 ] =3 ;/* immutable signature version */ if (sigdump || params.verbose >=LOG_INFO ) -dump (sig, len); +ima_dump (sig, len);if (xattr) { err =lsetxattr (file, xattr_evm, sig, len,0 );@@ -604,7 +604,7 @@ static int hash_ima(const char *file)log_info ("hash: " );if (sigdump || params.verbose >=LOG_INFO ) -dump (hash, len); +ima_dump (hash, len);if (xattr) { err =lsetxattr (file, xattr_ima, hash, len,0 );@@ -638,7 +638,7 @@ static int sign_ima(const char *file, const char *key) sig[0 ] =EVM_IMA_XATTR_DIGSIG ;if (sigdump || params.verbose >=LOG_INFO ) -dump (sig, len); +ima_dump (sig, len);if (sigfile)bin2file (file,"sig" , sig, len);src/imaevm.h +6
-3@@ -49,9 +49,12 @@#include <openssl/rsa.h> +/* Namespace some internal symbols */ +#define params ima_params +#ifdef USE_FPRINTF #define do_log(level, fmt, args...) ({ if (level <= params.verbose) fprintf(stderr, fmt, ##args); }) -#define do_log_dump (level, p, len, cr) ({ if (level <= params.verbose) do_dump(stderr, p, len, cr); }) +#define do_log_dump (level, p, len, cr) ({ if (level <= params.verbose) ima_do_dump(stderr, p, len, cr); })#else #define do_log(level, fmt, args...) syslog(level, fmt, ##args)#define do_log_dump (level, p, len, cr)@@ -206,8 +209,8 @@ struct RSA_ASN1_template {extern struct libevm_params params; -void do_dump (FILE *fp,const void *ptr,int len,bool cr); -void dump (const void *ptr,int len); +void ima_do_dump (FILE *fp,const void *ptr,int len,bool cr); +void ima_dump (const void *ptr,int len);int ima_calc_hash (const char *file,uint8_t *hash);int get_hash_algo (const char *algo);RSA *read_pub_key (const char *keyfile,int x509);src/libimaevm.c +3
-3@@ -89,7 +89,7 @@ struct libevm_params params = {static void __attribute__ ((constructor))libinit (void ); -void do_dump (FILE *fp,const void *ptr,int len,bool cr) +void ima_do_dump (FILE *fp,const void *ptr,int len,bool cr) {int i;uint8_t *data = (uint8_t *) ptr;@@ -100,9 +100,9 @@ void do_dump(FILE *fp, const void *ptr, int len, bool cr)fprintf (fp,"\n" ); } -void dump (const void *ptr,int len) +void ima_dump (const void *ptr,int len) { -do_dump (stdout, ptr, len, true); +ima_do_dump (stdout, ptr, len, true); }const char *get_hash_algo_by_id (int algo)Signature · 1 line
2.11.0
Mimi Zohar
maintainerQuoted 2 lines · Vitaly Chikunov
Prefix
dump',do_dump', andparams' withima_' to avoid colliding with other global symbols.
The package is named ima-evm-utils, the tool is named evmctl, and now we're prefixing the global symbols with "ima". Some of the functions, like dump(), are used by both "ima" and "evm". Aiming for some sort of consistency, maybe it should be prefixed with "ima_evm", not just "ima_"?
dump() should never have been named just "dump". It should have at least been named "hexdump".
Quoted 3 lines
`params' is prefixed with a #define trick to avoid change in half hundred places.
Perhaps separate this change from the other change?
thanks,
Mimi
Quoted 97 lines
Signed-off-by Vitaly Chikunov <[email protected]>---
I think all other exported functions (good example is
verify_hash) should be prefixed too.src/evmctl.c | 6 +++--- src/imaevm.h | 9 ++++++--- src/libimaevm.c | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-)src/evmctl.c +3
-3@@ -565,7 +565,7 @@ static int sign_evm(const char *file, const char *key) sig[1 ] =3 ;/* immutable signature version */ if (sigdump || params.verbose >=LOG_INFO ) -dump (sig, len); +ima_dump (sig, len);if (xattr) { err =lsetxattr (file, xattr_evm, sig, len,0 );@@ -604,7 +604,7 @@ static int hash_ima(const char *file)log_info ("hash: " );if (sigdump || params.verbose >=LOG_INFO ) -dump (hash, len); +ima_dump (hash, len);if (xattr) { err =lsetxattr (file, xattr_ima, hash, len,0 );@@ -638,7 +638,7 @@ static int sign_ima(const char *file, const char *key) sig[0 ] =EVM_IMA_XATTR_DIGSIG ;if (sigdump || params.verbose >=LOG_INFO ) -dump (sig, len); +ima_dump (sig, len);if (sigfile)bin2file (file,"sig" , sig, len);src/imaevm.h +6
-3@@ -49,9 +49,12 @@#include <openssl/rsa.h> +/* Namespace some internal symbols */ +#define params ima_params +#ifdef USE_FPRINTF #define do_log(level, fmt, args...) ({ if (level <= params.verbose) fprintf(stderr, fmt, ##args); }) -#define do_log_dump (level, p, len, cr) ({ if (level <= params.verbose) do_dump(stderr, p, len, cr); }) +#define do_log_dump (level, p, len, cr) ({ if (level <= params.verbose) ima_do_dump(stderr, p, len, cr); })#else #define do_log(level, fmt, args...) syslog(level, fmt, ##args)#define do_log_dump (level, p, len, cr)@@ -206,8 +209,8 @@ struct RSA_ASN1_template {extern struct libevm_params params; -void do_dump (FILE *fp,const void *ptr,int len,bool cr); -void dump (const void *ptr,int len); +void ima_do_dump (FILE *fp,const void *ptr,int len,bool cr); +void ima_dump (const void *ptr,int len);int ima_calc_hash (const char *file,uint8_t *hash);int get_hash_algo (const char *algo);RSA *read_pub_key (const char *keyfile,int x509);src/libimaevm.c +3
-3@@ -89,7 +89,7 @@ struct libevm_params params = {static void __attribute__ ((constructor))libinit (void ); -void do_dump (FILE *fp,const void *ptr,int len,bool cr) +void ima_do_dump (FILE *fp,const void *ptr,int len,bool cr) {int i;uint8_t *data = (uint8_t *) ptr;@@ -100,9 +100,9 @@ void do_dump(FILE *fp, const void *ptr, int len, bool cr)fprintf (fp,"\n" ); } -void dump (const void *ptr,int len) +void ima_dump (const void *ptr,int len) { -do_dump (stdout, ptr, len, true); +ima_do_dump (stdout, ptr, len, true); }const char *get_hash_algo_by_id (int algo)
Mimi,
Quoted 9 lines · Mimi Zohar
Quoted 2 lines · Vitaly Chikunov
Prefix
dump',do_dump', andparams' withima_' to avoid colliding with other global symbols.The package is named ima-evm-utils, the tool is named evmctl, and now we're prefixing the global symbols with "ima". Some of the functions, like
dump(), are used by both "ima" and "evm". Aiming for some sort of consistency, maybe it should be prefixed with "ima_evm", not just "ima_"?
Just ima_ is OK with me. EVM could be thought as IMA extension. Or we can use evm_ like in evmctl. Or imaevm_ (without underscore, like in libimaevm or imaevm.h).
Quoted 7 lines
dump()should never have been named just "dump". It should have at least been named "hexdump".Quoted 2 lines
`params' is prefixed with a #define trick to avoid change in half hundred places.
Perhaps separate this change from the other change?
I agree to Bruno E. O. Meneguele it's better to actually rename `params' like other functions instead of redefining. Then all renames can go in one commit?
Thanks,
Mimi Zohar
maintainerQuoted 7 lines · Vitaly Chikunov
Mimi,
Quoted 4 lines · Mimi Zohar
Quoted 2 lines · Vitaly Chikunov
Prefix
dump',do_dump', andparams' withima_' to avoid colliding with other global symbols.
Quoted 7 lines
Quoted 5 lines
The package is named ima-evm-utils, the tool is named evmctl, and now we're prefixing the global symbols with "ima". Some of the functions, like
dump(), are used by both "ima" and "evm". Aiming for some sort of consistency, maybe it should be prefixed with "ima_evm", not just "ima_"?Just
ima_is OK with me. EVM could be thought as IMA extension.
At least in the kernel, I've tried really hard to keep them as two independent subsystems. Does it make sense to use EVM without IMA, probably not. The EVM design allows for other subsystems, not only IMA, to verify the file metdata integrity. In fact, I heard about some plans, relatively recently, to do so.
Quoted 2 lines
Or we can use
evm_like in evmctl. Orimaevm_(without underscore, like in libimaevm orimaevm.h).
There's already a lot of confusion as to what is "IMA". Not only can IMA be configured to store measurements, but can also be configured to verify file signatures/hashes and audit file hashes. Not that anyone is looking at the naming details in this code, but I don't think we should add to the confusion. Could we use "imaevm_" as you suggested?
struct libimaevm_params {
int verbose;
int x509;
const char *hash_algo;
const char *keyfile;
const char *keypass;
};
extern struct libimaevm_params ima_params;
imaevm_params?
Quoted 4 lines
Quoted 4 lines
dump()should never have been named just "dump". It should have at least been named "hexdump".
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
`params' is prefixed with a #define trick to avoid change in half hundred places.
Perhaps separate this change from the other change?
I agree to Bruno E. O. Meneguele it's better to actually rename `params' like other functions instead of redefining. Then all renames can go in one commit?
Sure.
"get_hash_algo()" can't be made static as it is being called from hash_ima(). Could you also include renaming "get_hash_algo()" as well?
Thanks!
Mimi