Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rxrpc: Tidy up abort generation infrastructure

Tidy up the abort generation infrastructure in the following ways:

(1) Create an enum and string mapping table to list the reasons an abort
might be generated in tracing.

(2) Replace the 3-char string with the values from (1) in the places that
use that to log the abort source. This gets rid of a memcpy() in the
tracepoint.

(3) Subsume the rxrpc_rx_eproto tracepoint with the rxrpc_abort tracepoint
and use values from (1) to indicate the trace reason.

(4) Always make a call to an abort function at the point of the abort
rather than stashing the values into variables and using goto to get
to a place where it reported. The C optimiser will collapse the calls
together as appropriate. The abort functions return a value that can
be returned directly if appropriate.

Note that this extends into afs also at the points where that generates an
abort. To aid with this, the afs sources need to #define
RXRPC_TRACE_ONLY_DEFINE_ENUMS before including the rxrpc tracing header
because they don't have access to the rxrpc internal structures that some
of the tracepoints make use of.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org

+484 -444
+4 -2
fs/afs/cmservice.c
··· 13 13 #include "internal.h" 14 14 #include "afs_cm.h" 15 15 #include "protocol_yfs.h" 16 + #define RXRPC_TRACE_ONLY_DEFINE_ENUMS 17 + #include <trace/events/rxrpc.h> 16 18 17 19 static int afs_deliver_cb_init_call_back_state(struct afs_call *); 18 20 static int afs_deliver_cb_init_call_back_state3(struct afs_call *); ··· 193 191 * Abort a service call from within an action function. 194 192 */ 195 193 static void afs_abort_service_call(struct afs_call *call, u32 abort_code, int error, 196 - const char *why) 194 + enum rxrpc_abort_reason why) 197 195 { 198 196 rxrpc_kernel_abort_call(call->net->socket, call->rxcall, 199 197 abort_code, error, why); ··· 471 469 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0) 472 470 afs_send_empty_reply(call); 473 471 else 474 - afs_abort_service_call(call, 1, 1, "K-1"); 472 + afs_abort_service_call(call, 1, 1, afs_abort_probeuuid_negative); 475 473 476 474 afs_put_call(call); 477 475 _leave("");
+16 -7
fs/afs/rxrpc.c
··· 13 13 #include "internal.h" 14 14 #include "afs_cm.h" 15 15 #include "protocol_yfs.h" 16 + #define RXRPC_TRACE_ONLY_DEFINE_ENUMS 17 + #include <trace/events/rxrpc.h> 16 18 17 19 struct workqueue_struct *afs_async_calls; 18 20 ··· 399 397 error_do_abort: 400 398 if (ret != -ECONNABORTED) { 401 399 rxrpc_kernel_abort_call(call->net->socket, rxcall, 402 - RX_USER_ABORT, ret, "KSD"); 400 + RX_USER_ABORT, ret, 401 + afs_abort_send_data_error); 403 402 } else { 404 403 len = 0; 405 404 iov_iter_kvec(&msg.msg_iter, ITER_DEST, NULL, 0, 0); ··· 530 527 case -ENOTSUPP: 531 528 abort_code = RXGEN_OPCODE; 532 529 rxrpc_kernel_abort_call(call->net->socket, call->rxcall, 533 - abort_code, ret, "KIV"); 530 + abort_code, ret, 531 + afs_abort_op_not_supported); 534 532 goto local_abort; 535 533 case -EIO: 536 534 pr_err("kAFS: Call %u in bad state %u\n", ··· 546 542 if (state != AFS_CALL_CL_AWAIT_REPLY) 547 543 abort_code = RXGEN_SS_UNMARSHAL; 548 544 rxrpc_kernel_abort_call(call->net->socket, call->rxcall, 549 - abort_code, ret, "KUM"); 545 + abort_code, ret, 546 + afs_abort_unmarshal_error); 550 547 goto local_abort; 551 548 default: 552 549 abort_code = RX_CALL_DEAD; 553 550 rxrpc_kernel_abort_call(call->net->socket, call->rxcall, 554 - abort_code, ret, "KER"); 551 + abort_code, ret, 552 + afs_abort_general_error); 555 553 goto local_abort; 556 554 } 557 555 } ··· 625 619 /* Kill off the call if it's still live. */ 626 620 _debug("call interrupted"); 627 621 if (rxrpc_kernel_abort_call(call->net->socket, call->rxcall, 628 - RX_USER_ABORT, -EINTR, "KWI")) 622 + RX_USER_ABORT, -EINTR, 623 + afs_abort_interrupted)) 629 624 afs_set_call_complete(call, -EINTR, 0); 630 625 } 631 626 } ··· 843 836 case -ENOMEM: 844 837 _debug("oom"); 845 838 rxrpc_kernel_abort_call(net->socket, call->rxcall, 846 - RXGEN_SS_MARSHAL, -ENOMEM, "KOO"); 839 + RXGEN_SS_MARSHAL, -ENOMEM, 840 + afs_abort_oom); 847 841 fallthrough; 848 842 default: 849 843 _leave(" [error]"); ··· 886 878 if (n == -ENOMEM) { 887 879 _debug("oom"); 888 880 rxrpc_kernel_abort_call(net->socket, call->rxcall, 889 - RXGEN_SS_MARSHAL, -ENOMEM, "KOO"); 881 + RXGEN_SS_MARSHAL, -ENOMEM, 882 + afs_abort_oom); 890 883 } 891 884 _leave(" [error]"); 892 885 }
+2 -1
include/net/af_rxrpc.h
··· 15 15 struct sock; 16 16 struct socket; 17 17 struct rxrpc_call; 18 + enum rxrpc_abort_reason; 18 19 19 20 enum rxrpc_interruptibility { 20 21 RXRPC_INTERRUPTIBLE, /* Call is interruptible */ ··· 56 55 int rxrpc_kernel_recv_data(struct socket *, struct rxrpc_call *, 57 56 struct iov_iter *, size_t *, bool, u32 *, u16 *); 58 57 bool rxrpc_kernel_abort_call(struct socket *, struct rxrpc_call *, 59 - u32, int, const char *); 58 + u32, int, enum rxrpc_abort_reason); 60 59 void rxrpc_kernel_end_call(struct socket *, struct rxrpc_call *); 61 60 void rxrpc_kernel_get_peer(struct socket *, struct rxrpc_call *, 62 61 struct sockaddr_rxrpc *);
+111 -29
include/trace/events/rxrpc.h
··· 16 16 /* 17 17 * Declare tracing information enums and their string mappings for display. 18 18 */ 19 + #define rxrpc_abort_reasons \ 20 + /* AFS errors */ \ 21 + EM(afs_abort_general_error, "afs-error") \ 22 + EM(afs_abort_interrupted, "afs-intr") \ 23 + EM(afs_abort_oom, "afs-oom") \ 24 + EM(afs_abort_op_not_supported, "afs-op-notsupp") \ 25 + EM(afs_abort_probeuuid_negative, "afs-probeuuid-neg") \ 26 + EM(afs_abort_send_data_error, "afs-send-data") \ 27 + EM(afs_abort_unmarshal_error, "afs-unmarshal") \ 28 + /* rxperf errors */ \ 29 + EM(rxperf_abort_general_error, "rxperf-error") \ 30 + EM(rxperf_abort_oom, "rxperf-oom") \ 31 + EM(rxperf_abort_op_not_supported, "rxperf-op-notsupp") \ 32 + EM(rxperf_abort_unmarshal_error, "rxperf-unmarshal") \ 33 + /* RxKAD security errors */ \ 34 + EM(rxkad_abort_1_short_check, "rxkad1-short-check") \ 35 + EM(rxkad_abort_1_short_data, "rxkad1-short-data") \ 36 + EM(rxkad_abort_1_short_encdata, "rxkad1-short-encdata") \ 37 + EM(rxkad_abort_1_short_header, "rxkad1-short-hdr") \ 38 + EM(rxkad_abort_2_short_check, "rxkad2-short-check") \ 39 + EM(rxkad_abort_2_short_data, "rxkad2-short-data") \ 40 + EM(rxkad_abort_2_short_header, "rxkad2-short-hdr") \ 41 + EM(rxkad_abort_2_short_len, "rxkad2-short-len") \ 42 + EM(rxkad_abort_bad_checksum, "rxkad2-bad-cksum") \ 43 + EM(rxkad_abort_chall_key_expired, "rxkad-chall-key-exp") \ 44 + EM(rxkad_abort_chall_level, "rxkad-chall-level") \ 45 + EM(rxkad_abort_chall_no_key, "rxkad-chall-nokey") \ 46 + EM(rxkad_abort_chall_short, "rxkad-chall-short") \ 47 + EM(rxkad_abort_chall_version, "rxkad-chall-version") \ 48 + EM(rxkad_abort_resp_bad_callid, "rxkad-resp-bad-callid") \ 49 + EM(rxkad_abort_resp_bad_checksum, "rxkad-resp-bad-cksum") \ 50 + EM(rxkad_abort_resp_bad_param, "rxkad-resp-bad-param") \ 51 + EM(rxkad_abort_resp_call_ctr, "rxkad-resp-call-ctr") \ 52 + EM(rxkad_abort_resp_call_state, "rxkad-resp-call-state") \ 53 + EM(rxkad_abort_resp_key_expired, "rxkad-resp-key-exp") \ 54 + EM(rxkad_abort_resp_key_rejected, "rxkad-resp-key-rej") \ 55 + EM(rxkad_abort_resp_level, "rxkad-resp-level") \ 56 + EM(rxkad_abort_resp_nokey, "rxkad-resp-nokey") \ 57 + EM(rxkad_abort_resp_ooseq, "rxkad-resp-ooseq") \ 58 + EM(rxkad_abort_resp_short, "rxkad-resp-short") \ 59 + EM(rxkad_abort_resp_short_tkt, "rxkad-resp-short-tkt") \ 60 + EM(rxkad_abort_resp_tkt_aname, "rxkad-resp-tk-aname") \ 61 + EM(rxkad_abort_resp_tkt_expired, "rxkad-resp-tk-exp") \ 62 + EM(rxkad_abort_resp_tkt_future, "rxkad-resp-tk-future") \ 63 + EM(rxkad_abort_resp_tkt_inst, "rxkad-resp-tk-inst") \ 64 + EM(rxkad_abort_resp_tkt_len, "rxkad-resp-tk-len") \ 65 + EM(rxkad_abort_resp_tkt_realm, "rxkad-resp-tk-realm") \ 66 + EM(rxkad_abort_resp_tkt_short, "rxkad-resp-tk-short") \ 67 + EM(rxkad_abort_resp_tkt_sinst, "rxkad-resp-tk-sinst") \ 68 + EM(rxkad_abort_resp_tkt_sname, "rxkad-resp-tk-sname") \ 69 + EM(rxkad_abort_resp_unknown_tkt, "rxkad-resp-unknown-tkt") \ 70 + EM(rxkad_abort_resp_version, "rxkad-resp-version") \ 71 + /* rxrpc errors */ \ 72 + EM(rxrpc_abort_call_improper_term, "call-improper-term") \ 73 + EM(rxrpc_abort_call_reset, "call-reset") \ 74 + EM(rxrpc_abort_call_sendmsg, "call-sendmsg") \ 75 + EM(rxrpc_abort_call_sock_release, "call-sock-rel") \ 76 + EM(rxrpc_abort_call_sock_release_tba, "call-sock-rel-tba") \ 77 + EM(rxrpc_abort_call_timeout, "call-timeout") \ 78 + EM(rxrpc_abort_no_service_key, "no-serv-key") \ 79 + EM(rxrpc_abort_nomem, "nomem") \ 80 + EM(rxrpc_abort_service_not_offered, "serv-not-offered") \ 81 + EM(rxrpc_abort_shut_down, "shut-down") \ 82 + EM(rxrpc_abort_unsupported_security, "unsup-sec") \ 83 + EM(rxrpc_badmsg_bad_abort, "bad-abort") \ 84 + EM(rxrpc_badmsg_bad_jumbo, "bad-jumbo") \ 85 + EM(rxrpc_badmsg_short_ack, "short-ack") \ 86 + EM(rxrpc_badmsg_short_ack_info, "short-ack-info") \ 87 + EM(rxrpc_badmsg_short_hdr, "short-hdr") \ 88 + EM(rxrpc_badmsg_unsupported_packet, "unsup-pkt") \ 89 + EM(rxrpc_badmsg_zero_call, "zero-call") \ 90 + EM(rxrpc_badmsg_zero_seq, "zero-seq") \ 91 + EM(rxrpc_badmsg_zero_service, "zero-service") \ 92 + EM(rxrpc_eproto_ackr_outside_window, "ackr-out-win") \ 93 + EM(rxrpc_eproto_ackr_sack_overflow, "ackr-sack-over") \ 94 + EM(rxrpc_eproto_ackr_short_sack, "ackr-short-sack") \ 95 + EM(rxrpc_eproto_ackr_zero, "ackr-zero") \ 96 + EM(rxrpc_eproto_bad_upgrade, "bad-upgrade") \ 97 + EM(rxrpc_eproto_data_after_last, "data-after-last") \ 98 + EM(rxrpc_eproto_different_last, "diff-last") \ 99 + EM(rxrpc_eproto_early_reply, "early-reply") \ 100 + EM(rxrpc_eproto_improper_term, "improper-term") \ 101 + EM(rxrpc_eproto_no_client_call, "no-cl-call") \ 102 + EM(rxrpc_eproto_no_client_conn, "no-cl-conn") \ 103 + EM(rxrpc_eproto_no_service_call, "no-sv-call") \ 104 + EM(rxrpc_eproto_reupgrade, "re-upgrade") \ 105 + EM(rxrpc_eproto_rxnull_challenge, "rxnull-chall") \ 106 + EM(rxrpc_eproto_rxnull_response, "rxnull-resp") \ 107 + EM(rxrpc_eproto_tx_rot_last, "tx-rot-last") \ 108 + EM(rxrpc_eproto_unexpected_ack, "unex-ack") \ 109 + EM(rxrpc_eproto_unexpected_ackall, "unex-ackall") \ 110 + EM(rxrpc_eproto_unexpected_implicit_end, "unex-impl-end") \ 111 + EM(rxrpc_eproto_unexpected_reply, "unex-reply") \ 112 + EM(rxrpc_eproto_wrong_security, "wrong-sec") \ 113 + EM(rxrpc_recvmsg_excess_data, "recvmsg-excess") \ 114 + EM(rxrpc_recvmsg_short_data, "recvmsg-short") \ 115 + E_(rxrpc_sendmsg_late_send, "sendmsg-late") 116 + 19 117 #define rxrpc_call_poke_traces \ 20 118 EM(rxrpc_call_poke_abort, "Abort") \ 21 119 EM(rxrpc_call_poke_complete, "Compl") \ ··· 480 382 #define EM(a, b) a, 481 383 #define E_(a, b) a 482 384 385 + enum rxrpc_abort_reason { rxrpc_abort_reasons } __mode(byte); 483 386 enum rxrpc_bundle_trace { rxrpc_bundle_traces } __mode(byte); 484 387 enum rxrpc_call_poke_trace { rxrpc_call_poke_traces } __mode(byte); 485 388 enum rxrpc_call_trace { rxrpc_call_traces } __mode(byte); ··· 509 410 */ 510 411 #undef EM 511 412 #undef E_ 413 + 414 + #ifndef RXRPC_TRACE_ONLY_DEFINE_ENUMS 415 + 512 416 #define EM(a, b) TRACE_DEFINE_ENUM(a); 513 417 #define E_(a, b) TRACE_DEFINE_ENUM(a); 514 418 419 + rxrpc_abort_reasons; 515 420 rxrpc_bundle_traces; 516 421 rxrpc_call_poke_traces; 517 422 rxrpc_call_traces; ··· 766 663 ); 767 664 768 665 TRACE_EVENT(rxrpc_abort, 769 - TP_PROTO(unsigned int call_nr, const char *why, u32 cid, u32 call_id, 770 - rxrpc_seq_t seq, int abort_code, int error), 666 + TP_PROTO(unsigned int call_nr, enum rxrpc_abort_reason why, 667 + u32 cid, u32 call_id, rxrpc_seq_t seq, int abort_code, int error), 771 668 772 669 TP_ARGS(call_nr, why, cid, call_id, seq, abort_code, error), 773 670 774 671 TP_STRUCT__entry( 775 672 __field(unsigned int, call_nr ) 776 - __array(char, why, 4 ) 673 + __field(enum rxrpc_abort_reason, why ) 777 674 __field(u32, cid ) 778 675 __field(u32, call_id ) 779 676 __field(rxrpc_seq_t, seq ) ··· 782 679 ), 783 680 784 681 TP_fast_assign( 785 - memcpy(__entry->why, why, 4); 786 682 __entry->call_nr = call_nr; 683 + __entry->why = why; 787 684 __entry->cid = cid; 788 685 __entry->call_id = call_id; 789 686 __entry->abort_code = abort_code; ··· 794 691 TP_printk("c=%08x %08x:%08x s=%u a=%d e=%d %s", 795 692 __entry->call_nr, 796 693 __entry->cid, __entry->call_id, __entry->seq, 797 - __entry->abort_code, __entry->error, __entry->why) 694 + __entry->abort_code, __entry->error, 695 + __print_symbolic(__entry->why, rxrpc_abort_reasons)) 798 696 ); 799 697 800 698 TRACE_EVENT(rxrpc_call_complete, ··· 1631 1527 __entry->abort_code) 1632 1528 ); 1633 1529 1634 - TRACE_EVENT(rxrpc_rx_eproto, 1635 - TP_PROTO(struct rxrpc_call *call, rxrpc_serial_t serial, 1636 - const char *why), 1637 - 1638 - TP_ARGS(call, serial, why), 1639 - 1640 - TP_STRUCT__entry( 1641 - __field(unsigned int, call ) 1642 - __field(rxrpc_serial_t, serial ) 1643 - __field(const char *, why ) 1644 - ), 1645 - 1646 - TP_fast_assign( 1647 - __entry->call = call ? call->debug_id : 0; 1648 - __entry->serial = serial; 1649 - __entry->why = why; 1650 - ), 1651 - 1652 - TP_printk("c=%08x EPROTO %08x %s", 1653 - __entry->call, 1654 - __entry->serial, 1655 - __entry->why) 1656 - ); 1657 - 1658 1530 TRACE_EVENT(rxrpc_connect_call, 1659 1531 TP_PROTO(struct rxrpc_call *call), 1660 1532 ··· 1928 1848 1929 1849 #undef EM 1930 1850 #undef E_ 1851 + 1852 + #endif /* RXRPC_TRACE_ONLY_DEFINE_ENUMS */ 1931 1853 #endif /* _TRACE_RXRPC_H */ 1932 1854 1933 1855 /* This part must be outside protection */
+29 -22
net/rxrpc/ar-internal.h
··· 627 627 unsigned long events; 628 628 spinlock_t notify_lock; /* Kernel notification lock */ 629 629 rwlock_t state_lock; /* lock for state transition */ 630 - const char *send_abort_why; /* String indicating why the abort was sent */ 630 + unsigned int send_abort_why; /* Why the abort [enum rxrpc_abort_reason] */ 631 631 s32 send_abort; /* Abort code to be sent */ 632 632 short send_abort_err; /* Error to be associated with the abort */ 633 + rxrpc_seq_t send_abort_seq; /* DATA packet that incurred the abort (or 0) */ 633 634 s32 abort_code; /* Local/remote abort code */ 634 635 int error; /* Local error incurred */ 635 636 enum rxrpc_call_state state; /* current state of call */ ··· 819 818 */ 820 819 int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); 821 820 void rxrpc_discard_prealloc(struct rxrpc_sock *); 822 - int rxrpc_new_incoming_call(struct rxrpc_local *, struct rxrpc_peer *, 823 - struct rxrpc_connection *, struct sockaddr_rxrpc *, 824 - struct sk_buff *); 821 + bool rxrpc_new_incoming_call(struct rxrpc_local *local, 822 + struct rxrpc_peer *peer, 823 + struct rxrpc_connection *conn, 824 + struct sockaddr_rxrpc *peer_srx, 825 + struct sk_buff *skb); 825 826 void rxrpc_accept_incoming_calls(struct rxrpc_local *); 826 827 int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long); 827 828 ··· 843 840 unsigned long now, 844 841 enum rxrpc_timer_trace why); 845 842 846 - void rxrpc_input_call_event(struct rxrpc_call *call, struct sk_buff *skb); 843 + bool rxrpc_input_call_event(struct rxrpc_call *call, struct sk_buff *skb); 847 844 848 845 /* 849 846 * call_object.c ··· 908 905 void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn, struct sk_buff *skb, 909 906 unsigned int channel); 910 907 int rxrpc_abort_conn(struct rxrpc_connection *conn, struct sk_buff *skb, 911 - s32 abort_code, int err, const char *why); 908 + s32 abort_code, int err, enum rxrpc_abort_reason why); 912 909 void rxrpc_process_connection(struct work_struct *); 913 910 void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool); 914 - int rxrpc_input_conn_packet(struct rxrpc_connection *conn, struct sk_buff *skb); 911 + bool rxrpc_input_conn_packet(struct rxrpc_connection *conn, struct sk_buff *skb); 915 912 void rxrpc_input_conn_event(struct rxrpc_connection *conn, struct sk_buff *skb); 916 913 917 914 static inline bool rxrpc_is_conn_aborted(const struct rxrpc_connection *conn) ··· 982 979 */ 983 980 int rxrpc_encap_rcv(struct sock *, struct sk_buff *); 984 981 void rxrpc_error_report(struct sock *); 982 + bool rxrpc_direct_abort(struct sk_buff *skb, enum rxrpc_abort_reason why, 983 + s32 abort_code, int err); 985 984 int rxrpc_io_thread(void *data); 986 985 static inline void rxrpc_wake_up_io_thread(struct rxrpc_local *local) 987 986 { 988 987 wake_up_process(local->io_thread); 988 + } 989 + 990 + static inline bool rxrpc_protocol_error(struct sk_buff *skb, enum rxrpc_abort_reason why) 991 + { 992 + return rxrpc_direct_abort(skb, why, RX_PROTOCOL_ERROR, -EPROTO); 989 993 } 990 994 991 995 /* ··· 1118 1108 bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int); 1119 1109 bool __rxrpc_call_completed(struct rxrpc_call *); 1120 1110 bool rxrpc_call_completed(struct rxrpc_call *); 1121 - bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); 1122 - bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); 1111 + bool __rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq, 1112 + u32 abort_code, int error, enum rxrpc_abort_reason why); 1113 + bool rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq, 1114 + u32 abort_code, int error, enum rxrpc_abort_reason why); 1123 1115 int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 1124 1116 1125 1117 /* 1126 1118 * Abort a call due to a protocol error. 1127 1119 */ 1128 - static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call, 1129 - struct sk_buff *skb, 1130 - const char *eproto_why, 1131 - const char *why, 1132 - u32 abort_code) 1120 + static inline int rxrpc_abort_eproto(struct rxrpc_call *call, 1121 + struct sk_buff *skb, 1122 + s32 abort_code, 1123 + enum rxrpc_abort_reason why) 1133 1124 { 1134 1125 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 1135 1126 1136 - trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why); 1137 - return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO); 1127 + rxrpc_abort_call(call, sp->hdr.seq, abort_code, -EPROTO, why); 1128 + return -EPROTO; 1138 1129 } 1139 - 1140 - #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \ 1141 - __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \ 1142 - (abort_why), (abort_code)) 1143 1130 1144 1131 /* 1145 1132 * rtt.c ··· 1169 1162 /* 1170 1163 * sendmsg.c 1171 1164 */ 1172 - bool rxrpc_propose_abort(struct rxrpc_call *call, 1173 - u32 abort_code, int error, const char *why); 1165 + bool rxrpc_propose_abort(struct rxrpc_call *call, s32 abort_code, int error, 1166 + enum rxrpc_abort_reason why); 1174 1167 int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 1175 1168 1176 1169 /*
+21 -22
net/rxrpc/call_accept.c
··· 326 326 * If we want to report an error, we mark the skb with the packet type and 327 327 * abort code and return false. 328 328 */ 329 - int rxrpc_new_incoming_call(struct rxrpc_local *local, 330 - struct rxrpc_peer *peer, 331 - struct rxrpc_connection *conn, 332 - struct sockaddr_rxrpc *peer_srx, 333 - struct sk_buff *skb) 329 + bool rxrpc_new_incoming_call(struct rxrpc_local *local, 330 + struct rxrpc_peer *peer, 331 + struct rxrpc_connection *conn, 332 + struct sockaddr_rxrpc *peer_srx, 333 + struct sk_buff *skb) 334 334 { 335 335 const struct rxrpc_security *sec = NULL; 336 336 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); ··· 339 339 340 340 _enter(""); 341 341 342 - /* Don't set up a call for anything other than the first DATA packet. */ 343 - if (sp->hdr.seq != 1 || 344 - sp->hdr.type != RXRPC_PACKET_TYPE_DATA) 345 - return 0; /* Just discard */ 342 + /* Don't set up a call for anything other than a DATA packet. */ 343 + if (sp->hdr.type != RXRPC_PACKET_TYPE_DATA) 344 + return rxrpc_protocol_error(skb, rxrpc_eproto_no_service_call); 346 345 347 346 rcu_read_lock(); 348 347 ··· 362 363 if (!conn) { 363 364 sec = rxrpc_get_incoming_security(rx, skb); 364 365 if (!sec) 365 - goto reject; 366 + goto unsupported_security; 366 367 } 367 368 368 369 spin_lock(&rx->incoming_lock); 369 370 if (rx->sk.sk_state == RXRPC_SERVER_LISTEN_DISABLED || 370 371 rx->sk.sk_state == RXRPC_CLOSE) { 371 - trace_rxrpc_abort(0, "CLS", sp->hdr.cid, sp->hdr.callNumber, 372 - sp->hdr.seq, RX_INVALID_OPERATION, ESHUTDOWN); 373 - skb->mark = RXRPC_SKB_MARK_REJECT_ABORT; 374 - skb->priority = RX_INVALID_OPERATION; 372 + rxrpc_direct_abort(skb, rxrpc_abort_shut_down, 373 + RX_INVALID_OPERATION, -ESHUTDOWN); 375 374 goto no_call; 376 375 } 377 376 ··· 410 413 _leave(" = %p{%d}", call, call->debug_id); 411 414 rxrpc_input_call_event(call, skb); 412 415 rxrpc_put_call(call, rxrpc_call_put_input); 413 - return 0; 416 + return true; 414 417 415 418 unsupported_service: 416 - trace_rxrpc_abort(0, "INV", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 417 - RX_INVALID_OPERATION, EOPNOTSUPP); 418 - skb->priority = RX_INVALID_OPERATION; 419 - goto reject; 419 + rcu_read_unlock(); 420 + return rxrpc_direct_abort(skb, rxrpc_abort_service_not_offered, 421 + RX_INVALID_OPERATION, -EOPNOTSUPP); 422 + unsupported_security: 423 + rcu_read_unlock(); 424 + return rxrpc_direct_abort(skb, rxrpc_abort_service_not_offered, 425 + RX_INVALID_OPERATION, -EKEYREJECTED); 420 426 no_call: 421 427 spin_unlock(&rx->incoming_lock); 422 - reject: 423 428 rcu_read_unlock(); 424 429 _leave(" = f [%u]", skb->mark); 425 - return -EPROTO; 430 + return false; 426 431 discard: 427 432 rcu_read_unlock(); 428 - return 0; 433 + return true; 429 434 } 430 435 431 436 /*
+8 -5
net/rxrpc/call_event.c
··· 333 333 /* 334 334 * Handle retransmission and deferred ACK/abort generation. 335 335 */ 336 - void rxrpc_input_call_event(struct rxrpc_call *call, struct sk_buff *skb) 336 + bool rxrpc_input_call_event(struct rxrpc_call *call, struct sk_buff *skb) 337 337 { 338 338 unsigned long now, next, t; 339 339 rxrpc_serial_t ackr_serial; ··· 352 352 /* Handle abort request locklessly, vs rxrpc_propose_abort(). */ 353 353 abort_code = smp_load_acquire(&call->send_abort); 354 354 if (abort_code) { 355 - rxrpc_abort_call(call->send_abort_why, call, 0, call->send_abort, 356 - call->send_abort_err); 355 + rxrpc_abort_call(call, 0, call->send_abort, call->send_abort_err, 356 + call->send_abort_why); 357 357 goto out; 358 358 } 359 359 ··· 440 440 if (test_bit(RXRPC_CALL_RX_HEARD, &call->flags) && 441 441 (int)call->conn->hi_serial - (int)call->rx_serial > 0) { 442 442 trace_rxrpc_call_reset(call); 443 - rxrpc_abort_call("EXP", call, 0, RX_CALL_DEAD, -ECONNRESET); 443 + rxrpc_abort_call(call, 0, RX_CALL_DEAD, -ECONNRESET, 444 + rxrpc_abort_call_reset); 444 445 } else { 445 - rxrpc_abort_call("EXP", call, 0, RX_CALL_TIMEOUT, -ETIME); 446 + rxrpc_abort_call(call, 0, RX_CALL_TIMEOUT, -ETIME, 447 + rxrpc_abort_call_timeout); 446 448 } 447 449 goto out; 448 450 } ··· 496 494 if (call->acks_hard_ack != call->tx_bottom) 497 495 rxrpc_shrink_call_tx_buffer(call); 498 496 _leave(""); 497 + return true; 499 498 }
+4 -2
net/rxrpc/call_object.c
··· 581 581 call = list_entry(rx->to_be_accepted.next, 582 582 struct rxrpc_call, accept_link); 583 583 list_del(&call->accept_link); 584 - rxrpc_propose_abort(call, RX_CALL_DEAD, -ECONNRESET, "SKR"); 584 + rxrpc_propose_abort(call, RX_CALL_DEAD, -ECONNRESET, 585 + rxrpc_abort_call_sock_release_tba); 585 586 rxrpc_put_call(call, rxrpc_call_put_release_sock_tba); 586 587 } 587 588 ··· 590 589 call = list_entry(rx->sock_calls.next, 591 590 struct rxrpc_call, sock_link); 592 591 rxrpc_get_call(call, rxrpc_call_get_release_sock); 593 - rxrpc_propose_abort(call, RX_CALL_DEAD, -ECONNRESET, "SKT"); 592 + rxrpc_propose_abort(call, RX_CALL_DEAD, -ECONNRESET, 593 + rxrpc_abort_call_sock_release); 594 594 rxrpc_release_call(rx, call); 595 595 rxrpc_put_call(call, rxrpc_call_put_release_sock); 596 596 }
+9 -10
net/rxrpc/conn_event.c
··· 47 47 * Mark a socket buffer to indicate that the connection it's on should be aborted. 48 48 */ 49 49 int rxrpc_abort_conn(struct rxrpc_connection *conn, struct sk_buff *skb, 50 - s32 abort_code, int err, const char *why) 50 + s32 abort_code, int err, enum rxrpc_abort_reason why) 51 51 { 52 52 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 53 53 ··· 288 288 return 0; 289 289 290 290 default: 291 - trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, 292 - tracepoint_string("bad_conn_pkt")); 291 + WARN_ON_ONCE(1); 293 292 return -EPROTO; 294 293 } 295 294 } ··· 299 300 static void rxrpc_secure_connection(struct rxrpc_connection *conn) 300 301 { 301 302 if (conn->security->issue_challenge(conn) < 0) 302 - rxrpc_abort_conn(conn, NULL, RX_CALL_DEAD, -ENOMEM, "OOM"); 303 + rxrpc_abort_conn(conn, NULL, RX_CALL_DEAD, -ENOMEM, 304 + rxrpc_abort_nomem); 303 305 } 304 306 305 307 /* ··· 405 405 /* 406 406 * Input a connection-level packet. 407 407 */ 408 - int rxrpc_input_conn_packet(struct rxrpc_connection *conn, struct sk_buff *skb) 408 + bool rxrpc_input_conn_packet(struct rxrpc_connection *conn, struct sk_buff *skb) 409 409 { 410 410 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 411 411 412 412 switch (sp->hdr.type) { 413 413 case RXRPC_PACKET_TYPE_BUSY: 414 414 /* Just ignore BUSY packets for now. */ 415 - return 0; 415 + return true; 416 416 417 417 case RXRPC_PACKET_TYPE_ABORT: 418 418 if (rxrpc_is_conn_aborted(conn)) ··· 429 429 return true; 430 430 } 431 431 rxrpc_post_packet_to_conn(conn, skb); 432 - return 0; 432 + return true; 433 433 434 434 default: 435 - trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, 436 - tracepoint_string("bad_conn_pkt")); 437 - return -EPROTO; 435 + WARN_ON_ONCE(1); 436 + return true; 438 437 } 439 438 } 440 439
+30 -35
net/rxrpc/input.c
··· 9 9 10 10 #include "ar-internal.h" 11 11 12 - static void rxrpc_proto_abort(const char *why, 13 - struct rxrpc_call *call, rxrpc_seq_t seq) 12 + static void rxrpc_proto_abort(struct rxrpc_call *call, rxrpc_seq_t seq, 13 + enum rxrpc_abort_reason why) 14 14 { 15 - rxrpc_abort_call(why, call, seq, RX_PROTOCOL_ERROR, -EBADMSG); 15 + rxrpc_abort_call(call, seq, RX_PROTOCOL_ERROR, -EBADMSG, why); 16 16 } 17 17 18 18 /* ··· 249 249 * This occurs when we get an ACKALL packet, the first DATA packet of a reply, 250 250 * or a final ACK packet. 251 251 */ 252 - static bool rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun, 253 - const char *abort_why) 252 + static void rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun, 253 + enum rxrpc_abort_reason abort_why) 254 254 { 255 255 unsigned int state; 256 256 ··· 283 283 else 284 284 trace_rxrpc_txqueue(call, rxrpc_txqueue_end); 285 285 _leave(" = ok"); 286 - return true; 286 + return; 287 287 288 288 bad_state: 289 289 write_unlock(&call->state_lock); 290 290 kdebug("end_tx %s", rxrpc_call_states[call->state]); 291 - rxrpc_proto_abort(abort_why, call, call->tx_top); 292 - return false; 291 + rxrpc_proto_abort(call, call->tx_top, abort_why); 293 292 } 294 293 295 294 /* ··· 310 311 311 312 if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags)) { 312 313 if (!rxrpc_rotate_tx_window(call, top, &summary)) { 313 - rxrpc_proto_abort("TXL", call, top); 314 + rxrpc_proto_abort(call, top, rxrpc_eproto_early_reply); 314 315 return false; 315 316 } 316 317 } 317 - return rxrpc_end_tx_phase(call, true, "ETD"); 318 + 319 + rxrpc_end_tx_phase(call, true, rxrpc_eproto_unexpected_reply); 320 + return true; 318 321 } 319 322 320 323 static void rxrpc_input_update_ack_window(struct rxrpc_call *call, ··· 366 365 367 366 if (last) { 368 367 if (test_and_set_bit(RXRPC_CALL_RX_LAST, &call->flags) && 369 - seq + 1 != wtop) { 370 - rxrpc_proto_abort("LSN", call, seq); 371 - return; 372 - } 368 + seq + 1 != wtop) 369 + return rxrpc_proto_abort(call, seq, rxrpc_eproto_different_last); 373 370 } else { 374 371 if (test_bit(RXRPC_CALL_RX_LAST, &call->flags) && 375 372 after_eq(seq, wtop)) { 376 373 pr_warn("Packet beyond last: c=%x q=%x window=%x-%x wlimit=%x\n", 377 374 call->debug_id, seq, window, wtop, wlimit); 378 - rxrpc_proto_abort("LSA", call, seq); 379 - return; 375 + return rxrpc_proto_abort(call, seq, rxrpc_eproto_data_after_last); 380 376 } 381 377 } 382 378 ··· 581 583 goto out_notify; 582 584 583 585 if (!rxrpc_input_split_jumbo(call, skb)) { 584 - rxrpc_proto_abort("VLD", call, sp->hdr.seq); 586 + rxrpc_proto_abort(call, sp->hdr.seq, rxrpc_badmsg_bad_jumbo); 585 587 goto out_notify; 586 588 } 587 589 skb = NULL; ··· 762 764 763 765 offset = sizeof(struct rxrpc_wire_header); 764 766 if (skb_copy_bits(skb, offset, &ack, sizeof(ack)) < 0) 765 - return rxrpc_proto_abort("XAK", call, 0); 767 + return rxrpc_proto_abort(call, 0, rxrpc_badmsg_short_ack); 766 768 offset += sizeof(ack); 767 769 768 770 ack_serial = sp->hdr.serial; ··· 842 844 ioffset = offset + nr_acks + 3; 843 845 if (skb->len >= ioffset + sizeof(info) && 844 846 skb_copy_bits(skb, ioffset, &info, sizeof(info)) < 0) 845 - return rxrpc_proto_abort("XAI", call, 0); 847 + return rxrpc_proto_abort(call, 0, rxrpc_badmsg_short_ack_info); 846 848 847 849 if (nr_acks > 0) 848 850 skb_condense(skb); ··· 865 867 rxrpc_input_ackinfo(call, skb, &info); 866 868 867 869 if (first_soft_ack == 0) 868 - return rxrpc_proto_abort("AK0", call, 0); 870 + return rxrpc_proto_abort(call, 0, rxrpc_eproto_ackr_zero); 869 871 870 872 /* Ignore ACKs unless we are or have just been transmitting. */ 871 873 switch (READ_ONCE(call->state)) { ··· 880 882 881 883 if (before(hard_ack, call->acks_hard_ack) || 882 884 after(hard_ack, call->tx_top)) 883 - return rxrpc_proto_abort("AKW", call, 0); 885 + return rxrpc_proto_abort(call, 0, rxrpc_eproto_ackr_outside_window); 884 886 if (nr_acks > call->tx_top - hard_ack) 885 - return rxrpc_proto_abort("AKN", call, 0); 887 + return rxrpc_proto_abort(call, 0, rxrpc_eproto_ackr_sack_overflow); 886 888 887 889 if (after(hard_ack, call->acks_hard_ack)) { 888 890 if (rxrpc_rotate_tx_window(call, hard_ack, &summary)) { 889 - rxrpc_end_tx_phase(call, false, "ETA"); 891 + rxrpc_end_tx_phase(call, false, rxrpc_eproto_unexpected_ack); 890 892 return; 891 893 } 892 894 } 893 895 894 896 if (nr_acks > 0) { 895 897 if (offset > (int)skb->len - nr_acks) 896 - return rxrpc_proto_abort("XSA", call, 0); 898 + return rxrpc_proto_abort(call, 0, rxrpc_eproto_ackr_short_sack); 897 899 rxrpc_input_soft_acks(call, skb->data + offset, first_soft_ack, 898 900 nr_acks, &summary); 899 901 } ··· 915 917 struct rxrpc_ack_summary summary = { 0 }; 916 918 917 919 if (rxrpc_rotate_tx_window(call, call->tx_top, &summary)) 918 - rxrpc_end_tx_phase(call, false, "ETL"); 920 + rxrpc_end_tx_phase(call, false, rxrpc_eproto_unexpected_ackall); 919 921 } 920 922 921 923 /* ··· 960 962 961 963 switch (sp->hdr.type) { 962 964 case RXRPC_PACKET_TYPE_DATA: 963 - rxrpc_input_data(call, skb); 964 - break; 965 + return rxrpc_input_data(call, skb); 965 966 966 967 case RXRPC_PACKET_TYPE_ACK: 967 - rxrpc_input_ack(call, skb); 968 - break; 968 + return rxrpc_input_ack(call, skb); 969 969 970 970 case RXRPC_PACKET_TYPE_BUSY: 971 971 /* Just ignore BUSY packets from the server; the retry and 972 972 * lifespan timers will take care of business. BUSY packets 973 973 * from the client don't make sense. 974 974 */ 975 - break; 975 + return; 976 976 977 977 case RXRPC_PACKET_TYPE_ABORT: 978 - rxrpc_input_abort(call, skb); 979 - break; 978 + return rxrpc_input_abort(call, skb); 980 979 981 980 case RXRPC_PACKET_TYPE_ACKALL: 982 - rxrpc_input_ackall(call, skb); 983 - break; 981 + return rxrpc_input_ackall(call, skb); 984 982 985 983 default: 986 984 break; ··· 998 1004 case RXRPC_CALL_COMPLETE: 999 1005 break; 1000 1006 default: 1001 - rxrpc_abort_call("IMP", call, 0, RX_CALL_DEAD, -ESHUTDOWN); 1007 + rxrpc_abort_call(call, 0, RX_CALL_DEAD, -ESHUTDOWN, 1008 + rxrpc_eproto_improper_term); 1002 1009 trace_rxrpc_improper_term(call); 1003 1010 break; 1004 1011 }
+4 -2
net/rxrpc/insecure.c
··· 45 45 static int none_respond_to_challenge(struct rxrpc_connection *conn, 46 46 struct sk_buff *skb) 47 47 { 48 - return rxrpc_abort_conn(conn, skb, RX_PROTOCOL_ERROR, -EPROTO, "RXN"); 48 + return rxrpc_abort_conn(conn, skb, RX_PROTOCOL_ERROR, -EPROTO, 49 + rxrpc_eproto_rxnull_challenge); 49 50 } 50 51 51 52 static int none_verify_response(struct rxrpc_connection *conn, 52 53 struct sk_buff *skb) 53 54 { 54 - return rxrpc_abort_conn(conn, skb, RX_PROTOCOL_ERROR, -EPROTO, "RXN"); 55 + return rxrpc_abort_conn(conn, skb, RX_PROTOCOL_ERROR, -EPROTO, 56 + rxrpc_eproto_rxnull_response); 55 57 } 56 58 57 59 static void none_clear(struct rxrpc_connection *conn)
+74 -89
net/rxrpc/io_thread.c
··· 67 67 } 68 68 69 69 /* 70 + * Directly produce an abort from a packet. 71 + */ 72 + bool rxrpc_direct_abort(struct sk_buff *skb, enum rxrpc_abort_reason why, 73 + s32 abort_code, int err) 74 + { 75 + struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 76 + 77 + trace_rxrpc_abort(0, why, sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 78 + abort_code, err); 79 + skb->mark = RXRPC_SKB_MARK_REJECT_ABORT; 80 + skb->priority = abort_code; 81 + return false; 82 + } 83 + 84 + static bool rxrpc_bad_message(struct sk_buff *skb, enum rxrpc_abort_reason why) 85 + { 86 + return rxrpc_direct_abort(skb, why, RX_PROTOCOL_ERROR, -EBADMSG); 87 + } 88 + 89 + #define just_discard true 90 + 91 + /* 70 92 * Process event packets targeted at a local endpoint. 71 93 */ 72 - static void rxrpc_input_version(struct rxrpc_local *local, struct sk_buff *skb) 94 + static bool rxrpc_input_version(struct rxrpc_local *local, struct sk_buff *skb) 73 95 { 74 96 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 75 97 char v; ··· 103 81 if (v == 0) 104 82 rxrpc_send_version_request(local, &sp->hdr, skb); 105 83 } 84 + 85 + return true; 106 86 } 107 87 108 88 /* 109 89 * Extract the wire header from a packet and translate the byte order. 110 90 */ 111 - static noinline 112 - int rxrpc_extract_header(struct rxrpc_skb_priv *sp, struct sk_buff *skb) 91 + static bool rxrpc_extract_header(struct rxrpc_skb_priv *sp, 92 + struct sk_buff *skb) 113 93 { 114 94 struct rxrpc_wire_header whdr; 115 95 116 96 /* dig out the RxRPC connection details */ 117 - if (skb_copy_bits(skb, 0, &whdr, sizeof(whdr)) < 0) { 118 - trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, 119 - tracepoint_string("bad_hdr")); 120 - return -EBADMSG; 121 - } 97 + if (skb_copy_bits(skb, 0, &whdr, sizeof(whdr)) < 0) 98 + return rxrpc_bad_message(skb, rxrpc_badmsg_short_hdr); 122 99 123 100 memset(sp, 0, sizeof(*sp)); 124 101 sp->hdr.epoch = ntohl(whdr.epoch); ··· 131 110 sp->hdr.securityIndex = whdr.securityIndex; 132 111 sp->hdr._rsvd = ntohs(whdr._rsvd); 133 112 sp->hdr.serviceId = ntohs(whdr.serviceId); 134 - return 0; 113 + return true; 135 114 } 136 115 137 116 /* ··· 151 130 /* 152 131 * Process packets received on the local endpoint 153 132 */ 154 - static int rxrpc_input_packet(struct rxrpc_local *local, struct sk_buff **_skb) 133 + static bool rxrpc_input_packet(struct rxrpc_local *local, struct sk_buff **_skb) 155 134 { 156 135 struct rxrpc_connection *conn; 157 136 struct sockaddr_rxrpc peer_srx; 158 137 struct rxrpc_skb_priv *sp; 159 138 struct rxrpc_peer *peer = NULL; 160 139 struct sk_buff *skb = *_skb; 161 - int ret = 0; 140 + bool ret = false; 162 141 163 142 skb_pull(skb, sizeof(struct udphdr)); 164 143 165 144 sp = rxrpc_skb(skb); 166 145 167 146 /* dig out the RxRPC connection details */ 168 - if (rxrpc_extract_header(sp, skb) < 0) 169 - goto bad_message; 147 + if (!rxrpc_extract_header(sp, skb)) 148 + return just_discard; 170 149 171 150 if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) { 172 151 static int lose; 173 152 if ((lose++ & 7) == 7) { 174 153 trace_rxrpc_rx_lose(sp); 175 - return 0; 154 + return just_discard; 176 155 } 177 156 } 178 157 ··· 181 160 switch (sp->hdr.type) { 182 161 case RXRPC_PACKET_TYPE_VERSION: 183 162 if (rxrpc_to_client(sp)) 184 - return 0; 185 - rxrpc_input_version(local, skb); 186 - return 0; 163 + return just_discard; 164 + return rxrpc_input_version(local, skb); 187 165 188 166 case RXRPC_PACKET_TYPE_BUSY: 189 167 if (rxrpc_to_server(sp)) 190 - return 0; 168 + return just_discard; 191 169 fallthrough; 192 170 case RXRPC_PACKET_TYPE_ACK: 193 171 case RXRPC_PACKET_TYPE_ACKALL: 194 172 if (sp->hdr.callNumber == 0) 195 - goto bad_message; 173 + return rxrpc_bad_message(skb, rxrpc_badmsg_zero_call); 196 174 break; 197 175 case RXRPC_PACKET_TYPE_ABORT: 198 176 if (!rxrpc_extract_abort(skb)) 199 - return 0; /* Just discard if malformed */ 177 + return just_discard; /* Just discard if malformed */ 200 178 break; 201 179 202 180 case RXRPC_PACKET_TYPE_DATA: 203 - if (sp->hdr.callNumber == 0 || 204 - sp->hdr.seq == 0) 205 - goto bad_message; 181 + if (sp->hdr.callNumber == 0) 182 + return rxrpc_bad_message(skb, rxrpc_badmsg_zero_call); 183 + if (sp->hdr.seq == 0) 184 + return rxrpc_bad_message(skb, rxrpc_badmsg_zero_seq); 206 185 207 186 /* Unshare the packet so that it can be modified for in-place 208 187 * decryption. ··· 212 191 if (!skb) { 213 192 rxrpc_eaten_skb(*_skb, rxrpc_skb_eaten_by_unshare_nomem); 214 193 *_skb = NULL; 215 - return 0; 194 + return just_discard; 216 195 } 217 196 218 197 if (skb != *_skb) { ··· 226 205 227 206 case RXRPC_PACKET_TYPE_CHALLENGE: 228 207 if (rxrpc_to_server(sp)) 229 - return 0; 208 + return just_discard; 230 209 break; 231 210 case RXRPC_PACKET_TYPE_RESPONSE: 232 211 if (rxrpc_to_client(sp)) 233 - return 0; 212 + return just_discard; 234 213 break; 235 214 236 215 /* Packet types 9-11 should just be ignored. */ 237 216 case RXRPC_PACKET_TYPE_PARAMS: 238 217 case RXRPC_PACKET_TYPE_10: 239 218 case RXRPC_PACKET_TYPE_11: 240 - return 0; 219 + return just_discard; 241 220 242 221 default: 243 - goto bad_message; 222 + return rxrpc_bad_message(skb, rxrpc_badmsg_unsupported_packet); 244 223 } 245 224 246 225 if (sp->hdr.serviceId == 0) 247 - goto bad_message; 226 + return rxrpc_bad_message(skb, rxrpc_badmsg_zero_service); 248 227 249 228 if (WARN_ON_ONCE(rxrpc_extract_addr_from_skb(&peer_srx, skb) < 0)) 250 - return true; /* Unsupported address type - discard. */ 229 + return just_discard; /* Unsupported address type. */ 251 230 252 231 if (peer_srx.transport.family != local->srx.transport.family && 253 232 (peer_srx.transport.family == AF_INET && ··· 255 234 pr_warn_ratelimited("AF_RXRPC: Protocol mismatch %u not %u\n", 256 235 peer_srx.transport.family, 257 236 local->srx.transport.family); 258 - return true; /* Wrong address type - discard. */ 237 + return just_discard; /* Wrong address type. */ 259 238 } 260 239 261 240 if (rxrpc_to_client(sp)) { ··· 263 242 conn = rxrpc_find_client_connection_rcu(local, &peer_srx, skb); 264 243 conn = rxrpc_get_connection_maybe(conn, rxrpc_conn_get_call_input); 265 244 rcu_read_unlock(); 266 - if (!conn) { 267 - trace_rxrpc_abort(0, "NCC", sp->hdr.cid, 268 - sp->hdr.callNumber, sp->hdr.seq, 269 - RXKADINCONSISTENCY, EBADMSG); 270 - goto protocol_error; 271 - } 245 + if (!conn) 246 + return rxrpc_protocol_error(skb, rxrpc_eproto_no_client_conn); 272 247 273 248 ret = rxrpc_input_packet_on_conn(conn, &peer_srx, skb); 274 249 rxrpc_put_connection(conn, rxrpc_conn_put_call_input); ··· 297 280 298 281 ret = rxrpc_new_incoming_call(local, peer, NULL, &peer_srx, skb); 299 282 rxrpc_put_peer(peer, rxrpc_peer_put_input); 300 - if (ret < 0) 301 - goto reject_packet; 302 - return 0; 303 - 304 - bad_message: 305 - trace_rxrpc_abort(0, "BAD", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 306 - RX_PROTOCOL_ERROR, EBADMSG); 307 - protocol_error: 308 - skb->priority = RX_PROTOCOL_ERROR; 309 - skb->mark = RXRPC_SKB_MARK_REJECT_ABORT; 310 - reject_packet: 311 - rxrpc_reject_packet(local, skb); 312 - return 0; 283 + return ret; 313 284 } 314 285 315 286 /* ··· 311 306 struct rxrpc_channel *chan; 312 307 struct rxrpc_call *call = NULL; 313 308 unsigned int channel; 309 + bool ret; 314 310 315 311 if (sp->hdr.securityIndex != conn->security_ix) 316 - goto wrong_security; 312 + return rxrpc_direct_abort(skb, rxrpc_eproto_wrong_security, 313 + RXKADINCONSISTENCY, -EBADMSG); 317 314 318 315 if (sp->hdr.serviceId != conn->service_id) { 319 316 int old_id; 320 317 321 318 if (!test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags)) 322 - goto reupgrade; 319 + return rxrpc_protocol_error(skb, rxrpc_eproto_reupgrade); 320 + 323 321 old_id = cmpxchg(&conn->service_id, conn->orig_service_id, 324 322 sp->hdr.serviceId); 325 - 326 323 if (old_id != conn->orig_service_id && 327 324 old_id != sp->hdr.serviceId) 328 - goto reupgrade; 325 + return rxrpc_protocol_error(skb, rxrpc_eproto_bad_upgrade); 329 326 } 330 327 331 328 if (after(sp->hdr.serial, conn->hi_serial)) ··· 343 336 344 337 /* Ignore really old calls */ 345 338 if (sp->hdr.callNumber < chan->last_call) 346 - return 0; 339 + return just_discard; 347 340 348 341 if (sp->hdr.callNumber == chan->last_call) { 349 342 if (chan->call || 350 343 sp->hdr.type == RXRPC_PACKET_TYPE_ABORT) 351 - return 0; 344 + return just_discard; 352 345 353 346 /* For the previous service call, if completed successfully, we 354 347 * discard all further packets. 355 348 */ 356 349 if (rxrpc_conn_is_service(conn) && 357 350 chan->last_type == RXRPC_PACKET_TYPE_ACK) 358 - return 0; 351 + return just_discard; 359 352 360 353 /* But otherwise we need to retransmit the final packet from 361 354 * data cached in the connection record. ··· 366 359 sp->hdr.serial, 367 360 sp->hdr.flags); 368 361 rxrpc_conn_retransmit_call(conn, skb, channel); 369 - return 0; 362 + return just_discard; 370 363 } 371 364 372 365 rcu_read_lock(); ··· 377 370 if (sp->hdr.callNumber > chan->call_id) { 378 371 if (rxrpc_to_client(sp)) { 379 372 rxrpc_put_call(call, rxrpc_call_put_input); 380 - goto reject_packet; 373 + return rxrpc_protocol_error(skb, 374 + rxrpc_eproto_unexpected_implicit_end); 381 375 } 382 376 383 377 if (call) { ··· 390 382 391 383 if (!call) { 392 384 if (rxrpc_to_client(sp)) 393 - goto bad_message; 394 - if (rxrpc_new_incoming_call(conn->local, conn->peer, conn, 395 - peer_srx, skb) == 0) 396 - return 0; 397 - goto reject_packet; 385 + return rxrpc_protocol_error(skb, rxrpc_eproto_no_client_call); 386 + return rxrpc_new_incoming_call(conn->local, conn->peer, conn, 387 + peer_srx, skb); 398 388 } 399 389 400 - rxrpc_input_call_event(call, skb); 390 + ret = rxrpc_input_call_event(call, skb); 401 391 rxrpc_put_call(call, rxrpc_call_put_input); 402 - return 0; 403 - 404 - wrong_security: 405 - trace_rxrpc_abort(0, "SEC", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 406 - RXKADINCONSISTENCY, EBADMSG); 407 - skb->priority = RXKADINCONSISTENCY; 408 - goto post_abort; 409 - 410 - reupgrade: 411 - trace_rxrpc_abort(0, "UPG", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 412 - RX_PROTOCOL_ERROR, EBADMSG); 413 - goto protocol_error; 414 - 415 - bad_message: 416 - trace_rxrpc_abort(0, "BAD", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 417 - RX_PROTOCOL_ERROR, EBADMSG); 418 - protocol_error: 419 - skb->priority = RX_PROTOCOL_ERROR; 420 - post_abort: 421 - skb->mark = RXRPC_SKB_MARK_REJECT_ABORT; 422 - reject_packet: 423 - rxrpc_reject_packet(conn->local, skb); 424 - return 0; 392 + return ret; 425 393 } 426 394 427 395 /* ··· 454 470 switch (skb->mark) { 455 471 case RXRPC_SKB_MARK_PACKET: 456 472 skb->priority = 0; 457 - rxrpc_input_packet(local, &skb); 473 + if (!rxrpc_input_packet(local, &skb)) 474 + rxrpc_reject_packet(local, skb); 458 475 trace_rxrpc_rx_done(skb->mark, skb->priority); 459 476 rxrpc_free_skb(skb, rxrpc_skb_put_input); 460 477 break;
+11 -7
net/rxrpc/recvmsg.c
··· 117 117 /* 118 118 * Record that a call is locally aborted. 119 119 */ 120 - bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call, 121 - rxrpc_seq_t seq, u32 abort_code, int error) 120 + bool __rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq, 121 + u32 abort_code, int error, enum rxrpc_abort_reason why) 122 122 { 123 123 trace_rxrpc_abort(call->debug_id, why, call->cid, call->call_id, seq, 124 124 abort_code, error); ··· 126 126 abort_code, error); 127 127 } 128 128 129 - bool rxrpc_abort_call(const char *why, struct rxrpc_call *call, 130 - rxrpc_seq_t seq, u32 abort_code, int error) 129 + bool rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq, 130 + u32 abort_code, int error, enum rxrpc_abort_reason why) 131 131 { 132 132 bool ret; 133 133 134 134 write_lock(&call->state_lock); 135 - ret = __rxrpc_abort_call(why, call, seq, abort_code, error); 135 + ret = __rxrpc_abort_call(call, seq, abort_code, error, why); 136 136 write_unlock(&call->state_lock); 137 137 if (ret && test_bit(RXRPC_CALL_EXPOSED, &call->flags)) 138 138 rxrpc_send_abort_packet(call); ··· 642 642 return ret; 643 643 644 644 short_data: 645 - trace_rxrpc_rx_eproto(call, 0, tracepoint_string("short_data")); 645 + trace_rxrpc_abort(call->debug_id, rxrpc_recvmsg_short_data, 646 + call->cid, call->call_id, call->rx_consumed, 647 + 0, -EBADMSG); 646 648 ret = -EBADMSG; 647 649 goto out; 648 650 excess_data: 649 - trace_rxrpc_rx_eproto(call, 0, tracepoint_string("excess_data")); 651 + trace_rxrpc_abort(call->debug_id, rxrpc_recvmsg_excess_data, 652 + call->cid, call->call_id, call->rx_consumed, 653 + 0, -EMSGSIZE); 650 654 ret = -EMSGSIZE; 651 655 goto out; 652 656 call_complete:
+133 -188
net/rxrpc/rxkad.c
··· 411 411 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 412 412 struct rxrpc_crypt iv; 413 413 struct scatterlist sg[16]; 414 - bool aborted; 415 414 u32 data_size, buf; 416 415 u16 check; 417 416 int ret; 418 417 419 418 _enter(""); 420 419 421 - if (sp->len < 8) { 422 - aborted = rxrpc_abort_eproto(call, skb, "rxkad_1_hdr", "V1H", 423 - RXKADSEALEDINCON); 424 - goto protocol_error; 425 - } 420 + if (sp->len < 8) 421 + return rxrpc_abort_eproto(call, skb, RXKADSEALEDINCON, 422 + rxkad_abort_1_short_header); 426 423 427 424 /* Decrypt the skbuff in-place. TODO: We really want to decrypt 428 425 * directly into the target buffer. ··· 439 442 skcipher_request_zero(req); 440 443 441 444 /* Extract the decrypted packet length */ 442 - if (skb_copy_bits(skb, sp->offset, &sechdr, sizeof(sechdr)) < 0) { 443 - aborted = rxrpc_abort_eproto(call, skb, "rxkad_1_len", "XV1", 444 - RXKADDATALEN); 445 - goto protocol_error; 446 - } 445 + if (skb_copy_bits(skb, sp->offset, &sechdr, sizeof(sechdr)) < 0) 446 + return rxrpc_abort_eproto(call, skb, RXKADDATALEN, 447 + rxkad_abort_1_short_encdata); 447 448 sp->offset += sizeof(sechdr); 448 449 sp->len -= sizeof(sechdr); 449 450 ··· 451 456 check = buf >> 16; 452 457 check ^= seq ^ call->call_id; 453 458 check &= 0xffff; 454 - if (check != 0) { 455 - aborted = rxrpc_abort_eproto(call, skb, "rxkad_1_check", "V1C", 456 - RXKADSEALEDINCON); 457 - goto protocol_error; 458 - } 459 - 460 - if (data_size > sp->len) { 461 - aborted = rxrpc_abort_eproto(call, skb, "rxkad_1_datalen", "V1L", 462 - RXKADDATALEN); 463 - goto protocol_error; 464 - } 459 + if (check != 0) 460 + return rxrpc_abort_eproto(call, skb, RXKADSEALEDINCON, 461 + rxkad_abort_1_short_check); 462 + if (data_size > sp->len) 463 + return rxrpc_abort_eproto(call, skb, RXKADDATALEN, 464 + rxkad_abort_1_short_data); 465 465 sp->len = data_size; 466 466 467 467 _leave(" = 0 [dlen=%x]", data_size); 468 468 return 0; 469 - 470 - protocol_error: 471 - if (aborted) 472 - rxrpc_send_abort_packet(call); 473 - return -EPROTO; 474 469 } 475 470 476 471 /* ··· 475 490 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 476 491 struct rxrpc_crypt iv; 477 492 struct scatterlist _sg[4], *sg; 478 - bool aborted; 479 493 u32 data_size, buf; 480 494 u16 check; 481 495 int nsg, ret; 482 496 483 497 _enter(",{%d}", sp->len); 484 498 485 - if (sp->len < 8) { 486 - aborted = rxrpc_abort_eproto(call, skb, "rxkad_2_hdr", "V2H", 487 - RXKADSEALEDINCON); 488 - goto protocol_error; 489 - } 499 + if (sp->len < 8) 500 + return rxrpc_abort_eproto(call, skb, RXKADSEALEDINCON, 501 + rxkad_abort_2_short_header); 490 502 491 503 /* Decrypt the skbuff in-place. TODO: We really want to decrypt 492 504 * directly into the target buffer. ··· 495 513 } else { 496 514 sg = kmalloc_array(nsg, sizeof(*sg), GFP_NOIO); 497 515 if (!sg) 498 - goto nomem; 516 + return -ENOMEM; 499 517 } 500 518 501 519 sg_init_table(sg, nsg); ··· 519 537 kfree(sg); 520 538 521 539 /* Extract the decrypted packet length */ 522 - if (skb_copy_bits(skb, sp->offset, &sechdr, sizeof(sechdr)) < 0) { 523 - aborted = rxrpc_abort_eproto(call, skb, "rxkad_2_len", "XV2", 524 - RXKADDATALEN); 525 - goto protocol_error; 526 - } 540 + if (skb_copy_bits(skb, sp->offset, &sechdr, sizeof(sechdr)) < 0) 541 + return rxrpc_abort_eproto(call, skb, RXKADDATALEN, 542 + rxkad_abort_2_short_len); 527 543 sp->offset += sizeof(sechdr); 528 544 sp->len -= sizeof(sechdr); 529 545 ··· 531 551 check = buf >> 16; 532 552 check ^= seq ^ call->call_id; 533 553 check &= 0xffff; 534 - if (check != 0) { 535 - aborted = rxrpc_abort_eproto(call, skb, "rxkad_2_check", "V2C", 536 - RXKADSEALEDINCON); 537 - goto protocol_error; 538 - } 554 + if (check != 0) 555 + return rxrpc_abort_eproto(call, skb, RXKADSEALEDINCON, 556 + rxkad_abort_2_short_check); 539 557 540 - if (data_size > sp->len) { 541 - aborted = rxrpc_abort_eproto(call, skb, "rxkad_2_datalen", "V2L", 542 - RXKADDATALEN); 543 - goto protocol_error; 544 - } 558 + if (data_size > sp->len) 559 + return rxrpc_abort_eproto(call, skb, RXKADDATALEN, 560 + rxkad_abort_2_short_data); 545 561 546 562 sp->len = data_size; 547 563 _leave(" = 0 [dlen=%x]", data_size); 548 564 return 0; 549 - 550 - protocol_error: 551 - if (aborted) 552 - rxrpc_send_abort_packet(call); 553 - return -EPROTO; 554 - 555 - nomem: 556 - _leave(" = -ENOMEM"); 557 - return -ENOMEM; 558 565 } 559 566 560 567 /* ··· 557 590 __be32 buf[2]; 558 591 } crypto __aligned(8); 559 592 rxrpc_seq_t seq = sp->hdr.seq; 560 - bool aborted; 561 593 int ret; 562 594 u16 cksum; 563 595 u32 x, y; ··· 593 627 cksum = 1; /* zero checksums are not permitted */ 594 628 595 629 if (cksum != sp->hdr.cksum) { 596 - aborted = rxrpc_abort_eproto(call, skb, "rxkad_csum", "VCK", 597 - RXKADSEALEDINCON); 598 - goto protocol_error; 630 + ret = rxrpc_abort_eproto(call, skb, RXKADSEALEDINCON, 631 + rxkad_abort_bad_checksum); 632 + goto out; 599 633 } 600 634 601 635 switch (call->conn->security_level) { ··· 613 647 break; 614 648 } 615 649 650 + out: 616 651 skcipher_request_free(req); 617 652 return ret; 618 - 619 - protocol_error: 620 - if (aborted) 621 - rxrpc_send_abort_packet(call); 622 - return -EPROTO; 623 653 } 624 654 625 655 /* ··· 789 827 struct rxkad_challenge challenge; 790 828 struct rxkad_response *resp; 791 829 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 792 - const char *eproto; 793 - u32 version, nonce, min_level, abort_code; 794 - int ret; 830 + u32 version, nonce, min_level; 831 + int ret = -EPROTO; 795 832 796 833 _enter("{%d,%x}", conn->debug_id, key_serial(conn->key)); 797 834 798 - eproto = tracepoint_string("chall_no_key"); 799 - abort_code = RX_PROTOCOL_ERROR; 800 835 if (!conn->key) 801 - goto protocol_error; 836 + return rxrpc_abort_conn(conn, skb, RX_PROTOCOL_ERROR, -EPROTO, 837 + rxkad_abort_chall_no_key); 802 838 803 - abort_code = RXKADEXPIRED; 804 839 ret = key_validate(conn->key); 805 840 if (ret < 0) 806 - goto other_error; 841 + return rxrpc_abort_conn(conn, skb, RXKADEXPIRED, ret, 842 + rxkad_abort_chall_key_expired); 807 843 808 - eproto = tracepoint_string("chall_short"); 809 - abort_code = RXKADPACKETSHORT; 810 844 if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header), 811 845 &challenge, sizeof(challenge)) < 0) 812 - goto protocol_error; 846 + return rxrpc_abort_conn(conn, skb, RXKADPACKETSHORT, -EPROTO, 847 + rxkad_abort_chall_short); 813 848 814 849 version = ntohl(challenge.version); 815 850 nonce = ntohl(challenge.nonce); ··· 814 855 815 856 trace_rxrpc_rx_challenge(conn, sp->hdr.serial, version, nonce, min_level); 816 857 817 - eproto = tracepoint_string("chall_ver"); 818 - abort_code = RXKADINCONSISTENCY; 819 858 if (version != RXKAD_VERSION) 820 - goto protocol_error; 859 + return rxrpc_abort_conn(conn, skb, RXKADINCONSISTENCY, -EPROTO, 860 + rxkad_abort_chall_version); 821 861 822 - abort_code = RXKADLEVELFAIL; 823 - ret = -EACCES; 824 862 if (conn->security_level < min_level) 825 - goto other_error; 863 + return rxrpc_abort_conn(conn, skb, RXKADLEVELFAIL, -EACCES, 864 + rxkad_abort_chall_level); 826 865 827 866 token = conn->key->payload.data[0]; 828 867 ··· 849 892 ret = rxkad_send_response(conn, &sp->hdr, resp, token->kad); 850 893 kfree(resp); 851 894 return ret; 852 - 853 - protocol_error: 854 - trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto); 855 - ret = -EPROTO; 856 - other_error: 857 - rxrpc_abort_conn(conn, skb, abort_code, ret, "RXK"); 858 - return ret; 859 895 } 860 896 861 897 /* ··· 862 912 time64_t *_expiry) 863 913 { 864 914 struct skcipher_request *req; 865 - struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 866 915 struct rxrpc_crypt iv, key; 867 916 struct scatterlist sg[1]; 868 917 struct in_addr addr; 869 918 unsigned int life; 870 - const char *eproto; 871 919 time64_t issue, now; 872 920 bool little_endian; 873 - int ret; 874 - u32 abort_code; 875 921 u8 *p, *q, *name, *end; 876 922 877 923 _enter("{%d},{%x}", conn->debug_id, key_serial(server_key)); ··· 879 933 880 934 memcpy(&iv, &server_key->payload.data[2], sizeof(iv)); 881 935 882 - ret = -ENOMEM; 883 936 req = skcipher_request_alloc(server_key->payload.data[0], GFP_NOFS); 884 937 if (!req) 885 - goto temporary_error; 938 + return -ENOMEM; 886 939 887 940 sg_init_one(&sg[0], ticket, ticket_len); 888 941 skcipher_request_set_callback(req, 0, NULL, NULL); ··· 892 947 p = ticket; 893 948 end = p + ticket_len; 894 949 895 - #define Z(field) \ 896 - ({ \ 897 - u8 *__str = p; \ 898 - eproto = tracepoint_string("rxkad_bad_"#field); \ 899 - q = memchr(p, 0, end - p); \ 900 - if (!q || q - p > (field##_SZ)) \ 901 - goto bad_ticket; \ 902 - for (; p < q; p++) \ 903 - if (!isprint(*p)) \ 904 - goto bad_ticket; \ 905 - p++; \ 906 - __str; \ 950 + #define Z(field, fieldl) \ 951 + ({ \ 952 + u8 *__str = p; \ 953 + q = memchr(p, 0, end - p); \ 954 + if (!q || q - p > field##_SZ) \ 955 + return rxrpc_abort_conn( \ 956 + conn, skb, RXKADBADTICKET, -EPROTO, \ 957 + rxkad_abort_resp_tkt_##fieldl); \ 958 + for (; p < q; p++) \ 959 + if (!isprint(*p)) \ 960 + return rxrpc_abort_conn( \ 961 + conn, skb, RXKADBADTICKET, -EPROTO, \ 962 + rxkad_abort_resp_tkt_##fieldl); \ 963 + p++; \ 964 + __str; \ 907 965 }) 908 966 909 967 /* extract the ticket flags */ ··· 915 967 p++; 916 968 917 969 /* extract the authentication name */ 918 - name = Z(ANAME); 970 + name = Z(ANAME, aname); 919 971 _debug("KIV ANAME: %s", name); 920 972 921 973 /* extract the principal's instance */ 922 - name = Z(INST); 974 + name = Z(INST, inst); 923 975 _debug("KIV INST : %s", name); 924 976 925 977 /* extract the principal's authentication domain */ 926 - name = Z(REALM); 978 + name = Z(REALM, realm); 927 979 _debug("KIV REALM: %s", name); 928 980 929 - eproto = tracepoint_string("rxkad_bad_len"); 930 981 if (end - p < 4 + 8 + 4 + 2) 931 - goto bad_ticket; 982 + return rxrpc_abort_conn(conn, skb, RXKADBADTICKET, -EPROTO, 983 + rxkad_abort_resp_tkt_short); 932 984 933 985 /* get the IPv4 address of the entity that requested the ticket */ 934 986 memcpy(&addr, p, sizeof(addr)); ··· 960 1012 _debug("KIV ISSUE: %llx [%llx]", issue, now); 961 1013 962 1014 /* check the ticket is in date */ 963 - if (issue > now) { 964 - abort_code = RXKADNOAUTH; 965 - ret = -EKEYREJECTED; 966 - goto other_error; 967 - } 968 - 969 - if (issue < now - life) { 970 - abort_code = RXKADEXPIRED; 971 - ret = -EKEYEXPIRED; 972 - goto other_error; 973 - } 1015 + if (issue > now) 1016 + return rxrpc_abort_conn(conn, skb, RXKADNOAUTH, -EKEYREJECTED, 1017 + rxkad_abort_resp_tkt_future); 1018 + if (issue < now - life) 1019 + return rxrpc_abort_conn(conn, skb, RXKADEXPIRED, -EKEYEXPIRED, 1020 + rxkad_abort_resp_tkt_expired); 974 1021 975 1022 *_expiry = issue + life; 976 1023 977 1024 /* get the service name */ 978 - name = Z(SNAME); 1025 + name = Z(SNAME, sname); 979 1026 _debug("KIV SNAME: %s", name); 980 1027 981 1028 /* get the service instance name */ 982 - name = Z(INST); 1029 + name = Z(INST, sinst); 983 1030 _debug("KIV SINST: %s", name); 984 1031 return 0; 985 - 986 - bad_ticket: 987 - trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto); 988 - abort_code = RXKADBADTICKET; 989 - ret = -EPROTO; 990 - other_error: 991 - return rxrpc_abort_conn(conn, skb, abort_code, ret, "RXK"); 992 - temporary_error: 993 - return ret; 994 1032 } 995 1033 996 1034 /* ··· 1023 1089 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 1024 1090 struct rxrpc_crypt session_key; 1025 1091 struct key *server_key; 1026 - const char *eproto; 1027 1092 time64_t expiry; 1028 1093 void *ticket; 1029 - u32 abort_code, version, kvno, ticket_len, level; 1094 + u32 version, kvno, ticket_len, level; 1030 1095 __be32 csum; 1031 1096 int ret, i; 1032 1097 ··· 1033 1100 1034 1101 server_key = rxrpc_look_up_server_security(conn, skb, 0, 0); 1035 1102 if (IS_ERR(server_key)) { 1036 - switch (PTR_ERR(server_key)) { 1103 + ret = PTR_ERR(server_key); 1104 + switch (ret) { 1037 1105 case -ENOKEY: 1038 - abort_code = RXKADUNKNOWNKEY; 1039 - break; 1106 + return rxrpc_abort_conn(conn, skb, RXKADUNKNOWNKEY, ret, 1107 + rxkad_abort_resp_nokey); 1040 1108 case -EKEYEXPIRED: 1041 - abort_code = RXKADEXPIRED; 1042 - break; 1109 + return rxrpc_abort_conn(conn, skb, RXKADEXPIRED, ret, 1110 + rxkad_abort_resp_key_expired); 1043 1111 default: 1044 - abort_code = RXKADNOAUTH; 1045 - break; 1112 + return rxrpc_abort_conn(conn, skb, RXKADNOAUTH, ret, 1113 + rxkad_abort_resp_key_rejected); 1046 1114 } 1047 - return rxrpc_abort_conn(conn, skb, abort_code, 1048 - PTR_ERR(server_key), "RXK"); 1049 1115 } 1050 1116 1051 1117 ret = -ENOMEM; ··· 1052 1120 if (!response) 1053 1121 goto temporary_error; 1054 1122 1055 - eproto = tracepoint_string("rxkad_rsp_short"); 1056 - abort_code = RXKADPACKETSHORT; 1057 1123 if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header), 1058 - response, sizeof(*response)) < 0) 1124 + response, sizeof(*response)) < 0) { 1125 + rxrpc_abort_conn(conn, skb, RXKADPACKETSHORT, -EPROTO, 1126 + rxkad_abort_resp_short); 1059 1127 goto protocol_error; 1128 + } 1060 1129 1061 1130 version = ntohl(response->version); 1062 1131 ticket_len = ntohl(response->ticket_len); ··· 1065 1132 1066 1133 trace_rxrpc_rx_response(conn, sp->hdr.serial, version, kvno, ticket_len); 1067 1134 1068 - eproto = tracepoint_string("rxkad_rsp_ver"); 1069 - abort_code = RXKADINCONSISTENCY; 1070 - if (version != RXKAD_VERSION) 1135 + if (version != RXKAD_VERSION) { 1136 + rxrpc_abort_conn(conn, skb, RXKADINCONSISTENCY, -EPROTO, 1137 + rxkad_abort_resp_version); 1071 1138 goto protocol_error; 1139 + } 1072 1140 1073 - eproto = tracepoint_string("rxkad_rsp_tktlen"); 1074 - abort_code = RXKADTICKETLEN; 1075 - if (ticket_len < 4 || ticket_len > MAXKRB5TICKETLEN) 1141 + if (ticket_len < 4 || ticket_len > MAXKRB5TICKETLEN) { 1142 + rxrpc_abort_conn(conn, skb, RXKADTICKETLEN, -EPROTO, 1143 + rxkad_abort_resp_tkt_len); 1076 1144 goto protocol_error; 1145 + } 1077 1146 1078 - eproto = tracepoint_string("rxkad_rsp_unkkey"); 1079 - abort_code = RXKADUNKNOWNKEY; 1080 - if (kvno >= RXKAD_TKT_TYPE_KERBEROS_V5) 1147 + if (kvno >= RXKAD_TKT_TYPE_KERBEROS_V5) { 1148 + rxrpc_abort_conn(conn, skb, RXKADUNKNOWNKEY, -EPROTO, 1149 + rxkad_abort_resp_unknown_tkt); 1081 1150 goto protocol_error; 1151 + } 1082 1152 1083 1153 /* extract the kerberos ticket and decrypt and decode it */ 1084 1154 ret = -ENOMEM; ··· 1089 1153 if (!ticket) 1090 1154 goto temporary_error_free_resp; 1091 1155 1092 - eproto = tracepoint_string("rxkad_tkt_short"); 1093 - abort_code = RXKADPACKETSHORT; 1094 - ret = skb_copy_bits(skb, sizeof(struct rxrpc_wire_header) + sizeof(*response), 1095 - ticket, ticket_len); 1096 - if (ret < 0) 1097 - goto temporary_error_free_ticket; 1156 + if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header) + sizeof(*response), 1157 + ticket, ticket_len) < 0) { 1158 + rxrpc_abort_conn(conn, skb, RXKADPACKETSHORT, -EPROTO, 1159 + rxkad_abort_resp_short_tkt); 1160 + goto protocol_error; 1161 + } 1098 1162 1099 1163 ret = rxkad_decrypt_ticket(conn, server_key, skb, ticket, ticket_len, 1100 1164 &session_key, &expiry); ··· 1105 1169 * response */ 1106 1170 rxkad_decrypt_response(conn, response, &session_key); 1107 1171 1108 - eproto = tracepoint_string("rxkad_rsp_param"); 1109 - abort_code = RXKADSEALEDINCON; 1110 - if (ntohl(response->encrypted.epoch) != conn->proto.epoch) 1172 + if (ntohl(response->encrypted.epoch) != conn->proto.epoch || 1173 + ntohl(response->encrypted.cid) != conn->proto.cid || 1174 + ntohl(response->encrypted.securityIndex) != conn->security_ix) { 1175 + rxrpc_abort_conn(conn, skb, RXKADSEALEDINCON, -EPROTO, 1176 + rxkad_abort_resp_bad_param); 1111 1177 goto protocol_error_free; 1112 - if (ntohl(response->encrypted.cid) != conn->proto.cid) 1113 - goto protocol_error_free; 1114 - if (ntohl(response->encrypted.securityIndex) != conn->security_ix) 1115 - goto protocol_error_free; 1178 + } 1179 + 1116 1180 csum = response->encrypted.checksum; 1117 1181 response->encrypted.checksum = 0; 1118 1182 rxkad_calc_response_checksum(response); 1119 - eproto = tracepoint_string("rxkad_rsp_csum"); 1120 - if (response->encrypted.checksum != csum) 1183 + if (response->encrypted.checksum != csum) { 1184 + rxrpc_abort_conn(conn, skb, RXKADSEALEDINCON, -EPROTO, 1185 + rxkad_abort_resp_bad_checksum); 1121 1186 goto protocol_error_free; 1187 + } 1122 1188 1123 1189 spin_lock(&conn->bundle->channel_lock); 1124 1190 for (i = 0; i < RXRPC_MAXCALLS; i++) { 1125 1191 struct rxrpc_call *call; 1126 1192 u32 call_id = ntohl(response->encrypted.call_id[i]); 1127 1193 1128 - eproto = tracepoint_string("rxkad_rsp_callid"); 1129 - if (call_id > INT_MAX) 1194 + if (call_id > INT_MAX) { 1195 + rxrpc_abort_conn(conn, skb, RXKADSEALEDINCON, -EPROTO, 1196 + rxkad_abort_resp_bad_callid); 1130 1197 goto protocol_error_unlock; 1198 + } 1131 1199 1132 - eproto = tracepoint_string("rxkad_rsp_callctr"); 1133 - if (call_id < conn->channels[i].call_counter) 1200 + if (call_id < conn->channels[i].call_counter) { 1201 + rxrpc_abort_conn(conn, skb, RXKADSEALEDINCON, -EPROTO, 1202 + rxkad_abort_resp_call_ctr); 1134 1203 goto protocol_error_unlock; 1204 + } 1135 1205 1136 - eproto = tracepoint_string("rxkad_rsp_callst"); 1137 1206 if (call_id > conn->channels[i].call_counter) { 1138 1207 call = rcu_dereference_protected( 1139 1208 conn->channels[i].call, 1140 1209 lockdep_is_held(&conn->bundle->channel_lock)); 1141 - if (call && call->state < RXRPC_CALL_COMPLETE) 1210 + if (call && call->state < RXRPC_CALL_COMPLETE) { 1211 + rxrpc_abort_conn(conn, skb, RXKADSEALEDINCON, -EPROTO, 1212 + rxkad_abort_resp_call_state); 1142 1213 goto protocol_error_unlock; 1214 + } 1143 1215 conn->channels[i].call_counter = call_id; 1144 1216 } 1145 1217 } 1146 1218 spin_unlock(&conn->bundle->channel_lock); 1147 1219 1148 - eproto = tracepoint_string("rxkad_rsp_seq"); 1149 - abort_code = RXKADOUTOFSEQUENCE; 1150 - if (ntohl(response->encrypted.inc_nonce) != conn->rxkad.nonce + 1) 1220 + if (ntohl(response->encrypted.inc_nonce) != conn->rxkad.nonce + 1) { 1221 + rxrpc_abort_conn(conn, skb, RXKADOUTOFSEQUENCE, -EPROTO, 1222 + rxkad_abort_resp_ooseq); 1151 1223 goto protocol_error_free; 1224 + } 1152 1225 1153 - eproto = tracepoint_string("rxkad_rsp_level"); 1154 - abort_code = RXKADLEVELFAIL; 1155 1226 level = ntohl(response->encrypted.level); 1156 - if (level > RXRPC_SECURITY_ENCRYPT) 1227 + if (level > RXRPC_SECURITY_ENCRYPT) { 1228 + rxrpc_abort_conn(conn, skb, RXKADLEVELFAIL, -EPROTO, 1229 + rxkad_abort_resp_level); 1157 1230 goto protocol_error_free; 1231 + } 1158 1232 conn->security_level = level; 1159 1233 1160 1234 /* create a key to hold the security data and expiration time - after ··· 1186 1240 protocol_error: 1187 1241 kfree(response); 1188 1242 key_put(server_key); 1189 - trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto); 1190 - return rxrpc_abort_conn(conn, skb, abort_code, -EPROTO, "RXK"); 1243 + return -EPROTO; 1191 1244 1192 1245 temporary_error_free_ticket: 1193 1246 kfree(ticket);
+12 -5
net/rxrpc/rxperf.c
··· 10 10 #include <linux/slab.h> 11 11 #include <net/sock.h> 12 12 #include <net/af_rxrpc.h> 13 + #define RXRPC_TRACE_ONLY_DEFINE_ENUMS 14 + #include <trace/events/rxrpc.h> 13 15 14 16 MODULE_DESCRIPTION("rxperf test server (afs)"); 15 17 MODULE_AUTHOR("Red Hat, Inc."); ··· 309 307 case -EOPNOTSUPP: 310 308 abort_code = RXGEN_OPCODE; 311 309 rxrpc_kernel_abort_call(rxperf_socket, call->rxcall, 312 - abort_code, ret, "GOP"); 310 + abort_code, ret, 311 + rxperf_abort_op_not_supported); 313 312 goto call_complete; 314 313 case -ENOTSUPP: 315 314 abort_code = RX_USER_ABORT; 316 315 rxrpc_kernel_abort_call(rxperf_socket, call->rxcall, 317 - abort_code, ret, "GUA"); 316 + abort_code, ret, 317 + rxperf_abort_op_not_supported); 318 318 goto call_complete; 319 319 case -EIO: 320 320 pr_err("Call %u in bad state %u\n", ··· 328 324 case -ENOMEM: 329 325 case -EFAULT: 330 326 rxrpc_kernel_abort_call(rxperf_socket, call->rxcall, 331 - RXGEN_SS_UNMARSHAL, ret, "GUM"); 327 + RXGEN_SS_UNMARSHAL, ret, 328 + rxperf_abort_unmarshal_error); 332 329 goto call_complete; 333 330 default: 334 331 rxrpc_kernel_abort_call(rxperf_socket, call->rxcall, 335 - RX_CALL_DEAD, ret, "GER"); 332 + RX_CALL_DEAD, ret, 333 + rxperf_abort_general_error); 336 334 goto call_complete; 337 335 } 338 336 } ··· 529 523 530 524 if (n == -ENOMEM) 531 525 rxrpc_kernel_abort_call(rxperf_socket, call->rxcall, 532 - RXGEN_SS_MARSHAL, -ENOMEM, "GOM"); 526 + RXGEN_SS_MARSHAL, -ENOMEM, 527 + rxperf_abort_oom); 533 528 return n; 534 529 } 535 530
+4 -10
net/rxrpc/security.c
··· 144 144 145 145 sec = rxrpc_security_lookup(sp->hdr.securityIndex); 146 146 if (!sec) { 147 - trace_rxrpc_abort(0, "SVS", 148 - sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 149 - RX_INVALID_OPERATION, EKEYREJECTED); 150 - skb->mark = RXRPC_SKB_MARK_REJECT_ABORT; 151 - skb->priority = RX_INVALID_OPERATION; 147 + rxrpc_direct_abort(skb, rxrpc_abort_unsupported_security, 148 + RX_INVALID_OPERATION, -EKEYREJECTED); 152 149 return NULL; 153 150 } 154 151 155 152 if (sp->hdr.securityIndex != RXRPC_SECURITY_NONE && 156 153 !rx->securities) { 157 - trace_rxrpc_abort(0, "SVR", 158 - sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq, 159 - RX_INVALID_OPERATION, EKEYREJECTED); 160 - skb->mark = RXRPC_SKB_MARK_REJECT_ABORT; 161 - skb->priority = sec->no_key_abort; 154 + rxrpc_direct_abort(skb, rxrpc_abort_no_service_key, 155 + sec->no_key_abort, -EKEYREJECTED); 162 156 return NULL; 163 157 } 164 158
+12 -8
net/rxrpc/sendmsg.c
··· 20 20 /* 21 21 * Propose an abort to be made in the I/O thread. 22 22 */ 23 - bool rxrpc_propose_abort(struct rxrpc_call *call, 24 - u32 abort_code, int error, const char *why) 23 + bool rxrpc_propose_abort(struct rxrpc_call *call, s32 abort_code, int error, 24 + enum rxrpc_abort_reason why) 25 25 { 26 - _enter("{%d},%d,%d,%s", call->debug_id, abort_code, error, why); 26 + _enter("{%d},%d,%d,%u", call->debug_id, abort_code, error, why); 27 27 28 28 if (!call->send_abort && call->state < RXRPC_CALL_COMPLETE) { 29 29 call->send_abort_why = why; 30 30 call->send_abort_err = error; 31 + call->send_abort_seq = 0; 31 32 /* Request abort locklessly vs rxrpc_input_call_event(). */ 32 33 smp_store_release(&call->send_abort, abort_code); 33 34 rxrpc_poke_call(call, rxrpc_call_poke_abort); ··· 684 683 /* it's too late for this call */ 685 684 ret = -ESHUTDOWN; 686 685 } else if (p.command == RXRPC_CMD_SEND_ABORT) { 687 - rxrpc_propose_abort(call, p.abort_code, -ECONNABORTED, "CMD"); 686 + rxrpc_propose_abort(call, p.abort_code, -ECONNABORTED, 687 + rxrpc_abort_call_sendmsg); 688 688 ret = 0; 689 689 } else if (p.command != RXRPC_CMD_SEND_DATA) { 690 690 ret = -EINVAL; ··· 750 748 break; 751 749 default: 752 750 /* Request phase complete for this client call */ 753 - trace_rxrpc_rx_eproto(call, 0, tracepoint_string("late_send")); 751 + trace_rxrpc_abort(call->debug_id, rxrpc_sendmsg_late_send, 752 + call->cid, call->call_id, call->rx_consumed, 753 + 0, -EPROTO); 754 754 ret = -EPROTO; 755 755 break; 756 756 } ··· 770 766 * @call: The call to be aborted 771 767 * @abort_code: The abort code to stick into the ABORT packet 772 768 * @error: Local error value 773 - * @why: 3-char string indicating why. 769 + * @why: Indication as to why. 774 770 * 775 771 * Allow a kernel service to abort a call, if it's still in an abortable state 776 772 * and return true if the call was aborted, false if it was already complete. 777 773 */ 778 774 bool rxrpc_kernel_abort_call(struct socket *sock, struct rxrpc_call *call, 779 - u32 abort_code, int error, const char *why) 775 + u32 abort_code, int error, enum rxrpc_abort_reason why) 780 776 { 781 777 bool aborted; 782 778 783 - _enter("{%d},%d,%d,%s", call->debug_id, abort_code, error, why); 779 + _enter("{%d},%d,%d,%u", call->debug_id, abort_code, error, why); 784 780 785 781 mutex_lock(&call->user_mutex); 786 782 aborted = rxrpc_propose_abort(call, abort_code, error, why);