Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

netlink_crypto.c 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
  3. * Copyright (c) 2017-2020 The strace developers.
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: LGPL-2.1-or-later
  7. */
  8. #include "defs.h"
  9. #include "netlink.h"
  10. #include "nlattr.h"
  11. #include "print_fields.h"
  12. #include "types/cryptouser.h"
  13. #include "xlat/crypto_nl_attrs.h"
  14. #define XLAT_MACROS_ONLY
  15. # include "xlat/crypto_msgs.h"
  16. #undef XLAT_MACROS_ONLY
  17. static bool
  18. decode_crypto_report_generic(struct tcb *const tcp,
  19. const kernel_ulong_t addr,
  20. const unsigned int len,
  21. const void *const opaque_data)
  22. {
  23. tprints("{type=");
  24. printstr_ex(tcp, addr, len, QUOTE_0_TERMINATED);
  25. tprints("}");
  26. return true;
  27. }
  28. static bool
  29. decode_crypto_report_hash(struct tcb *const tcp,
  30. const kernel_ulong_t addr,
  31. const unsigned int len,
  32. const void *const opaque_data)
  33. {
  34. struct_crypto_report_hash rhash;
  35. if (len < sizeof(rhash))
  36. printstrn(tcp, addr, len);
  37. else if (!umove_or_printaddr(tcp, addr, &rhash)) {
  38. PRINT_FIELD_CSTRING("{", rhash, type);
  39. PRINT_FIELD_U(", ", rhash, blocksize);
  40. PRINT_FIELD_U(", ", rhash, digestsize);
  41. tprints("}");
  42. }
  43. return true;
  44. }
  45. static bool
  46. decode_crypto_report_blkcipher(struct tcb *const tcp,
  47. const kernel_ulong_t addr,
  48. const unsigned int len,
  49. const void *const opaque_data)
  50. {
  51. struct_crypto_report_blkcipher rblkcipher;
  52. if (len < sizeof(rblkcipher))
  53. printstrn(tcp, addr, len);
  54. else if (!umove_or_printaddr(tcp, addr, &rblkcipher)) {
  55. PRINT_FIELD_CSTRING("{", rblkcipher, type);
  56. PRINT_FIELD_CSTRING(", ", rblkcipher, geniv);
  57. PRINT_FIELD_U(", ", rblkcipher, blocksize);
  58. PRINT_FIELD_U(", ", rblkcipher, min_keysize);
  59. PRINT_FIELD_U(", ", rblkcipher, max_keysize);
  60. PRINT_FIELD_U(", ", rblkcipher, ivsize);
  61. tprints("}");
  62. }
  63. return true;
  64. }
  65. static bool
  66. decode_crypto_report_aead(struct tcb *const tcp,
  67. const kernel_ulong_t addr,
  68. const unsigned int len,
  69. const void *const opaque_data)
  70. {
  71. struct_crypto_report_aead raead;
  72. if (len < sizeof(raead))
  73. printstrn(tcp, addr, len);
  74. else if (!umove_or_printaddr(tcp, addr, &raead)) {
  75. PRINT_FIELD_CSTRING("{", raead, type);
  76. PRINT_FIELD_CSTRING(", ", raead, geniv);
  77. PRINT_FIELD_U(", ", raead, blocksize);
  78. PRINT_FIELD_U(", ", raead, maxauthsize);
  79. PRINT_FIELD_U(", ", raead, ivsize);
  80. tprints("}");
  81. }
  82. return true;
  83. }
  84. static bool
  85. decode_crypto_report_rng(struct tcb *const tcp,
  86. const kernel_ulong_t addr,
  87. const unsigned int len,
  88. const void *const opaque_data)
  89. {
  90. struct_crypto_report_rng rrng;
  91. if (len < sizeof(rrng))
  92. printstrn(tcp, addr, len);
  93. else if (!umove_or_printaddr(tcp, addr, &rrng)) {
  94. PRINT_FIELD_CSTRING("{", rrng, type);
  95. PRINT_FIELD_U(", ", rrng, seedsize);
  96. tprints("}");
  97. }
  98. return true;
  99. }
  100. static bool
  101. decode_crypto_report_cipher(struct tcb *const tcp,
  102. const kernel_ulong_t addr,
  103. const unsigned int len,
  104. const void *const opaque_data)
  105. {
  106. struct_crypto_report_cipher rcipher;
  107. if (len < sizeof(rcipher))
  108. printstrn(tcp, addr, len);
  109. else if (!umove_or_printaddr(tcp, addr, &rcipher)) {
  110. PRINT_FIELD_CSTRING("{", rcipher, type);
  111. PRINT_FIELD_U(", ", rcipher, blocksize);
  112. PRINT_FIELD_U(", ", rcipher, min_keysize);
  113. PRINT_FIELD_U(", ", rcipher, max_keysize);
  114. tprints("}");
  115. }
  116. return true;
  117. }
  118. static const nla_decoder_t crypto_user_alg_nla_decoders[] = {
  119. [CRYPTOCFGA_PRIORITY_VAL] = decode_nla_u32,
  120. [CRYPTOCFGA_REPORT_LARVAL] = decode_crypto_report_generic,
  121. [CRYPTOCFGA_REPORT_HASH] = decode_crypto_report_hash,
  122. [CRYPTOCFGA_REPORT_BLKCIPHER] = decode_crypto_report_blkcipher,
  123. [CRYPTOCFGA_REPORT_AEAD] = decode_crypto_report_aead,
  124. [CRYPTOCFGA_REPORT_COMPRESS] = decode_crypto_report_generic,
  125. [CRYPTOCFGA_REPORT_RNG] = decode_crypto_report_rng,
  126. [CRYPTOCFGA_REPORT_CIPHER] = decode_crypto_report_cipher,
  127. [CRYPTOCFGA_REPORT_AKCIPHER] = decode_crypto_report_generic,
  128. [CRYPTOCFGA_REPORT_KPP] = decode_crypto_report_generic,
  129. [CRYPTOCFGA_REPORT_ACOMP] = decode_crypto_report_generic
  130. };
  131. static void
  132. decode_crypto_user_alg(struct tcb *const tcp,
  133. const kernel_ulong_t addr,
  134. const unsigned int len)
  135. {
  136. struct_crypto_user_alg alg;
  137. if (len < sizeof(alg))
  138. printstrn(tcp, addr, len);
  139. else if (!umove_or_printaddr(tcp, addr, &alg)) {
  140. PRINT_FIELD_CSTRING("{", alg, cru_name);
  141. PRINT_FIELD_CSTRING(", ", alg, cru_driver_name);
  142. PRINT_FIELD_CSTRING(", ", alg, cru_module_name);
  143. PRINT_FIELD_X(", ", alg, cru_type);
  144. PRINT_FIELD_X(", ", alg, cru_mask);
  145. PRINT_FIELD_U(", ", alg, cru_refcnt);
  146. PRINT_FIELD_X(", ", alg, cru_flags);
  147. tprints("}");
  148. const size_t offset = NLMSG_ALIGN(sizeof(alg));
  149. if (len > offset) {
  150. tprints(", ");
  151. decode_nlattr(tcp, addr + offset, len - offset,
  152. crypto_nl_attrs, "CRYPTOCFGA_???",
  153. crypto_user_alg_nla_decoders,
  154. ARRAY_SIZE(crypto_user_alg_nla_decoders),
  155. NULL);
  156. }
  157. }
  158. }
  159. bool
  160. decode_netlink_crypto(struct tcb *const tcp,
  161. const struct nlmsghdr *const nlmsghdr,
  162. const kernel_ulong_t addr,
  163. const unsigned int len)
  164. {
  165. switch (nlmsghdr->nlmsg_type) {
  166. case CRYPTO_MSG_NEWALG:
  167. case CRYPTO_MSG_DELALG:
  168. case CRYPTO_MSG_UPDATEALG:
  169. case CRYPTO_MSG_GETALG:
  170. decode_crypto_user_alg(tcp, addr, len);
  171. break;
  172. default:
  173. return false;
  174. }
  175. return true;
  176. }