From cf4013ff48ef3a687ba223450210862e1b2b7a6f Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Wed, 9 Oct 2019 20:07:58 +0200 Subject: [PATCH 62/76] 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 --- configure.ac | 1 + netlink.c | 6 ++- netlink_crypto.c | 125 +++++++++++++++++++++++++++++++++++++++------------- xlat/crypto_msgs.in | 6 +++ 4 files changed, 105 insertions(+), 33 deletions(-) create mode 100644 xlat/crypto_msgs.in Index: strace-5.1/configure.ac =================================================================== --- strace-5.1.orig/configure.ac 2020-01-27 19:35:31.069505931 +0100 +++ strace-5.1/configure.ac 2020-01-29 12:35:51.722702560 +0100 @@ -320,6 +320,7 @@ #include ]) AC_CHECK_TYPES(m4_normalize([ + struct crypto_user_alg, struct crypto_report_aead, struct crypto_report_blkcipher, struct crypto_report_cipher, Index: strace-5.1/netlink.c =================================================================== --- strace-5.1.orig/netlink.c 2018-12-10 01:00:00.000000000 +0100 +++ strace-5.1/netlink.c 2020-01-29 12:35:51.723702551 +0100 @@ -39,6 +39,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. */ @@ -534,9 +538,7 @@ } 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 Index: strace-5.1/netlink_crypto.c =================================================================== --- strace-5.1.orig/netlink_crypto.c 2018-12-25 00:46:43.000000000 +0100 +++ strace-5.1/netlink_crypto.c 2020-01-29 12:35:51.725702535 +0100 @@ -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 @@ 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 @@ PRINT_FIELD_U(", ", rhash, digestsize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -61,8 +142,7 @@ 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 @@ PRINT_FIELD_U(", ", rblkcipher, ivsize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -88,8 +165,7 @@ 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 @@ PRINT_FIELD_U(", ", raead, ivsize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -114,8 +187,7 @@ 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 @@ PRINT_FIELD_U(", ", rrng, seedsize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -137,8 +206,7 @@ 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 @@ PRINT_FIELD_U(", ", rcipher, max_keysize); tprints("}"); } -# else - printstrn(tcp, addr, len); -# endif return true; } @@ -175,7 +240,7 @@ 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 @@ return true; } - -#endif /* HAVE_LINUX_CRYPTOUSER_H */ Index: strace-5.1/xlat/crypto_msgs.in =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ strace-5.1/xlat/crypto_msgs.in 2020-01-29 12:35:51.725702535 +0100 @@ -0,0 +1,6 @@ +CRYPTO_MSG_NEWALG 0x10 +CRYPTO_MSG_DELALG 0x11 +CRYPTO_MSG_UPDATEALG 0x12 +CRYPTO_MSG_GETALG 0x13 +CRYPTO_MSG_DELRNG 0x14 +CRYPTO_MSG_GETSTAT 0x15 Index: strace-5.1/xlat/crypto_msgs.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ strace-5.1/xlat/crypto_msgs.h 2020-01-29 12:36:08.847557616 +0100 @@ -0,0 +1,70 @@ +/* Generated by xlat/gen.sh from xlat/crypto_msgs.in; do not edit. */ + +#include "gcc_compat.h" +#include "static_assert.h" + +#if defined(CRYPTO_MSG_NEWALG) || (defined(HAVE_DECL_CRYPTO_MSG_NEWALG) && HAVE_DECL_CRYPTO_MSG_NEWALG) +DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE +static_assert((CRYPTO_MSG_NEWALG) == (0x10), "CRYPTO_MSG_NEWALG != 0x10"); +DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE +#else +# define CRYPTO_MSG_NEWALG 0x10 +#endif +#if defined(CRYPTO_MSG_DELALG) || (defined(HAVE_DECL_CRYPTO_MSG_DELALG) && HAVE_DECL_CRYPTO_MSG_DELALG) +DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE +static_assert((CRYPTO_MSG_DELALG) == (0x11), "CRYPTO_MSG_DELALG != 0x11"); +DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE +#else +# define CRYPTO_MSG_DELALG 0x11 +#endif +#if defined(CRYPTO_MSG_UPDATEALG) || (defined(HAVE_DECL_CRYPTO_MSG_UPDATEALG) && HAVE_DECL_CRYPTO_MSG_UPDATEALG) +DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE +static_assert((CRYPTO_MSG_UPDATEALG) == (0x12), "CRYPTO_MSG_UPDATEALG != 0x12"); +DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE +#else +# define CRYPTO_MSG_UPDATEALG 0x12 +#endif +#if defined(CRYPTO_MSG_GETALG) || (defined(HAVE_DECL_CRYPTO_MSG_GETALG) && HAVE_DECL_CRYPTO_MSG_GETALG) +DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE +static_assert((CRYPTO_MSG_GETALG) == (0x13), "CRYPTO_MSG_GETALG != 0x13"); +DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE +#else +# define CRYPTO_MSG_GETALG 0x13 +#endif +#if defined(CRYPTO_MSG_DELRNG) || (defined(HAVE_DECL_CRYPTO_MSG_DELRNG) && HAVE_DECL_CRYPTO_MSG_DELRNG) +DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE +static_assert((CRYPTO_MSG_DELRNG) == (0x14), "CRYPTO_MSG_DELRNG != 0x14"); +DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE +#else +# define CRYPTO_MSG_DELRNG 0x14 +#endif +#if defined(CRYPTO_MSG_GETSTAT) || (defined(HAVE_DECL_CRYPTO_MSG_GETSTAT) && HAVE_DECL_CRYPTO_MSG_GETSTAT) +DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE +static_assert((CRYPTO_MSG_GETSTAT) == (0x15), "CRYPTO_MSG_GETSTAT != 0x15"); +DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE +#else +# define CRYPTO_MSG_GETSTAT 0x15 +#endif + +#ifndef XLAT_MACROS_ONLY + +# ifdef IN_MPERS + +# error static const struct xlat crypto_msgs in mpers mode + +# else + +static +const struct xlat crypto_msgs[] = { + XLAT(CRYPTO_MSG_NEWALG), + XLAT(CRYPTO_MSG_DELALG), + XLAT(CRYPTO_MSG_UPDATEALG), + XLAT(CRYPTO_MSG_GETALG), + XLAT(CRYPTO_MSG_DELRNG), + XLAT(CRYPTO_MSG_GETSTAT), + XLAT_END +}; + +# endif /* !IN_MPERS */ + +#endif /* !XLAT_MACROS_ONLY */