File util-linux-ipcs-shmall-overflow-1.patch of Package util-linux.12160
From 7a08784ab053d6aa30db990cbec1fd35b34ed00a Mon Sep 17 00:00:00 2001
From: Vasilis Liaskovitis <vliaskovitis@suse.com>
Date: Fri, 15 Jan 2021 15:00:11 +0100
Subject: [PATCH 1/2] ipcs: Avoid shmall overflows
Avoid computing the number of bytes in shmall, by only
computing and printing the number of Kbytes. This avoids
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
v1->v2:
Print the non-overflow KB value only for IPC_UNIT_KB and
IPC_UNIT_DEFAULT.
This way --bytes and --human options will still get an expected
output
(but not avoiding the overflow).
Signed-off-by: Vasilis Liaskovitis <vliaskovitis@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
---
sys-utils/ipcs.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
Index: util-linux-2.29.2/sys-utils/ipcs.c
===================================================================
--- util-linux-2.29.2.orig/sys-utils/ipcs.c
+++ util-linux-2.29.2/sys-utils/ipcs.c
@@ -198,6 +198,7 @@ static void do_shm (char format, int uni
case LIMITS:
{
struct ipc_limits lim;
+ uint64_t tmp, pgsz = getpagesize();
if (ipc_shm_get_limits(&lim)) {
printf (_("unable to fetch shared memory limits\n"));
@@ -207,6 +208,25 @@ static void do_shm (char format, int uni
printf (_("max number of segments = %ju\n"), lim.shmmni);
ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
_("max seg size"), lim.shmmax, "\n", 0);
+
+ if (unit == IPC_UNIT_KB || unit == IPC_UNIT_DEFAULT) {
+ ipc_print_size(IPC_UNIT_DEFAULT,
+ _("max total shared memory (kbytes)"), (pgsz / 1024) *
+ (uint64_t) 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);
+ }
+ ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
+ _("min seg size"), lim.shmmin, "\n", 0);
+
+
+
ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
_("max total shared memory"),
(uint64_t) lim.shmall * getpagesize(), "\n", 0);