/* * Kernel Connection Multiplexor * * Copyright (c) 2016 Tom Herbert * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. */ #ifndef __NET_KCM_H_ #define __NET_KCM_H_ #include #include #include #include extern unsigned int kcm_net_id; #define KCM_STATS_ADD(stat, count) ((stat) += (count)) #define KCM_STATS_INCR(stat) ((stat)++) struct kcm_psock_stats { unsigned long long tx_msgs; unsigned long long tx_bytes; unsigned long long reserved; unsigned long long unreserved; unsigned int tx_aborts; }; struct kcm_mux_stats { unsigned long long rx_msgs; unsigned long long rx_bytes; unsigned long long tx_msgs; unsigned long long tx_bytes; unsigned int rx_ready_drops; unsigned int tx_retries; unsigned int psock_attach; unsigned int psock_unattach_rsvd; unsigned int psock_unattach; }; struct kcm_stats { unsigned long long rx_msgs; unsigned long long rx_bytes; unsigned long long tx_msgs; unsigned long long tx_bytes; }; struct kcm_tx_msg { unsigned int sent; unsigned int fragidx; unsigned int frag_offset; unsigned int msg_flags; struct sk_buff *frag_skb; struct sk_buff *last_skb; }; /* Socket structure for KCM client sockets */ struct kcm_sock { struct sock sk; struct kcm_mux *mux; struct list_head kcm_sock_list; int index; u32 done : 1; struct work_struct done_work; struct kcm_stats stats; /* Transmit */ struct kcm_psock *tx_psock; struct work_struct tx_work; struct list_head wait_psock_list; struct sk_buff *seq_skb; u32 tx_stopped : 1; /* Don't use bit fields here, these are set under different locks */ bool tx_wait; bool tx_wait_more; /* Receive */ struct kcm_psock *rx_psock; struct list_head wait_rx_list; /* KCMs waiting for receiving */ bool rx_wait; u32 rx_disabled : 1; }; struct bpf_prog; /* Structure for an attached lower socket */ struct kcm_psock { struct sock *sk; struct strparser strp; struct kcm_mux *mux; int index; u32 tx_stopped : 1; u32 done : 1; u32 unattaching : 1; void (*save_state_change)(struct sock *sk); void (*save_data_ready)(struct sock *sk); void (*save_write_space)(struct sock *sk); struct list_head psock_list; struct kcm_psock_stats stats; /* Receive */ struct list_head psock_ready_list; struct bpf_prog *bpf_prog; struct kcm_sock *rx_kcm; unsigned long long saved_rx_bytes; unsigned long long saved_rx_msgs; struct sk_buff *ready_rx_msg; /* Transmit */ struct kcm_sock *tx_kcm; struct list_head psock_avail_list; unsigned long long saved_tx_bytes; unsigned long long saved_tx_msgs; }; /* Per net MUX list */ struct kcm_net { struct mutex mutex; struct kcm_psock_stats aggregate_psock_stats; struct kcm_mux_stats aggregate_mux_stats; struct strp_aggr_stats aggregate_strp_stats; struct list_head mux_list; int count; }; /* Structure for a MUX */ struct kcm_mux { struct list_head kcm_mux_list; struct rcu_head rcu; struct kcm_net *knet; struct list_head kcm_socks; /* All KCM sockets on MUX */ int kcm_socks_cnt; /* Total KCM socket count for MUX */ struct list_head psocks; /* List of all psocks on MUX */ int psocks_cnt; /* Total attached sockets */ struct kcm_mux_stats stats; struct kcm_psock_stats aggregate_psock_stats; struct strp_aggr_stats aggregate_strp_stats; /* Receive */ spinlock_t rx_lock ____cacheline_aligned_in_smp; struct list_head kcm_rx_waiters; /* KCMs waiting for receiving */ struct list_head psocks_ready; /* List of psocks with a msg ready */ struct sk_buff_head rx_hold_queue; /* Transmit */ spinlock_t lock ____cacheline_aligned_in_smp; /* TX and mux locking */ struct list_head psocks_avail; /* List of available psocks */ struct list_head kcm_tx_waiters; /* KCMs waiting for a TX psock */ }; #ifdef CONFIG_PROC_FS int kcm_proc_init(void); void kcm_proc_exit(void); #else static inline int kcm_proc_init(void) { return 0; } static inline void kcm_proc_exit(void) { } #endif static inline void aggregate_psock_stats(struct kcm_psock_stats *stats, struct kcm_psock_stats *agg_stats) { /* Save psock statistics in the mux when psock is being unattached. */ #define SAVE_PSOCK_STATS(_stat) (agg_stats->_stat += stats->_stat) SAVE_PSOCK_STATS(tx_msgs); SAVE_PSOCK_STATS(tx_bytes); SAVE_PSOCK_STATS(reserved); SAVE_PSOCK_STATS(unreserved); SAVE_PSOCK_STATS(tx_aborts); #undef SAVE_PSOCK_STATS } static inline void aggregate_mux_stats(struct kcm_mux_stats *stats, struct kcm_mux_stats *agg_stats) { /* Save psock statistics in the mux when psock is being unattached. */ #define SAVE_MUX_STATS(_stat) (agg_stats->_stat += stats->_stat) SAVE_MUX_STATS(rx_msgs); SAVE_MUX_STATS(rx_bytes); SAVE_MUX_STATS(tx_msgs); SAVE_MUX_STATS(tx_bytes); SAVE_MUX_STATS(rx_ready_drops); SAVE_MUX_STATS(psock_attach); SAVE_MUX_STATS(psock_unattach_rsvd); SAVE_MUX_STATS(psock_unattach); #undef SAVE_MUX_STATS } #endif /* __NET_KCM_H_ */ move&id=02608e02fbec04fccf2eb0cc8d8082f65c0a4286'>02608e02fbec04fccf2eb0cc8d8082f65c0a4286 (patch) tree37ff0410d130cfe77185f591b07cd6403f207f0c /include/xen parent7ce7d89f48834cefece7804d38fc5d85382edf77 (diff)
crypto: testmgr - Use heap buffer for acomp test input
Christopher Covington reported a crash on aarch64 on recent Fedora kernels: kernel BUG at ./include/linux/scatterlist.h:140! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Modules linked in: CPU: 2 PID: 752 Comm: cryptomgr_test Not tainted 4.9.0-11815-ge93b1cc #162 Hardware name: linux,dummy-virt (DT) task: ffff80007c650080 task.stack: ffff800008910000 PC is at sg_init_one+0xa0/0xb8 LR is at sg_init_one+0x24/0xb8 ... [<ffff000008398db8>] sg_init_one+0xa0/0xb8 [<ffff000008350a44>] test_acomp+0x10c/0x438 [<ffff000008350e20>] alg_test_comp+0xb0/0x118 [<ffff00000834f28c>] alg_test+0x17c/0x2f0 [<ffff00000834c6a4>] cryptomgr_test+0x44/0x50 [<ffff0000080dac70>] kthread+0xf8/0x128 [<ffff000008082ec0>] ret_from_fork+0x10/0x50 The test vectors used for input are part of the kernel image. These inputs are passed as a buffer to sg_init_one which eventually blows up with BUG_ON(!virt_addr_valid(buf)). On arm64, virt_addr_valid returns false for the kernel image since virt_to_page will not return the correct page. Fix this by copying the input vectors to heap buffer before setting up the scatterlist. Reported-by: Christopher Covington <cov@codeaurora.org> Fixes: d7db7a882deb ("crypto: acomp - update testmgr with support for acomp") Signed-off-by: Laura Abbott <labbott@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/xen')