[Intel-gfx] [PATCH 0/6] Fixes integer overflow or integer truncation issues in page lookups, ttm place configuration and scatterlist creation

Gwan-gyeong Mun gwan-gyeong.mun at intel.com
Tue Jun 14 08:49:10 UTC 2022



On 6/3/22 4:19 PM, Jani Nikula wrote:
> On Fri, 03 Jun 2022, Gwan-gyeong Mun <gwan-gyeong.mun at intel.com> wrote:
>> This patch series fixes integer overflow or integer truncation issues in
>> page lookups, ttm place configuration and scatterlist creation, etc.
>> We need to check that we avoid integer overflows when looking up a page,
>> and so fix all the instances where we have mistakenly used a plain integer
>> instead of a more suitable long.
> 
> So when are we going to start moving the helpers, both existing and the
> ones being added here, from i915_utils.h to proper kernel headers? We
> just keep adding more and more. This needs to stop.
> 
> BR,
> Jani.
> 

Thanks for your comments.

The following two macros have been added to i915_utils.h in this patch 
series.

#define exactly_pgoff_t(n) exact_type(pgoff_t, n)
The reason this macro was added is that there was a possibility that an 
overflow could occur in the code that is passed as a function parameter 
in the form of "offset >> PAGE_SHIFT" for the offset variable of 
unsigned int type in the code. Therefore this macro added so that we can 
check this part at the code level.
After checking all of this type of overflow problem in the i915 driver 
code, it is thought that it will be possible to remove it through 
refactoring in the future.

So, in my opinion, there is no need to move this macro to 
include/linux/types.h or other header files.


#define safe_conversion(ptr, value) ({ \
	typeof(value) __v = (value); \
	typeof(ptr) __ptr = (ptr); \
	overflows_type(__v, *__ptr) ? 0 : (*__ptr = (typeof(*__ptr))__v), 1; \
})
The above macro depends on overflows_type(), and overflows_type() is 
defined in i915_utils.h in the same way.
To move the safe_conversion() macro to a commonly available header, the 
overflows_type() macro must also be moved, and if the name or type of 
this macro is changed, all other code using overflows_type() will be 
affected. In this patch, safe_conversion() is added to i915_utils.h, and 
it seems to be prepared and moved to the next patch.

If you absolutely need to move the safe_conversion() macro to a common 
header in this patch series, please let me know and I will update this 
patch series.

Br,

G.G.


More information about the Intel-gfx mailing list