insecure.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* Null security operations.
  3. *
  4. * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #include <net/af_rxrpc.h>
  8. #include "ar-internal.h"
  9. static int none_init_connection_security(struct rxrpc_connection *conn,
  10. struct rxrpc_key_token *token)
  11. {
  12. return 0;
  13. }
  14. /*
  15. * Allocate an appropriately sized buffer for the amount of data remaining.
  16. */
  17. static struct rxrpc_txbuf *none_alloc_txbuf(struct rxrpc_call *call, size_t remain, gfp_t gfp)
  18. {
  19. return rxrpc_alloc_data_txbuf(call, umin(remain, RXRPC_JUMBO_DATALEN), 1, gfp);
  20. }
  21. static int none_secure_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
  22. {
  23. txb->pkt_len = txb->len;
  24. if (txb->len == RXRPC_JUMBO_DATALEN)
  25. txb->jumboable = true;
  26. return 0;
  27. }
  28. static int none_verify_packet(struct rxrpc_call *call, struct sk_buff *skb)
  29. {
  30. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  31. sp->flags |= RXRPC_RX_VERIFIED;
  32. return 0;
  33. }
  34. static void none_free_call_crypto(struct rxrpc_call *call)
  35. {
  36. }
  37. static bool none_validate_challenge(struct rxrpc_connection *conn,
  38. struct sk_buff *skb)
  39. {
  40. rxrpc_abort_conn(conn, skb, RX_PROTOCOL_ERROR, -EPROTO,
  41. rxrpc_eproto_rxnull_challenge);
  42. return true;
  43. }
  44. static int none_sendmsg_respond_to_challenge(struct sk_buff *challenge,
  45. struct msghdr *msg)
  46. {
  47. return -EINVAL;
  48. }
  49. static int none_verify_response(struct rxrpc_connection *conn,
  50. struct sk_buff *skb)
  51. {
  52. return rxrpc_abort_conn(conn, skb, RX_PROTOCOL_ERROR, -EPROTO,
  53. rxrpc_eproto_rxnull_response);
  54. }
  55. static void none_clear(struct rxrpc_connection *conn)
  56. {
  57. }
  58. static int none_init(void)
  59. {
  60. return 0;
  61. }
  62. static void none_exit(void)
  63. {
  64. }
  65. /*
  66. * RxRPC Kerberos-based security
  67. */
  68. const struct rxrpc_security rxrpc_no_security = {
  69. .name = "none",
  70. .security_index = RXRPC_SECURITY_NONE,
  71. .init = none_init,
  72. .exit = none_exit,
  73. .init_connection_security = none_init_connection_security,
  74. .free_call_crypto = none_free_call_crypto,
  75. .alloc_txbuf = none_alloc_txbuf,
  76. .secure_packet = none_secure_packet,
  77. .verify_packet = none_verify_packet,
  78. .validate_challenge = none_validate_challenge,
  79. .sendmsg_respond_to_challenge = none_sendmsg_respond_to_challenge,
  80. .verify_response = none_verify_response,
  81. .clear = none_clear,
  82. };