Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vma/dev/rfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ rfs::~rfs()
delete[] m_sinks_list;

while (m_attach_flow_data_vector.size() > 0) {
delete m_attach_flow_data_vector.back();
free(m_attach_flow_data_vector.back());
m_attach_flow_data_vector.pop_back();
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/vma/dev/rfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef RFS_H
#define RFS_H

#include <stdlib.h>
#include <type_traits>
#include <vector>

#include "vma/ib/base/verbs_extra.h"
Expand Down Expand Up @@ -213,6 +215,15 @@ class rfs
virtual bool rx_dispatch_packet(mem_buf_desc_t* p_rx_wc_buf_desc, void* pv_fd_ready_array) = 0;

protected:
template <class T, typename ...Args>
T * new_malloc(Args ... args) {
static_assert(std::is_trivially_destructible<T>::value == true);
void * p = aligned_alloc(alignof(T), sizeof(T));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: aligned_alloc returns NULL on failure, but there's no null check before placement new

Suggested change
void * p = aligned_alloc(alignof(T), sizeof(T));
void * p = aligned_alloc(alignof(T), sizeof(T));
if (!p) return NULL;
return new(p) T(args...);

if (!p)
throw std::bad_alloc{};
return new(p) T(args...);
}

flow_tuple m_flow_tuple;
ring_slave* m_p_ring;
rfs_rule_filter* m_p_rule_filter;
Expand Down
6 changes: 3 additions & 3 deletions src/vma/dev/rfs_mc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool rfs_mc::prepare_flow_spec()
#ifdef DEFINED_IBV_FLOW_SPEC_IB
attach_flow_data_ib_v1_t* attach_flow_data_ib_v1 = NULL;

attach_flow_data_ib_v1 = new attach_flow_data_ib_v1_t(p_ring->m_p_qp_mgr);
attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_v1_t>(p_ring->m_p_qp_mgr);

uint8_t dst_gid[16];
Comment on lines +59 to 61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 61 causes crash

Suggested change
attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_v1_t>(p_ring->m_p_qp_mgr);
uint8_t dst_gid[16];
attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_v1_t>(p_ring->m_p_qp_mgr);
if (!attach_flow_data_ib_v1) return false;
uint8_t dst_gid[16];

create_mgid_from_ipv4_mc_ip(dst_gid, p_ring->m_p_qp_mgr->get_partiton(), m_flow_tuple.get_dst_ip());
Expand All @@ -70,7 +70,7 @@ bool rfs_mc::prepare_flow_spec()
#endif
}

attach_flow_data_ib_v2 = new attach_flow_data_ib_v2_t(p_ring->m_p_qp_mgr);
attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_v2_t>(p_ring->m_p_qp_mgr);

ibv_flow_spec_ipv4_set(&(attach_flow_data_ib_v2->ibv_flow_attr.ipv4),
Comment on lines +73 to 75
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 75 causes crash

Suggested change
attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_v2_t>(p_ring->m_p_qp_mgr);
ibv_flow_spec_ipv4_set(&(attach_flow_data_ib_v2->ibv_flow_attr.ipv4),
attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_v2_t>(p_ring->m_p_qp_mgr);
if (!attach_flow_data_ib_v2) return false;
ibv_flow_spec_ipv4_set(&(attach_flow_data_ib_v2->ibv_flow_attr.ipv4),

m_flow_tuple.get_dst_ip(),
Expand All @@ -88,7 +88,7 @@ bool rfs_mc::prepare_flow_spec()
{
attach_flow_data_eth_ipv4_tcp_udp_t* attach_flow_data_eth = NULL;

attach_flow_data_eth = new attach_flow_data_eth_ipv4_tcp_udp_t(p_ring->m_p_qp_mgr);
attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr);

uint8_t dst_mac[6];
Comment on lines +91 to 93
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 93 causes crash

Suggested change
attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr);
uint8_t dst_mac[6];
attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr);
if (!attach_flow_data_eth) return false;
uint8_t dst_mac[6];

create_multicast_mac_from_ip(dst_mac, m_flow_tuple.get_dst_ip());
Expand Down
6 changes: 3 additions & 3 deletions src/vma/dev/rfs_uc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool rfs_uc::prepare_flow_spec()
if (0 == p_ring->m_p_qp_mgr->get_underly_qpn()) {
attach_flow_data_ib_ipv4_tcp_udp_v1_t* attach_flow_data_ib_v1 = NULL;

attach_flow_data_ib_v1 = new attach_flow_data_ib_ipv4_tcp_udp_v1_t(p_ring->m_p_qp_mgr);
attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v1_t>(p_ring->m_p_qp_mgr);
ibv_flow_spec_ib_set_by_dst_qpn(&(attach_flow_data_ib_v1->ibv_flow_attr.ib),
Comment on lines +62 to 63
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 63 causes crash

Suggested change
attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v1_t>(p_ring->m_p_qp_mgr);
ibv_flow_spec_ib_set_by_dst_qpn(&(attach_flow_data_ib_v1->ibv_flow_attr.ib),
attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v1_t>(p_ring->m_p_qp_mgr);
if (!attach_flow_data_ib_v1) return false;
ibv_flow_spec_ib_set_by_dst_qpn(&(attach_flow_data_ib_v1->ibv_flow_attr.ib),

htonl(((IPoIB_addr*)p_ring->m_p_l2_addr)->get_qpn()));
p_ipv4 = &(attach_flow_data_ib_v1->ibv_flow_attr.ipv4);
Expand All @@ -68,7 +68,7 @@ bool rfs_uc::prepare_flow_spec()
break;
}
#endif
attach_flow_data_ib_v2 = new attach_flow_data_ib_ipv4_tcp_udp_v2_t(p_ring->m_p_qp_mgr);
attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v2_t>(p_ring->m_p_qp_mgr);

p_ipv4 = &(attach_flow_data_ib_v2->ibv_flow_attr.ipv4);
Comment on lines +71 to 73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 73 causes crash

Suggested change
attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v2_t>(p_ring->m_p_qp_mgr);
p_ipv4 = &(attach_flow_data_ib_v2->ibv_flow_attr.ipv4);
attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v2_t>(p_ring->m_p_qp_mgr);
if (!attach_flow_data_ib_v2) return false;
p_ipv4 = &(attach_flow_data_ib_v2->ibv_flow_attr.ipv4);

p_tcp_udp = &(attach_flow_data_ib_v2->ibv_flow_attr.tcp_udp);
Expand All @@ -77,7 +77,7 @@ bool rfs_uc::prepare_flow_spec()
}
case VMA_TRANSPORT_ETH:
{
attach_flow_data_eth = new attach_flow_data_eth_ipv4_tcp_udp_t(p_ring->m_p_qp_mgr);
attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr);

ibv_flow_spec_eth_set(&(attach_flow_data_eth->ibv_flow_attr.eth),
Comment on lines +80 to 82
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 82 causes crash

Suggested change
attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr);
ibv_flow_spec_eth_set(&(attach_flow_data_eth->ibv_flow_attr.eth),
attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr);
if (!attach_flow_data_eth) return false;
ibv_flow_spec_eth_set(&(attach_flow_data_eth->ibv_flow_attr.eth),

p_ring->m_p_l2_addr->get_address(),
Expand Down