Blame SOURCES/0062-Enable-building-of-netlink_crypto-decoder-without-li.patch

86f512
From cf4013ff48ef3a687ba223450210862e1b2b7a6f Mon Sep 17 00:00:00 2001
86f512
From: Eugene Syromyatnikov <evgsyr@gmail.com>
86f512
Date: Wed, 9 Oct 2019 20:07:58 +0200
86f512
Subject: [PATCH 62/76] Enable building of netlink_crypto decoder without
86f512
 linux/cryptouser.h
86f512
86f512
* xlat/crypto_msgs.in: New file.
86f512
* configure.ac (AC_CHECK_TYPES): Check for struct crypto_user_alg.
86f512
* netlink.c: Include "xlat/crypto_msgs.h" with XLAT_MACROS_ONLY defined.
86f512
(netlink_decoders[]): Remove HAVE_LINUX_CRYPTOUSER_H guard around
86f512
[NETLINK_CRYPTO] item.
86f512
* netlink_crypto.c: Remove HAVE_LINUX_CRYPTOUSER_H guard; include
86f512
<linux/cryptouser.h> under HAVE_LINUX_CRYPTOUSER_H; include
86f512
"xlat/crypto_msgs.h" with XLAT_MACROS_ONLY defined.
86f512
[!CRYPTO_MAX_NAME] (CRYPTO_MAX_NAME): New macro.
86f512
(struct_crypto_user_alg, struct_crypto_report_hash,
86f512
struct_crypto_report_cipher, struct_crypto_report_blkcipher,
86f512
struct_crypto_report_aead, struct_crypto_report_rng): New typedefs.
86f512
[HAVE_STRUCT_CRYPTO_USER_ALG]: New static_assert to check
86f512
that sizeof(struct crypto_user_alg) has the expected value.
86f512
[HAVE_STRUCT_CRYPTO_REPORT_HASH]: New static_assert to check
86f512
that sizeof(struct crypto_report_hash) has the expected value.
86f512
[HAVE_STRUCT_CRYPTO_REPORT_CIPHER]: New static_assert to check
86f512
that sizeof(struct crypto_report_cipher) has the expected value.
86f512
[HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER]: New static_assert to check
86f512
that sizeof(struct crypto_report_blkcipher) has the expected value.
86f512
[HAVE_STRUCT_CRYPTO_REPORT_AEAD]: New static_assert to check
86f512
that sizeof(struct crypto_report_aead) has the expected value.
86f512
[HAVE_STRUCT_CRYPTO_REPORT_RNG]: New static_assert to check
86f512
that sizeof(struct crypto_report_rng) has the expected value.
86f512
(decode_crypto_report_hash) [!HAVE_STRUCT_CRYPTO_REPORT_HASH]: Remove.
86f512
(decode_crypto_report_hash): Change type of rhash to
86f512
struct_crypto_report_hash.
86f512
(decode_crypto_report_blkcipher) [!HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER]:
86f512
Remove.
86f512
(decode_crypto_report_blkcipher): Change type of rblkcipher to
86f512
struct_crypto_report_blkcipher.
86f512
(decode_crypto_report_aead) [!HAVE_STRUCT_CRYPTO_REPORT_AEAD]: Remove.
86f512
(decode_crypto_report_aead): Change type of raead to
86f512
struct_crypto_report_aead.
86f512
(decode_crypto_report_rng) [!HAVE_STRUCT_CRYPTO_REPORT_RNG]: Remove.
86f512
(decode_crypto_report_rng): Change type of rrng to
86f512
struct_crypto_report_rng.
86f512
(decode_crypto_report_cipher) [!HAVE_STRUCT_CRYPTO_REPORT_CIPHER]:
86f512
Remove.
86f512
(decode_crypto_report_cipher): Change type of rcipher to
86f512
struct_crypto_report_cipher.
86f512
(decode_crypto_user_alg): Change type of alg to struct_crypto_user_alg.
86f512
86f512
References: https://bugzilla.redhat.com/show_bug.cgi?id=1758201
86f512
---
86f512
 configure.ac        |   1 +
86f512
 netlink.c           |   6 ++-
86f512
 netlink_crypto.c    | 125 +++++++++++++++++++++++++++++++++++++++-------------
