Right now, CONFIG_FORTIFY_SOURCE uses __builtin_object_size(member, 0), which returns the size of the larger structure (inter-object bounds checking). In the case of:
struct thing {
char first[16];
int middle;
int final;
};
...
struct thing instance;
...
strcpy(instance->first, ...);
CONFIG_FORTIFY_SOURCE will check that the write does not go past the end of instance, but it will allow an overflow beyond the end of first into middle and final.
Fixing this will likely require several steps:
Right now,
CONFIG_FORTIFY_SOURCEuses__builtin_object_size(member, 0), which returns the size of the larger structure (inter-object bounds checking). In the case of:CONFIG_FORTIFY_SOURCEwill check that the write does not go past the end ofinstance, but it will allow an overflow beyond the end offirstintomiddleandfinal.Fixing this will likely require several steps:
__builtin_object_size(member, 1)to gain intra-object bounds checking forstr*()family functions. A patch for this already exists. Landed in commit 6a39e62 (v5.11)__builtin_object_size(member, 1)formem*()family functions, there are several cases in the kernel where copies are intentionally targeting the address of a structure member but intentionally write across multiple structure members. For example, with the above structurememcpy(&instance->middle, src, sizeof(int) * 2). So many patches landed for these fixes.mem*()family functions. Landed in commit f68f2ff (v5.18)mem*()family functions.mem*()family functions.