Skip to content

Commit 9e6a8cc

Browse files
fremmipoiana
authored andcommitted
fix(userspace/libsinsp): prevent infinite loop in ancillary data parsing due to integer overflow
Add validation in ppm_cmsg_nxthdr to ensure cmsg_aligned_len is at least sizeof(ppm_cmsghdr) after alignment calculation. This prevents an infinite loop when malformed ancillary data contains cmsg_len = 0xFFFFFFFFFFFFFFFF, which causes integer overflow in PPM_CMSG_ALIGN macro, resulting in cmsg_aligned_len = 0 and preventing forward progress in the loop. Signed-off-by: Francesco Emmi <[email protected]>
1 parent 9b8a8e4 commit 9e6a8cc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

userspace/libsinsp/parsers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,10 @@ static ppm_cmsghdr *ppm_cmsg_nxthdr(char const *msg_control,
31923192
}
31933193

31943194
size_t const cmsg_aligned_len = PPM_CMSG_ALIGN(cmsg_len);
3195+
// Guard against infinite loop: ensure we advance by at least sizeof(ppm_cmsghdr)
3196+
if(cmsg_aligned_len < sizeof(ppm_cmsghdr)) {
3197+
return nullptr;
3198+
}
31953199
cmsg = reinterpret_cast<ppm_cmsghdr *>(reinterpret_cast<char *>(cmsg) + cmsg_aligned_len);
31963200
if(reinterpret_cast<char *>(cmsg + 1) > msg_control + msg_controllen ||
31973201
reinterpret_cast<char *>(cmsg) + cmsg_aligned_len > msg_control + msg_controllen) {

0 commit comments

Comments
 (0)