From: Eugene Syromyatnikov Date: Wed, 9 Oct 2019 18:07:58 +0000 (+0200) Subject: Enable building of netlink_crypto decoder without linux/cryptouser.h X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f1d273a003c25de827f6aba4727adaed6ae9b176;p=strace Enable building of netlink_crypto decoder without linux/cryptouser.h * xlat/crypto_msgs.in: New file. * configure.ac (AC_CHECK_TYPES): Check for struct crypto_user_alg. * netlink.c: Include "xlat/crypto_msgs.h" with XLAT_MACROS_ONLY defined. (netlink_decoders[]): Remove HAVE_LINUX_CRYPTOUSER_H guard around [NETLINK_CRYPTO] item. * netlink_crypto.c: Remove HAVE_LINUX_CRYPTOUSER_H guard; include under HAVE_LINUX_CRYPTOUSER_H; include "xlat/crypto_msgs.h" with XLAT_MACROS_ONLY defined. [!CRYPTO_MAX_NAME] (CRYPTO_MAX_NAME): New macro. (struct_crypto_user_alg, struct_crypto_report_hash, struct_crypto_report_cipher, struct_crypto_report_blkcipher, struct_crypto_report_aead, struct_crypto_report_rng): New typedefs. [HAVE_STRUCT_CRYPTO_USER_ALG]: New static_assert to check that sizeof(struct crypto_user_alg) has the expected value. [HAVE_STRUCT_CRYPTO_REPORT_HASH]: New static_assert to check that sizeof(struct crypto_report_hash) has the expected value. [HAVE_STRUCT_CRYPTO_REPORT_CIPHER]: New static_assert to check that sizeof(struct crypto_report_cipher) has the expected value. [HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER]: New static_assert to check that sizeof(struct crypto_report_blkcipher) has the expected value. [HAVE_STRUCT_CRYPTO_REPORT_AEAD]: New static_assert to check that sizeof(struct crypto_report_aead) has the expected value. [HAVE_STRUCT_CRYPTO_REPORT_RNG]: New static_assert to check that sizeof(struct crypto_report_rng) has the expected value. (decode_crypto_report_hash) [!HAVE_STRUCT_CRYPTO_REPORT_HASH]: Remove. (decode_crypto_report_hash): Change type of rhash to struct_crypto_report_hash. (decode_crypto_report_blkcipher) [!HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER]: Remove. (decode_crypto_report_blkcipher): Change type of rblkcipher to struct_crypto_report_blkcipher. (decode_crypto_report_aead) [!HAVE_STRUCT_CRYPTO_REPORT_AEAD]: Remove. (decode_crypto_report_aead): Change type of raead to struct_crypto_report_aead. (decode_crypto_report_rng) [!HAVE_STRUCT_CRYPTO_REPORT_RNG]: Remove. (decode_crypto_report_rng): Change type of rrng to struct_crypto_report_rng. (decode_crypto_report_cipher) [!HAVE_STRUCT_CRYPTO_REPORT_CIPHER]: Remove. (decode_crypto_report_cipher): Change type of rcipher to struct_crypto_report_cipher. (decode_crypto_user_alg): Change type of alg to struct_crypto_user_alg. References: https://bugzilla.redhat.com/show_bug.cgi?id=1758201 --- diff --git a/configure.ac b/configure.ac index 949b058a..866e65ab 100644 --- a/configure.ac +++ b/configure.ac @@ -333,6 +333,7 @@ AC_CHECK_TYPES(m4_normalize([ #include ]) AC_CHECK_TYPES(m4_normalize([ + struct crypto_user_alg, struct crypto_report_aead, struct crypto_report_blkcipher, struct crypto_report_cipher, diff --git a/netlink.c b/netlink.c index ad10b7ab..1792a459 100644 --- a/netlink.c +++ b/netlink.c @@ -40,6 +40,10 @@ #include "xlat/nl_xfrm_types.h" #include "xlat/nlmsgerr_attrs.h" +# define XLAT_MACROS_ONLY +# include "xlat/crypto_msgs.h" +# undef XLAT_MACROS_ONLY + /* * Fetch a struct nlmsghdr from the given address. */ @@ -533,9 +537,7 @@ decode_nlmsgerr(struct tcb *const tcp, } static const netlink_decoder_t netlink_decoders[] = { -#ifdef HAVE_LINUX_CRYPTOUSER_H [NETLINK_CRYPTO] = decode_netlink_crypto, -#endif #ifdef HAVE_LINUX_NETFILTER_NFNETLINK_H [NETLINK_NETFILTER] = decode_netlink_netfilter, #endif diff --git a/netlink_crypto.c b/netlink_crypto.c index 135416b4..9ee458ab 100644 --- a/netlink_crypto.c +++ b/netlink_crypto.c @@ -8,16 +8,101 @@ #include "defs.h" -#ifdef HAVE_LINUX_CRYPTOUSER_H - # include "netlink.h" # include "nlattr.h" # include "print_fields.h" -# include +# if HAVE_LINUX_CRYPTOUSER_H +# include +# endif # include "xlat/crypto_nl_attrs.h" +# define XLAT_MACROS_ONLY +# include "xlat/crypto_msgs.h" +# undef XLAT_MACROS_ONLY + + +# ifndef CRYPTO_MAX_NAME +# define CRYPTO_MAX_NAME 64 +# endif + +typedef struct { + char cru_name[CRYPTO_MAX_NAME]; + char cru_driver_name[CRYPTO_MAX_NAME]; + char cru_module_name[CRYPTO_MAX_NAME]; + uint32_t cru_type; + uint32_t cru_mask; + uint32_t cru_refcnt; + uint32_t cru_flags; +} struct_crypto_user_alg; + +typedef struct { + char type[CRYPTO_MAX_NAME]; + uint32_t blocksize; + uint32_t digestsize; +} struct_crypto_report_hash; + +typedef struct { + char type[CRYPTO_MAX_NAME]; + uint32_t blocksize; + uint32_t min_keysize; + uint32_t max_keysize; +} struct_crypto_report_cipher; + +typedef struct { + char type[CRYPTO_MAX_NAME]; + char geniv[CRYPTO_MAX_NAME]; + uint32_t blocksize; + uint32_t min_keysize; + uint32_t max_keysize; + uint32_t ivsize; +} struct_crypto_report_blkcipher; + +typedef struct { + char type[CRYPTO_MAX_NAME]; + char geniv[CRYPTO_MAX_NAME]; + uint32_t blocksize; + uint32_t maxauthsize; + uint32_t ivsize; +} struct_crypto_report_aead; + +typedef struct { + char type[CRYPTO_MAX_NAME]; + uint32_t seedsize; +} struct_crypto_report_rng; + +# ifdef HAVE_STRUCT_CRYPTO_USER_ALG +static_assert(sizeof(struct_crypto_user_alg) == sizeof(struct crypto_user_alg), + "struct crypto_user_alg mismatch, please update the decoder"); +# endif +# ifdef HAVE_STRUCT_CRYPTO_REPORT_HASH +static_assert(sizeof(struct_crypto_report_hash) + == sizeof(struct crypto_report_hash), + "struct crypto_report_hash mismatch, please update the decoder"); +# endif +# ifdef HAVE_STRUCT_CRYPTO_REPORT_CIPHER +static_assert(sizeof(struct_crypto_report_cipher) + == sizeof(struct crypto_report_cipher), + "struct crypto_report_cipher mismatch, please update the decoder"); +# endif +# ifdef HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER +static_assert(sizeof(struct_crypto_report_blkcipher) + == sizeof(struct crypto_report_blkcipher), + "struct crypto_report_blkcipher mismatch, please update the decoder"); +# endif +# ifdef HAVE_STRUCT_CRYPTO_REPORT_AEAD +static_assert(sizeof(struct_crypto_report_aead) + == sizeof(struct crypto_report_aead), + "struct crypto_report_aead mismatch, please update the decoder"); +# endif +# ifdef HAVE_STRUCT_CRYPTO_REPORT_RNG +static_assert(sizeof(struct_crypto_report_rng) + == sizeof(struct crypto_report_rng), + "struct crypto_report_rng mismatch, please update the decoder"); +# endif + + static bool decode_crypto_report_generic(struct tcb *const tcp, const kernel_ulong_t addr, @@ -37,8 +122,7 @@ decode_crypto_report_hash(struct tcb *const tcp, const unsigned int len, const void *const opaque_data) { -# ifdef HAVE_STRUCT_CRYPTO_REPORT_HASH - struct crypto_report_hash rhash; + struct_crypto_report_hash rhash; if (len < sizeof(rhash)) printstrn(tcp, addr, len); @@ -48,9 +132,6 @@ decode_crypto_report_hash(struct tcb *const tcp, PRINT_FIELD_U(", ", rhash, digestsize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -61,8 +142,7 @@ decode_crypto_report_blkcipher(struct tcb *const tcp, const unsigned int len, const void *const opaque_data) { -# ifdef HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER - struct crypto_report_blkcipher rblkcipher; + struct_crypto_report_blkcipher rblkcipher; if (len < sizeof(rblkcipher)) printstrn(tcp, addr, len); @@ -75,9 +155,6 @@ decode_crypto_report_blkcipher(struct tcb *const tcp, PRINT_FIELD_U(", ", rblkcipher, ivsize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -88,8 +165,7 @@ decode_crypto_report_aead(struct tcb *const tcp, const unsigned int len, const void *const opaque_data) { -# ifdef HAVE_STRUCT_CRYPTO_REPORT_AEAD - struct crypto_report_aead raead; + struct_crypto_report_aead raead; if (len < sizeof(raead)) printstrn(tcp, addr, len); @@ -101,9 +177,6 @@ decode_crypto_report_aead(struct tcb *const tcp, PRINT_FIELD_U(", ", raead, ivsize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -114,8 +187,7 @@ decode_crypto_report_rng(struct tcb *const tcp, const unsigned int len, const void *const opaque_data) { -# ifdef HAVE_STRUCT_CRYPTO_REPORT_RNG - struct crypto_report_rng rrng; + struct_crypto_report_rng rrng; if (len < sizeof(rrng)) printstrn(tcp, addr, len); @@ -124,9 +196,6 @@ decode_crypto_report_rng(struct tcb *const tcp, PRINT_FIELD_U(", ", rrng, seedsize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -137,8 +206,7 @@ decode_crypto_report_cipher(struct tcb *const tcp, const unsigned int len, const void *const opaque_data) { -# ifdef HAVE_STRUCT_CRYPTO_REPORT_CIPHER - struct crypto_report_cipher rcipher; + struct_crypto_report_cipher rcipher; if (len < sizeof(rcipher)) printstrn(tcp, addr, len); @@ -149,9 +217,6 @@ decode_crypto_report_cipher(struct tcb *const tcp, PRINT_FIELD_U(", ", rcipher, max_keysize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -175,7 +240,7 @@ decode_crypto_user_alg(struct tcb *const tcp, const kernel_ulong_t addr, const unsigned int len) { - struct crypto_user_alg alg; + struct_crypto_user_alg alg; if (len < sizeof(alg)) printstrn(tcp, addr, len); @@ -220,5 +285,3 @@ decode_netlink_crypto(struct tcb *const tcp, return true; } - -#endif /* HAVE_LINUX_CRYPTOUSER_H */ diff --git a/xlat/crypto_msgs.in b/xlat/crypto_msgs.in new file mode 100644 index 00000000..89426a9a --- /dev/null +++ b/xlat/crypto_msgs.in @@ -0,0 +1,7 @@ +#sorted +CRYPTO_MSG_NEWALG 0x10 +CRYPTO_MSG_DELALG 0x11 +CRYPTO_MSG_UPDATEALG 0x12 +CRYPTO_MSG_GETALG 0x13 +CRYPTO_MSG_DELRNG 0x14 +CRYPTO_MSG_GETSTAT 0x15