86f512
 xlat/crypto_msgs.in |   6 +++
86f512
 4 files changed, 105 insertions(+), 33 deletions(-)
86f512
 create mode 100644 xlat/crypto_msgs.in
86f512
86f512
Index: strace-5.1/configure.ac
86f512
===================================================================
86f512
--- strace-5.1.orig/configure.ac	2020-01-27 19:35:31.069505931 +0100
86f512
+++ strace-5.1/configure.ac	2020-01-29 12:35:51.722702560 +0100
86f512
@@ -320,6 +320,7 @@
86f512
 #include <linux/fcntl.h>])
86f512
 
86f512
 AC_CHECK_TYPES(m4_normalize([
86f512
+	struct crypto_user_alg,
86f512
 	struct crypto_report_aead,
86f512
 	struct crypto_report_blkcipher,
86f512
 	struct crypto_report_cipher,
86f512
Index: strace-5.1/netlink.c
86f512
===================================================================
86f512
--- strace-5.1.orig/netlink.c	2018-12-10 01:00:00.000000000 +0100
86f512
+++ strace-5.1/netlink.c	2020-01-29 12:35:51.723702551 +0100
86f512
@@ -39,6 +39,10 @@
86f512
 #include "xlat/nl_xfrm_types.h"
86f512
 #include "xlat/nlmsgerr_attrs.h"
86f512
 
86f512
+# define XLAT_MACROS_ONLY
86f512
+#  include "xlat/crypto_msgs.h"
86f512
+# undef XLAT_MACROS_ONLY
86f512
+
86f512
 /*
86f512
  * Fetch a struct nlmsghdr from the given address.
86f512
  */
86f512
@@ -534,9 +538,7 @@
86f512
 }
86f512
 
86f512
 static const netlink_decoder_t netlink_decoders[] = {
86f512
-#ifdef HAVE_LINUX_CRYPTOUSER_H
86f512
 	[NETLINK_CRYPTO] = decode_netlink_crypto,
86f512
-#endif
86f512
 #ifdef HAVE_LINUX_NETFILTER_NFNETLINK_H
86f512
 	[NETLINK_NETFILTER] = decode_netlink_netfilter,
86f512
 #endif
86f512
Index: strace-5.1/netlink_crypto.c
86f512
===================================================================
86f512
--- strace-5.1.orig/netlink_crypto.c	2018-12-25 00:46:43.000000000 +0100
86f512
+++ strace-5.1/netlink_crypto.c	2020-01-29 12:35:51.725702535 +0100
86f512
@@ -8,16 +8,101 @@
86f512
 
86f512
 #include "defs.h"
86f512
 
86f512
-#ifdef HAVE_LINUX_CRYPTOUSER_H
86f512
-
86f512
 # include "netlink.h"
86f512
 # include "nlattr.h"
86f512
 # include "print_fields.h"
86f512
 
86f512
-# include <linux/cryptouser.h>
86f512
+# if HAVE_LINUX_CRYPTOUSER_H
86f512
+#  include <linux/cryptouser.h>
86f512
+# endif
86f512
 
86f512
 # include "xlat/crypto_nl_attrs.h"
86f512
 
86f512
+# define XLAT_MACROS_ONLY
86f512
+#  include "xlat/crypto_msgs.h"
86f512
+# undef XLAT_MACROS_ONLY
86f512
+
86f512
+
86f512
+# ifndef CRYPTO_MAX_NAME
86f512
+#  define CRYPTO_MAX_NAME 64
86f512
+# endif
86f512
+
86f512
+typedef struct {
86f512
+	char cru_name[CRYPTO_MAX_NAME];
86f512
+	char cru_driver_name[CRYPTO_MAX_NAME];
86f512
+	char cru_module_name[CRYPTO_MAX_NAME];
86f512
+	uint32_t cru_type;
86f512
+	uint32_t cru_mask;
86f512
+	uint32_t cru_refcnt;
86f512
+	uint32_t cru_flags;
86f512
+} struct_crypto_user_alg;
86f512
+
86f512
+typedef struct {
86f512
+	char type[CRYPTO_MAX_NAME];
86f512
+	uint32_t blocksize;
86f512
+	uint32_t digestsize;
86f512
+} struct_crypto_report_hash;
86f512
+
86f512
+typedef struct {
86f512
+	char type[CRYPTO_MAX_NAME];
86f512
+	uint32_t blocksize;
86f512
+	uint32_t min_keysize;
86f512
+	uint32_t max_keysize;
86f512
+} struct_crypto_report_cipher;
86f512
+
86f512
+typedef struct {
86f512
+	char type[CRYPTO_MAX_NAME];
86f512
+	char geniv[CRYPTO_MAX_NAME];
86f512
+	uint32_t blocksize;
86f512
+	uint32_t min_keysize;
86f512
+	uint32_t max_keysize;
86f512
+	uint32_t ivsize;
86f512
+} struct_crypto_report_blkcipher;
86f512
+
86f512
+typedef struct {
86f512
+	char type[CRYPTO_MAX_NAME];
86f512
+	char geniv[CRYPTO_MAX_NAME];
86f512
+	uint32_t blocksize;
86f512
+	uint32_t maxauthsize;
86f512
+	uint32_t ivsize;
86f512
+} struct_crypto_report_aead;
86f512
+
86f512
+typedef struct {
86f512
+	char type[CRYPTO_MAX_NAME];
86f512
+	uint32_t seedsize;
86f512
+} struct_crypto_report_rng;
86f512
+
86f512
+# ifdef HAVE_STRUCT_CRYPTO_USER_ALG
86f512
+static_assert(sizeof(struct_crypto_user_alg) == sizeof(struct crypto_user_alg),
86f512
+	      "struct crypto_user_alg mismatch, please update the decoder");
86f512
+# endif
86f512
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_HASH
86f512
+static_assert(sizeof(struct_crypto_report_hash)
86f512
+	      == sizeof(struct crypto_report_hash),
86f512
+	      "struct crypto_report_hash mismatch, please update the decoder");
86f512
+# endif
86f512
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_CIPHER
86f512
+static_assert(sizeof(struct_crypto_report_cipher)
86f512
+	      == sizeof(struct crypto_report_cipher),
86f512
+	      "struct crypto_report_cipher mismatch, please update the decoder");
86f512
+# endif
86f512
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER
86f512
+static_assert(sizeof(struct_crypto_report_blkcipher)
86f512
+	      == sizeof(struct crypto_report_blkcipher),
86f512
+	      "struct crypto_report_blkcipher mismatch, please update the decoder");
86f512
+# endif
86f512
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_AEAD
86f512
+static_assert(sizeof(struct_crypto_report_aead)
86f512
+	      == sizeof(struct crypto_report_aead),
86f512
+	      "struct crypto_report_aead mismatch, please update the decoder");
86f512
+# endif
86f512
+# ifdef HAVE_STRUCT_CRYPTO_REPORT_RNG
86f512
+static_assert(sizeof(struct_crypto_report_rng)
86f512
+	      == sizeof(struct crypto_report_rng),
86f512
+	      "struct crypto_report_rng mismatch, please update the decoder");
86f512
+# endif
86f512
+
86f512
+
86f512
 static bool
86f512
 decode_crypto_report_generic(struct tcb *const tcp,
86f512
 			     const kernel_ulong_t addr,
86f512
@@ -37,8 +122,7 @@
86f512
 			  const unsigned int len,
86f512
 			  const void *const opaque_data)
86f512
 {
86f512
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_HASH
86f512
-	struct crypto_report_hash rhash;
86f512
+	struct_crypto_report_hash rhash;
86f512
 
86f512
 	if (len < sizeof(rhash))
86f512
 		printstrn(tcp, addr, len);
86f512
@@ -48,9 +132,6 @@
86f512
 		PRINT_FIELD_U(", ", rhash, digestsize);
86f512
 		tprints("}");
86f512
 	}
86f512
-# else
86f512
-	printstrn(tcp, addr, len);
86f512
-# endif
86f512
 
86f512
 	return true;
86f512
 }
86f512
@@ -61,8 +142,7 @@
86f512
 			       const unsigned int len,
86f512
 			       const void *const opaque_data)
86f512
 {
86f512
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_BLKCIPHER
86f512
-	struct crypto_report_blkcipher rblkcipher;
86f512
+	struct_crypto_report_blkcipher rblkcipher;
86f512
 
86f512
 	if (len < sizeof(rblkcipher))
86f512
 		printstrn(tcp, addr, len);
86f512
@@ -75,9 +155,6 @@
86f512
 		PRINT_FIELD_U(", ", rblkcipher, ivsize);
86f512
 		tprints("}");
86f512
 	}
86f512
-# else
86f512
-	printstrn(tcp, addr, len);
86f512
-# endif
86f512
 
86f512
 	return true;
86f512
 }
