lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87lezs4qoq.fsf@email.froward.int.ebiederm.org>
Date:   Thu, 06 Jan 2022 13:20:05 -0600
From:   ebiederm@...ssion.com (Eric W. Biederman)
To:     Pintu Agarwal <pintu.ping@...il.com>
Cc:     David Laight <David.Laight@...lab.com>,
        Cyrill Gorcunov <gorcunov@...il.com>,
        Pintu Kumar <quic_pintu@...cinc.com>,
        open list <linux-kernel@...r.kernel.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        linux-mm <linux-mm@...ck.org>,
        "christian.brauner\@ubuntu.com" <christian.brauner@...ntu.com>,
        "sfr\@canb.auug.org.au" <sfr@...b.auug.org.au>,
        "legion\@kernel.org" <legion@...nel.org>,
        "sashal\@kernel.org" <sashal@...nel.org>,
        "chris.hyser\@oracle.com" <chris.hyser@...cle.com>,
        "ccross\@google.com" <ccross@...gle.com>,
        "pcc\@google.com" <pcc@...gle.com>,
        "dave\@stgolabs.net" <dave@...olabs.net>,
        "caoxiaofeng\@yulong.com" <caoxiaofeng@...ong.com>,
        "david\@redhat.com" <david@...hat.com>
Subject: Re: [PATCH] sysinfo: include availram field in sysinfo struct

Pintu Agarwal <pintu.ping@...il.com> writes:

> On Thu, 6 Jan 2022 at 23:12, David Laight <David.Laight@...lab.com> wrote:
>>
>> From: Pintu Agarwal
>> > Sent: 06 January 2022 16:50
>> >
>> > On Thu, 6 Jan 2022 at 21:41, Cyrill Gorcunov <gorcunov@...il.com> wrote:
>> > >
>> > > On Thu, Jan 06, 2022 at 09:04:10PM +0530, Pintu Kumar wrote:
>> > > > The sysinfo member does not have any "available ram" field and
>> > > > the bufferram field is not much helpful either, to get a rough
>> > > > estimate of available ram needed for allocation.
>> > > >
>> > > > One needs to parse MemAvailable field separately from /proc/meminfo
>> > > > to get this info instead of directly getting if from sysinfo itself.
>> > > >
>> > > > Thus, this patch introduce a new field as availram in sysinfo
>> > > > so that all the info total/free/available can be retrieved from
>> > > > one place itself.
>> > > >
>> > > > There are couple of places in kernel as well where this can be improved.
>> > > > For example:
>> > > > In fs/proc/meminfo.c:
>> > > > meminfo_proc_show:
>> > > >    si_meminfo(&i);
>> > > >    available = si_mem_available();
>> > > > Now with this change the second call be avoided.
>> > > > Thus, we can directly do:
>> > > > show_val_kb(m, "MemAvailable:   ", i.availram);
>> > > >
>> > > > Note, this also requires update in procfs for free and other commands.
>> > > > Like in free command as well we frist call sysinfo then again parse
>> > > > /proc/meminfo to get available field.
>> > > > This can be avoided too with higher kernel version.
>> > > >
>> > > > A sample output with single sysinfo call is shown below:
>> > > > Total RAM: 248376 kB
>> > > >  Free RAM: 231540 kB
>> > > > Avail RAM: 230448 kB
>> > > >
>> > > > Signed-off-by: Pintu Kumar <quic_pintu@...cinc.com>
>> > > > Signed-off-by: Pintu Agarwal <pintu.ping@...il.com>
>> > > > ---
>> > > >  include/uapi/linux/sysinfo.h | 1 +
>> > > >  kernel/sys.c                 | 4 ++++
>> > > >  mm/page_alloc.c              | 2 ++
>> > > >  3 files changed, 7 insertions(+)
>> > > >
>> > > > diff --git a/include/uapi/linux/sysinfo.h b/include/uapi/linux/sysinfo.h
>> > > > index 435d5c2..6e77e90 100644
>> > > > --- a/include/uapi/linux/sysinfo.h
>> > > > +++ b/include/uapi/linux/sysinfo.h
>> > > > @@ -12,6 +12,7 @@ struct sysinfo {
>> > > >       __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 availram;      /* Memory available for allocation */
>> > > >       __kernel_ulong_t totalswap;     /* Total swap space size */
>> > > >       __kernel_ulong_t freeswap;      /* swap space still available */
>> > > >       __u16 procs;                    /* Number of current processes */
>> > >
>> > > Hi! Sorry, but I don't understand -- the sysinfo structure seems to
>> > > be part of user API, no? Don't we break it up here?
>> >
>> > Yes, the corresponding user space header /usr/include/linux/sysinfo.h
>> > also needs to be updated.
>> > When we generate the kernel header it will be updated automatically.
>>
>> You can't add a field in the middle of a UAPI structure.
>> It breaks compatibility for old binaries.
>>
>> Depending on the interface definition you may be able to add one at the end.
>>
> oh okay thank you for your feedback. I will move to the end and check again.
> But my doubt is, whether I should move before this
> char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)];
> or after this ?

Before the padding and you should reduce the size of the padding by the
size of your new field.

> Also, I could not understand what this is for ?
> Do we need to update this since sture is changed ?

In general padding like that is so new fields can be added.  The
comment about libc5 makes me a wonder a bit, but I expect libc5 just
added the padding in it's copy of the structure that it exported to
userspace many many years ago so that new fields could be added.

Eric

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