util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: Vasilis Liaskovitis <vliaskovitis@suse.com>
Cc: util-linux@vger.kernel.org, ruediger.meier@ga-group.nl, sbrabec@suse.com
Subject: Re: [PATCH] ipcs: Avoid shmall overflows
Date: Mon, 4 Jan 2021 13:20:52 +0100	[thread overview]
Message-ID: <20210104122052.aoonb4l72c7crkso@ws.net.home> (raw)
In-Reply-To: <aa7c757636594db8f122185293393e326652e53d.camel@suse.com>

On Wed, Dec 16, 2020 at 03:54:29PM +0100, Vasilis Liaskovitis wrote:
> Avoid computing the number of bytes in shmall, by only
> computing the number of Kbytes. This improves some
> overflows, e.g.
> 
> $ echo "4503599627370496" > /proc/sys/kernel/shmall
> $ ipcs -l | grep 'max total shared memory'
> Before:
> max total shared memory (kbytes) = 18014398509481980
> After:
> max total shared memory (kbytes) = 18014398509481984
> 
> $ echo "99993599627370500" > /proc/sys/kernel/shmall
> 99993599627370500
> $ ipcs -l | grep 'max total shared memory'
> Before:
> max total shared memory (kbytes) = 18014398509481980
> After:
> max total shared memory (kbytes) = 399974398509482000
> 
> Signed-off-by: Vasilis Liaskovitis <vliaskovitis@suse.com>
> ---
>  sys-utils/ipcs.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
> index fc6fba4a6..544a3adcc 100644
> --- a/sys-utils/ipcs.c
> +++ b/sys-utils/ipcs.c
> @@ -216,13 +216,9 @@ static void do_shm (char format, int unit)
>                 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB :
> unit,
>                                _("max seg size"), lim.shmmax, "\n", 0);
> 
> -               tmp = (uint64_t) lim.shmall * pgsz;
> -               /* overflow handling, at least we don't print
> ridiculous small values */
> -               if (lim.shmall != 0 && tmp / lim.shmall != pgsz) {
> -                       tmp = UINT64_MAX - (UINT64_MAX % pgsz);
> -               }
> -               ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB :
> unit,
> -                              _("max total shared memory"), tmp, "\n",
> 0);
> +               ipc_print_size(IPC_UNIT_DEFAULT,
> +                              _("max total shared memory (kbytes)"),
> (pgsz / 1024) *
> +                              (uint64_t) lim.shmall, "\n", 0);

It means that --bytes and --human command line options will be 
ignored for shmall ... it would be probably better to use

 if (unit == IPC_UNIT_KB || units == IPC_UNIT_DEFAULT)
    ipc_print_size(IPC_UNIT_KB, ("max total shared memory"), lim.shmall, "\n", 0); 
 else {
   tmp = (uint64_t) lim.shmall * pgsz;
   /* overflow handling, at least we don't print ridiculous small values */ 
   if (lim.shmall != 0 && tmp / lim.shmall != pgsz)
       tmp = UINT64_MAX - (UINT64_MAX % pgsz);
   ipc_print_size(unit, _("max total shared memory"), tmp, "\n", 0);
 }

 Right? If yes, update the patch, please.

   Karel
    

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


      reply	other threads:[~2021-01-04 12:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16 14:54 [PATCH] ipcs: Avoid shmall overflows Vasilis Liaskovitis
2021-01-04 12:20 ` Karel Zak [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210104122052.aoonb4l72c7crkso@ws.net.home \
    --to=kzak@redhat.com \
    --cc=ruediger.meier@ga-group.nl \
    --cc=sbrabec@suse.com \
    --cc=util-linux@vger.kernel.org \
    --cc=vliaskovitis@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).