86f512
@@ -88,8 +165,7 @@
86f512
 			  const unsigned int len,
86f512
 			  const void *const opaque_data)
86f512
 {
86f512
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_AEAD
86f512
-	struct crypto_report_aead raead;
86f512
+	struct_crypto_report_aead raead;
86f512
 
86f512
 	if (len < sizeof(raead))
86f512
 		printstrn(tcp, addr, len);
86f512
@@ -101,9 +177,6 @@
86f512
 		PRINT_FIELD_U(", ", raead, ivsize);
86f512
 		tprints("}");
86f512
 	}
86f512
-# else
86f512
-	printstrn(tcp, addr, len);
86f512
-# endif
86f512
 
86f512
 	return true;
86f512
 }
86f512
@@ -114,8 +187,7 @@
86f512
 			 const unsigned int len,
86f512
 			 const void *const opaque_data)
86f512
 {
86f512
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_RNG
86f512
-	struct crypto_report_rng rrng;
86f512
+	struct_crypto_report_rng rrng;
86f512
 
86f512
 	if (len < sizeof(rrng))
86f512
 		printstrn(tcp, addr, len);
86f512
@@ -124,9 +196,6 @@
86f512
 		PRINT_FIELD_U(", ", rrng, seedsize);
86f512
 		tprints("}");
86f512
 	}
