[PATCH] ipcs: Avoid shmall overflows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
---
 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);
                ipc_print_size(unit == IPC_UNIT_DEFAULT ?
IPC_UNIT_BYTES : unit,
                               _("min seg size"), lim.shmmin, "\n", 0);
                return;
--
2.28.0




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux