Skip to content

fix(tx_pool): avoid pointer arithmetic on a void * in homa_copy_iter_to_frags - #96

Open
randomizedcoder wants to merge 1 commit into
PlatformLab:mainfrom
randomizedcoder:fix/tx-pool-void-ptr-arith
Open

randomizedcoder wants to merge 1 commit into
PlatformLab:mainfrom
randomizedcoder:fix/tx-pool-void-ptr-arith

Conversation

@randomizedcoder

Copy link
Copy Markdown

Bug: pointer arithmetic on a void * in homa_copy_iter_to_frags()

u8 *vaddr = kmap_local_page(p);        /* sibling homa_copy_to_frags(): u8 * */
...
void *vaddr = kmap_local_page(p);      /* homa_copy_iter_to_frags(): void * */
result = copy_from_iter(vaddr + p_off, p_len, iter);   /* void* arithmetic */

vaddr + p_off on a void * is a GNU extension and undefined in standard C. The sibling function homa_copy_to_frags() a few lines up already declares its mapping as u8 *vaddr; this just makes the two consistent.

Fix

-			void *vaddr = kmap_local_page(p);
+			u8 *vaddr = kmap_local_page(p);

Verification (static gate + regression)

Before:  homa_tx_pool.c:534: portability: 'vaddr' is of type 'void *'. When using
         void pointers in calculations, the behaviour is undefined.
         [arithOperationsOnVoidPointer]
After:   (clean — finding gone)

cppcheck --enable=all homa_tx_pool.c. The existing homa_copy_iter_to_frags and homa_copy_to_frags unit tests both stay green (2/2) — the byte-copy behaviour is unchanged (u8 * and the previous void * arithmetic address the same bytes).

…to_frags

homa_copy_iter_to_frags() maps a page into `void *vaddr` and then does
`vaddr + p_off` when calling copy_from_iter(). Arithmetic on a void
pointer is a GNU extension and undefined in standard C (cppcheck:
arithOperationsOnVoidPointer). Its sibling homa_copy_to_frags() already
uses `u8 *vaddr`; match it.

Verified: `cppcheck --enable=all homa_tx_pool.c` reports the finding at
homa_tx_pool.c:534 before the change and nothing after; the existing
homa_copy_iter_to_frags and homa_copy_to_frags unit tests stay green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant