Skip to content

Fix integer overflow in memory calculations on 32bit systems - #2770

Merged
pmatilai merged 1 commit into
rpm-software-management:masterfrom
pmatilai:lalalong
Nov 27, 2023
Merged

Fix integer overflow in memory calculations on 32bit systems#2770
pmatilai merged 1 commit into
rpm-software-management:masterfrom
pmatilai:lalalong

Conversation

@pmatilai

Copy link
Copy Markdown
Member

"long int" on at least x86 Linux is exactly the same as a plain "int", so calculations can easily overflow. 32bit systems are not expected to have hundreds of gigabytes of memory but a 32bit process on a x86_64 can run into all sorts of funny things, such having 500GB system memory. At which point the type capable of addressing all of process memory is absolutely useless for calculating the total memory.

Use uint64_t in the memory calculations to make the size explicit. Of course one day we may cross that border too, but I hope to be retired by then.

Fixes https://issues.redhat.com/browse/RHEL-16557

@pmatilai pmatilai added the bug label Nov 16, 2023
"long int" on at least x86 Linux is exactly the same as a plain "int",
so calculations can easily overflow. 32bit systems are not expected to
have hundreds of gigabytes of memory but a 32bit process on a x86_64 can
run into all sorts of funny things, such having 500GB system memory. At
which point the type capable of addressing all of process memory is
absolutely useless for calculating the total memory.

Use uint64_t in the memory calculations to make the size explicit. Of course
one day we may cross that border too, but I hope to be retired by then.

Fixes https://issues.redhat.com/browse/RHEL-16557
@pmatilai

pmatilai commented Nov 27, 2023

Copy link
Copy Markdown
Member Author

Actually this "fix" was just as broken as it was before, because:
mem = (uint64_t)(pages * pagesize) is just as bad as not casting it at all because it casts the result of the multiplication, whereas we want to force (one of) the members to 64bit 🤦

I love you C, but there are times...

@pmatilai

Copy link
Copy Markdown
Member Author

Anyway, actually tested now, merging.

@pmatilai
pmatilai merged commit 1cd9f90 into rpm-software-management:master Nov 27, 2023
@pmatilai
pmatilai deleted the lalalong branch November 27, 2023 13:56
@dmnks dmnks added the packaging Package building, SPEC files, etc. label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug packaging Package building, SPEC files, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants