Skip to contentSkip to conversation

libbpf: Fix theoretical u32 underflow in find_cd() function

PATCH Applied Daniel Müller 2 participants 2 messages Mar 7, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: Fix theoretical u32 underflow in find_cd() function

Coverity reported a potential underflow of the offset variable used in the find_cd() function. Switch to using a signed 64 bit integer for the representation of offset to make sure we can never underflow.

Fixes 1eebcb60633f ("libbpf: Implement basic zip archive parsing support")
---
 tools/lib/bpf/zip.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/lib/bpf/zip.c +1 -2
index 8458c2..f561aa 100644
@@ -168,9 +168,8 @@ static int try_parse_end_of_cd(struct zip_archive *archive, __u32 offset)
 
 static int find_cd(struct zip_archive *archive)
 {
+	int64_t limit, offset;
 	int rc = -EINVAL;
-	int64_t limit;
-	__u32 offset;
 
 	if (archive->size <= sizeof(struct end_of_cd_record))
 		return -EINVAL;
Signature · 1 line
2.34.1
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 8 lines · On Tue, 7 Mar 2023 21:55:04 +0000 you wrote:

Coverity reported a potential underflow of the offset variable used in the find_cd() function. Switch to using a signed 64 bit integer for the representation of offset to make sure we can never underflow.

Fixes 1eebcb60633f ("libbpf: Implement basic zip archive parsing support")

[...]

Here is the summary with links:
- [bpf-next] libbpf: Fix theoretical u32 underflow in find_cd() function

    https://git.kernel.org/bpf/bpf-next/c/3ecde2182adb

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html