Re: [PATCH 06/30] sysinfo: Use explicit types in <linux/sysinfo.h>

From: Geert Uytterhoeven
Date: Mon Feb 20 2012 - 15:01:49 EST


On Mon, Feb 20, 2012 at 18:29, H. Peter Anvin <hpa@xxxxxxxxx> wrote:
> Not really... it comes down to "implicit padding in kernel ABI structures is bad". ÂThey can easily become security holes.

On 64-bit platforms with natural alignment of long, there's an implicit padding.

> Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> wrote:
>
>>On Mon, Feb 20, 2012 at 01:07, H. Peter Anvin <hpa@xxxxxxxxx> wrote:
>>> --- a/include/linux/sysinfo.h
>>> +++ b/include/linux/sysinfo.h
>>> @@ -1,22 +1,24 @@
>>> Â#ifndef _LINUX_SYSINFO_H
>>> Â#define _LINUX_SYSINFO_H
>>>
>>> +#include <linux/types.h>
>>> +
>>> Â#define SI_LOAD_SHIFT Â16
>>> Âstruct sysinfo {
>>> - Â Â Â long uptime; Â Â Â Â Â Â Â Â Â Â/* Seconds since boot */
>>> - Â Â Â unsigned long loads[3]; Â Â Â Â /* 1, 5, and 15 minute load
>>averages */
>>> - Â Â Â unsigned long totalram; Â Â Â Â /* Total usable main memory
>>size */
>>> - Â Â Â unsigned long freeram; Â Â Â Â Â/* Available memory size */
>>> - Â Â Â unsigned long sharedram; Â Â Â Â/* Amount of shared memory */
>>> - Â Â Â unsigned long bufferram; Â Â Â Â/* Memory used by buffers */
>>> - Â Â Â unsigned long totalswap; Â Â Â Â/* Total swap space size */
>>> - Â Â Â unsigned long freeswap; Â Â Â Â /* swap space still available
>>*/
>>> - Â Â Â unsigned short procs; Â Â Â Â Â /* Number of current
>>processes */
>>> - Â Â Â unsigned short pad; Â Â Â Â Â Â /* explicit padding for m68k
>>*/
>>> - Â Â Â unsigned long totalhigh; Â Â Â Â/* Total high memory size */
>>> - Â Â Â unsigned long freehigh; Â Â Â Â /* Available high memory size
>>*/
>>> - Â Â Â unsigned int mem_unit; Â Â Â Â Â/* Memory unit size in bytes
>>*/
>>> - Â Â Â char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5
>>uses this.. */
>>> + Â Â Â __kernel_long_t uptime; Â Â Â Â /* Seconds since boot */
>>> + Â Â Â __kernel_ulong_t loads[3]; Â Â Â/* 1, 5, and 15 minute load
>>averages */
>>> + Â Â Â __kernel_ulong_t totalram; Â Â Â/* Total usable main memory
>>size */
>>> + Â Â Â __kernel_ulong_t freeram; Â Â Â /* Available memory size */
>>> + Â Â Â __kernel_ulong_t sharedram; Â Â /* Amount of shared memory */
>>> + Â Â Â __kernel_ulong_t bufferram; Â Â /* Memory used by buffers */
>>> + Â Â Â __kernel_ulong_t totalswap; Â Â /* Total swap space size */
>>> + Â Â Â __kernel_ulong_t freeswap; Â Â Â/* swap space still available
>>*/
>>> + Â Â Â __u16 procs; Â Â Â Â Â Â Â Â Â Â/* Number of current
>>processes */
>>> + Â Â Â __u16 pad; Â Â Â Â Â Â Â Â Â Â Â/* Explicit padding for m68k
>>*/
>>
>>Fueling the discussion about natural vs. 4-byte alignment?
>>
>>> + Â Â Â __kernel_ulong_t totalhigh; Â Â /* Total high memory size */
>>> + Â Â Â __kernel_ulong_t freehigh; Â Â Â/* Available high memory size
>>*/
>>> + Â Â Â __u32 mem_unit; Â Â Â Â Â Â Â Â /* Memory unit size in bytes
>>*/
>>> + Â Â Â char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)]; Â /*
>>Padding: libc5 uses this.. */
>>> Â};

Gr{oetje,eeting}s,

            Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
             Â Â -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/