News for hackers. Stuff that matters.
Re:size_t-to-int vulnerability in Linux’s filesystem layer by phkahler on Tuesday July 20, 2021 @01:35PM (#27896690)
This wouldn't be a problem if "int" was defined as the same size as size_t. The solution is probably to change all those functions to take a parameter of size_t instead of int.

IMHO one should always be using C99 types instead of int, but Linux predates that.

Also, shouldn't that implicit conversion cause a compiler warning?

Re:size_t-to-int vulnerability in Linux’s filesystem layer by pcwalton on Tuesday July 20, 2021 @02:42PM (#27897532)
> This wouldn't be a problem if "int" was defined as the same size as size_t.

ILP64 causes a lot of problems, most notably needlessly-increased memory usage and, in C, the inconvenience of requesting a 32-bit type when int is 64-bit. It's rather uncommon to actually need the extra 64-bit range except when describing pointer addresses and memory/disk sizes, both of which benefit from an explicit intptr_t/size_t type for readability if nothing else.

Re:size_t-to-int vulnerability in Linux’s filesystem layer by saagarjha on Tuesday July 20, 2021 @05:01PM (#27899267)
ILP64 also solves a lot of problems if you don’t define overflow to be UB.
Re:size_t-to-int vulnerability in Linux’s filesystem layer by tialaramex on Tuesday July 20, 2021 @01:54PM (#27896952)
Linux apparently provides a similarly named set of sized integer types to Rust, ie: s8 u8 s16 u16 s32 u32 s64 u64

But of course getting C programmers to use these integer types rather than the ones they grew up with isn't easy.

Re:size_t-to-int vulnerability in Linux’s filesystem layer by foobiekr on Tuesday July 20, 2021 @03:31PM (#27898165)
I did a lot of C - a lot - in the mid-90s through the mid/late 2000s and have never seen any sizable C code base where explicit sizes were not the norm throughout - u_int32_t etc. I think this is not the problem, it's the implicit conversions.
Re:size_t-to-int vulnerability in Linux’s filesystem layer by masklinn on Wednesday July 21, 2021 @03:46AM (#27903479)
I don't think that stops C's implicit conversions either, does it?
Re:size_t-to-int vulnerability in Linux’s filesystem layer by dezgeg on Wednesday July 21, 2021 @10:37AM (#27906865)
It doesn't. They are in the end just typedefs to the basic types like int, long, etc.
Re:size_t-to-int vulnerability in Linux’s filesystem layer by chippiewill on Tuesday July 20, 2021 @02:29PM (#27897376)
> IMHO one should always be using C99 types instead of int, but Linux predates that.

"Always" is a strong way of putting it, there are often times where it makes sense to use the platform's "natural" word sizes (which is the entire point of having `int` `long` `long long` etc.)

Re:size_t-to-int vulnerability in Linux’s filesystem layer by phkahler on Tuesday July 20, 2021 @03:19PM (#27897988)
>> there are often times where it makes sense to use the platform's "natural" word sizes

In those cases we probably don't care about the full range of the larger types, so it doesn't hurt to use the smallest type for a range of expected values. If it does make a difference, the program will behave differently when compiled on a different arch or even a different compiler.

But maybe "generally" instead of "always". OTOH even I am guilty of using an int to loop over an array.

Re:size_t-to-int vulnerability in Linux’s filesystem layer by cesarb on Tuesday July 20, 2021 @01:56PM (#27896975)
> This wouldn't be a problem if "int" was defined as the same size as size_t.

That would lead to a hole in the type sequence (char <= short <= int <= long <= long long) for 64-bit targets (where int is the 32-bit type while size_t is 64 bits).

> IMHO one should always be using C99 types instead of int, but Linux predates that.

On the other hand, on Linux "long" has always been defined as the same size as size_t, so using "long" instead of "int" everywhere could also be an option.

Re:size_t-to-int vulnerability in Linux’s filesystem layer by kenniskrag on Tuesday July 20, 2021 @01:40PM (#27896748)
so you mean int_fastX_t or int_leastX_t?