Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compat: avoid fortify memcpy/memmove warnings on linux>=6.11 #266

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions src/include/ci/tools/sysdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ typedef ci_int32 ci_kerr_t; /* range of OS kernel-mode return codes */
#define PTR_ERR_OR_ZERO(ptr) (IS_ERR(ptr) ? PTR_ERR(ptr) : 0)
#define ERR_PTR(err) ((void*)(uintptr_t)(long)(err))

#ifndef unsafe_memcpy
#define unsafe_memcpy(dst, src, bytes, justification) memcpy(dst, src, bytes)
#endif

#ifndef unsafe_memmove
/* Unlike unsafe_memcpy(), kernel does not provide unsafe_memmove(). */
#ifdef __KERNEL__
#define unsafe_memmove(dst, src, bytes, justification) \
__underlying_memmove(dst, src, bytes)
#ifndef __underlying_memmove
/* __underlying_memmove() was undefined in linux<5.18. */
#define __underlying_memmove __builtin_memmove
#endif /* __underlying_memmove */
#else
#define unsafe_memmove(dst, src, bytes, justification) memmove(dst, src, bytes)
#endif /* __KERNEL__ */
#endif /* ! unsafe_memmove */

/**********************************************************************
* Compiler and processor dependencies.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/transport/ip/csum_copy_iovec_setlen.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ci_inline int do_copy_from_user(void* to, const void* from, int n_bytes
if( addr_spc != CI_ADDR_SPC_KERNEL )
return copy_from_user(to, from, n_bytes);
#endif
memcpy(to, from, n_bytes);
unsafe_memcpy(to, from, n_bytes, "variable length dest struct");
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/transport/ip/tcp_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,8 @@ static int ci_tcp_rx_pkt_coalesce(ci_netif* ni, ci_ip_pkt_queue* q,
/* Move contents of packet to the beginning of the buffer. */
if( oo_offbuf_ptr(pkt_buf) != pkt_payload ) {
int n = (int)(oo_offbuf_ptr(pkt_buf) - pkt_payload);
memmove(pkt_payload, oo_offbuf_ptr(pkt_buf), oo_offbuf_left(pkt_buf));
unsafe_memmove(pkt_payload, oo_offbuf_ptr(pkt_buf), oo_offbuf_left(pkt_buf),
"variable length dest struct");
pkt_buf->off -= n;
pkt_buf->end -= n;
pkt_tcp->tcp_seq_be32 = CI_BSWAP_BE32(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/transport/ip/tcp_tx_reformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ static int ci_tcp_tx_merge_segment(ci_netif* ni, ci_ip_pkt_fmt* dest_pkt,
if( do_copy ) {
if( dest_pkt == src_pkt ) {
/* Same packet: may be overlapping. */
memmove(dest, src, n);
unsafe_memmove(dest, src, n, "variable length dest struct");
}
else
memcpy(dest, src, n);
unsafe_memcpy(dest, src, n, "variable length dest struct");
}

dest_pkt->buf_len += n;
Expand Down