86f512
-# else
86f512
-	printstrn(tcp, addr, len);
86f512
-# endif
86f512
 
86f512
 	return true;
86f512
 }
86f512
@@ -137,8 +206,7 @@
86f512
 			    const unsigned int len,
86f512
 			    const void *const opaque_data)
86f512
 {
86f512
-# ifdef HAVE_STRUCT_CRYPTO_REPORT_CIPHER
86f512
-	struct crypto_report_cipher rcipher;
86f512
+	struct_crypto_report_cipher rcipher;
86f512
 
86f512
 	if (len < sizeof(rcipher))
86f512
 		printstrn(tcp, addr, len);
86f512
@@ -149,9 +217,6 @@
86f512
 		PRINT_FIELD_U(", ", rcipher, max_keysize);
86f512
 		tprints("}");
86f512
 	}
86f512
-# else
86f512
-	printstrn(tcp, addr, len);
86f512
-# endif
86f512
 
86f512
 	return true;
86f512
 }
86f512
@@ -175,7 +240,7 @@
86f512
 		       const kernel_ulong_t addr,
86f512
 		       const unsigned int len)
86f512
 {
86f512
-	struct crypto_user_alg alg;
86f512
+	struct_crypto_user_alg alg;
86f512
 
86f512
 	if (len < sizeof(alg))
86f512
 		printstrn(tcp, addr, len);
86f512
@@ -220,5 +285,3 @@
86f512
 
86f512
 	return true;
86f512
 }
