2017-04-21 10:43:26 +00:00
|
|
|
/*
|
2021-09-18 08:05:45 +00:00
|
|
|
* Copyright (C) 2017-2021 THL A29 Limited, a Tencent company.
|
2017-04-21 10:43:26 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _FSTACK_VETH_H
|
|
|
|
#define _FSTACK_VETH_H
|
|
|
|
|
|
|
|
struct ff_port_cfg;
|
|
|
|
void *ff_veth_attach(struct ff_port_cfg *cfg);
|
|
|
|
int ff_veth_detach(void *arg);
|
|
|
|
|
2017-05-06 13:52:25 +00:00
|
|
|
void *ff_mbuf_gethdr(void *pkt, uint16_t total, void *data,
|
|
|
|
uint16_t len, uint8_t rx_csum);
|
fix use after free issue in mbuf free
Two kinds of mbuf are used in f-stack: freebsd mbuf and dpdk mbuf.
freebsd mbufs are metadata used in freebsd stack, and their data
pointers (m_data) point to dpdk mbuf's data (buf_addr). And they have
their own chain, like this:
bsd_mbuf1 -> bsd_mbuf2 -> bsd_mbuf3
\ \ \
dpdk_mbuf1 -> dpdk_mbuf2 -> dpdk_mbuf3
Considering the map relationship,
- m_freem() is corresponding to rte_pktmbuf_free(), is to free the whole
chain of mbufs.
- m_free() is corresponding to rte_pktmbuf_free_seg(), is to free the
specified mbuf segment.
The current implementation in f-stack uses rte_pktmbuf_free() for
m_free(). This leads to mbufs, which are still in use, be freed
unexpectedly. For example, if the bsd_mbuf1 is trimed into zero length,
bsd will invoke m_free() to free the specified segment, however, the
whole mbuf chain is freed by calling rte_pktmbuf_free().
#0 rte_pktmbuf_free (m=0x22006fb480)
#1 in ff_dpdk_pktmbuf_free (m=0x22006fb480)
#2 in ff_mbuf_ext_free (m=0x7ffff7f82800, arg1=0x22006fb480, arg2=0x0)
#3 in mb_free_ext (m=0x7ffff7f82800)
#4 in m_free (m=0x7ffff7f82800)
#5 in sbcompress (sb=, m=0x7ffff7f82800, n=)
#6 in sbappendstream_locked (sb=, m=0x7ffff7f82800, flags=0)
The fix is straightforward. Use the correct API for segment free.
Reported-by: Yong-Hao Zou <yonghaoz1994@gmail.com>
Signed-off-by: Jianfeng Tan <henry.tjf@antgroup.com>
2020-11-27 06:45:00 +00:00
|
|
|
void *ff_mbuf_get(void *p, void *m, void *data, uint16_t len);
|
2017-04-21 10:43:26 +00:00
|
|
|
void ff_mbuf_free(void *m);
|
|
|
|
|
|
|
|
int ff_mbuf_copydata(void *m, void *data, int off, int len);
|
2019-03-29 02:42:02 +00:00
|
|
|
int ff_next_mbuf(void **mbuf_bsd, void **data, unsigned *len);
|
|
|
|
void* ff_mbuf_mtod(void* bsd_mbuf);
|
|
|
|
void* ff_rte_frm_extcl(void* mbuf);
|
2017-04-21 10:43:26 +00:00
|
|
|
|
2017-05-06 13:52:25 +00:00
|
|
|
struct ff_tx_offload;
|
|
|
|
void ff_mbuf_tx_offload(void *m, struct ff_tx_offload *offload);
|
|
|
|
|
2017-04-21 10:43:26 +00:00
|
|
|
void ff_veth_process_packet(void *arg, void *m);
|
|
|
|
|
2017-08-28 08:51:06 +00:00
|
|
|
void *ff_veth_softc_to_hostc(void *softc);
|
|
|
|
|
2019-07-09 11:56:16 +00:00
|
|
|
void ff_mbuf_set_vlan_info(void *hdr, uint16_t vlan_tci);
|
2017-04-21 10:43:26 +00:00
|
|
|
|
|
|
|
#endif /* ifndef _FSTACK_VETH_H */
|