86f512
-
86f512
-#endif /* HAVE_LINUX_CRYPTOUSER_H */
86f512
Index: strace-5.1/xlat/crypto_msgs.in
86f512
===================================================================
86f512
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
86f512
+++ strace-5.1/xlat/crypto_msgs.in	2020-01-29 12:35:51.725702535 +0100
86f512
@@ -0,0 +1,6 @@
86f512
+CRYPTO_MSG_NEWALG	0x10
86f512
+CRYPTO_MSG_DELALG	0x11
86f512
+CRYPTO_MSG_UPDATEALG	0x12
86f512
+CRYPTO_MSG_GETALG	0x13
86f512
+CRYPTO_MSG_DELRNG	0x14
86f512
+CRYPTO_MSG_GETSTAT	0x15
86f512
Index: strace-5.1/xlat/crypto_msgs.h
86f512
===================================================================
86f512
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
86f512
+++ strace-5.1/xlat/crypto_msgs.h	2020-01-29 12:36:08.847557616 +0100
86f512
@@ -0,0 +1,70 @@
86f512
+/* Generated by xlat/gen.sh from xlat/crypto_msgs.in; do not edit. */
86f512
+
86f512
+#include "gcc_compat.h"
86f512
+#include "static_assert.h"
86f512
+
86f512
+#if defined(CRYPTO_MSG_NEWALG) || (defined(HAVE_DECL_CRYPTO_MSG_NEWALG) && HAVE_DECL_CRYPTO_MSG_NEWALG)
86f512
+DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+static_assert((CRYPTO_MSG_NEWALG) == (0x10), "CRYPTO_MSG_NEWALG != 0x10");
86f512
+DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+#else
86f512
+# define CRYPTO_MSG_NEWALG 0x10
86f512
+#endif
86f512
+#if defined(CRYPTO_MSG_DELALG) || (defined(HAVE_DECL_CRYPTO_MSG_DELALG) && HAVE_DECL_CRYPTO_MSG_DELALG)
86f512
+DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+static_assert((CRYPTO_MSG_DELALG) == (0x11), "CRYPTO_MSG_DELALG != 0x11");
86f512
+DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+#else
86f512
+# define CRYPTO_MSG_DELALG 0x11
86f512
+#endif
86f512
+#if defined(CRYPTO_MSG_UPDATEALG) || (defined(HAVE_DECL_CRYPTO_MSG_UPDATEALG) && HAVE_DECL_CRYPTO_MSG_UPDATEALG)
86f512
+DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+static_assert((CRYPTO_MSG_UPDATEALG) == (0x12), "CRYPTO_MSG_UPDATEALG != 0x12");
86f512
+DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+#else
86f512
+# define CRYPTO_MSG_UPDATEALG 0x12
86f512
+#endif
86f512
+#if defined(CRYPTO_MSG_GETALG) || (defined(HAVE_DECL_CRYPTO_MSG_GETALG) && HAVE_DECL_CRYPTO_MSG_GETALG)
86f512
+DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+static_assert((CRYPTO_MSG_GETALG) == (0x13), "CRYPTO_MSG_GETALG != 0x13");
86f512
+DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+#else
86f512
+# define CRYPTO_MSG_GETALG 0x13
86f512
+#endif
86f512
+#if defined(CRYPTO_MSG_DELRNG) || (defined(HAVE_DECL_CRYPTO_MSG_DELRNG) && HAVE_DECL_CRYPTO_MSG_DELRNG)
86f512
+DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+static_assert((CRYPTO_MSG_DELRNG) == (0x14), "CRYPTO_MSG_DELRNG != 0x14");
86f512
+DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+#else
86f512
+# define CRYPTO_MSG_DELRNG 0x14
86f512
+#endif
86f512
+#if defined(CRYPTO_MSG_GETSTAT) || (defined(HAVE_DECL_CRYPTO_MSG_GETSTAT) && HAVE_DECL_CRYPTO_MSG_GETSTAT)
86f512
+DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+static_assert((CRYPTO_MSG_GETSTAT) == (0x15), "CRYPTO_MSG_GETSTAT != 0x15");
86f512
+DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
86f512
+#else
86f512
+# define CRYPTO_MSG_GETSTAT 0x15
86f512
+#endif
86f512
+
86f512
+#ifndef XLAT_MACROS_ONLY
86f512
+
86f512
+# ifdef IN_MPERS
86f512
+
86f512
+#  error static const struct xlat crypto_msgs in mpers mode
86f512
+
86f512
+# else
86f512
+
86f512
+static
86f512
+const struct xlat crypto_msgs[] = {
86f512
+ XLAT(CRYPTO_MSG_NEWALG),
86f512
+ XLAT(CRYPTO_MSG_DELALG),
86f512
+ XLAT(CRYPTO_MSG_UPDATEALG),
86f512
+ XLAT(CRYPTO_MSG_GETALG),
86f512
+ XLAT(CRYPTO_MSG_DELRNG),
86f512
+ XLAT(CRYPTO_MSG_GETSTAT),
86f512
+ XLAT_END
86f512
+};
86f512
+
86f512
+# endif /* !IN_MPERS */
86f512
+
86f512
+#endif /* !XLAT_MACROS_ONLY */