public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing
@ 2026-02-23  3:18 Guixiong Wei via ltp
  2026-02-23  3:19 ` [LTP] [PATCH 1/4] syscalls/ipc: shmctl04: Parse /proc/sysvipc/shm size as unsigned long Guixiong Wei via ltp
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Guixiong Wei via ltp @ 2026-02-23  3:18 UTC (permalink / raw)
  To: ltp; +Cc: Guixiong Wei

Hi,

This series fixes shmctl04 parsing and reporting for /proc/sysvipc/shm.

On systems with large SHM segments, the "bytes" column in /proc/sysvipc/shm may
exceed int range, which can lead to truncation and incorrect accounting. The
series parses the size column as unsigned long, requires fscanf() to match all
expected fields to avoid using stale values on partial matches, fixes format
specifiers when reporting counters, and uses SAFE_FOPEN/SAFE_FCLOSE for /proc
reads.

Thanks.

Guixiong Wei (4):
  syscalls/ipc: shmctl04: Parse /proc/sysvipc/shm size as unsigned long
  syscalls/ipc: shmctl04: Require full fscanf match
  syscalls/ipc: shmctl04: Use SAFE_FOPEN for /proc parsing
  syscalls/ipc: shmctl04: Fix shm_info print formats

 .../kernel/syscalls/ipc/shmctl/shmctl04.c     | 24 ++++++++++---------
 1 file changed, 13 insertions(+), 11 deletions(-)

-- 
2.20.1

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 1/4] syscalls/ipc: shmctl04: Parse /proc/sysvipc/shm size as unsigned long
  2026-02-23  3:18 [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Guixiong Wei via ltp
@ 2026-02-23  3:19 ` Guixiong Wei via ltp
  2026-02-23 16:39   ` Cyril Hrubis
  2026-02-23  3:19 ` [LTP] [PATCH 2/4] syscalls/ipc: shmctl04: Require full fscanf match Guixiong Wei via ltp
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Guixiong Wei via ltp @ 2026-02-23  3:19 UTC (permalink / raw)
  To: ltp; +Cc: Guixiong Wei

The size column in /proc/sysvipc/shm may exceed int range on
some systems. Parse it as unsigned long.

Signed-off-by: Guixiong Wei <weiguixiong@bytedance.com>
---
 testcases/kernel/syscalls/ipc/shmctl/shmctl04.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
index 3ba05f9b5..908cd2926 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
@@ -57,7 +57,8 @@ static void parse_proc_sysvipc(struct shm_info *info)
 			break;
 	}
 
-	int shmid, size, rss, swap;
+	int shmid, rss, swap;
+	unsigned long size;
 
 	/*
 	 * Sum rss, swap and size for all elements listed, which should equal
@@ -66,7 +67,7 @@ static void parse_proc_sysvipc(struct shm_info *info)
 	 * Note that the size has to be rounded up to nearest multiple of page
 	 * size.
 	 */
-	while (fscanf(f, "%*i %i %*i %i %*i %*i %*i %*i %*i %*i %*i %*i %*i %*i %i %i",
+	while (fscanf(f, "%*i %i %*i %lu %*i %*i %*i %*i %*i %*i %*i %*i %*i %*i %i %i",
 			&shmid, &size, &rss, &swap) > 0) {
 		used_ids++;
 		shm_rss += rss/page_size;
-- 
2.20.1

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 2/4] syscalls/ipc: shmctl04: Require full fscanf match
  2026-02-23  3:18 [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Guixiong Wei via ltp
  2026-02-23  3:19 ` [LTP] [PATCH 1/4] syscalls/ipc: shmctl04: Parse /proc/sysvipc/shm size as unsigned long Guixiong Wei via ltp
@ 2026-02-23  3:19 ` Guixiong Wei via ltp
  2026-02-23 16:40   ` Cyril Hrubis
  2026-02-23  3:19 ` [LTP] [PATCH 3/4] syscalls/ipc: shmctl04: Use SAFE_FOPEN for /proc parsing Guixiong Wei via ltp
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Guixiong Wei via ltp @ 2026-02-23  3:19 UTC (permalink / raw)
  To: ltp; +Cc: Guixiong Wei

Stop parsing /proc/sysvipc/shm when fscanf() does not match all
expected fields, to avoid using stale values from previous iterations.

Signed-off-by: Guixiong Wei <weiguixiong@bytedance.com>
---
 testcases/kernel/syscalls/ipc/shmctl/shmctl04.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
index 908cd2926..967e5d4b2 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
@@ -68,7 +68,7 @@ static void parse_proc_sysvipc(struct shm_info *info)
 	 * size.
 	 */
 	while (fscanf(f, "%*i %i %*i %lu %*i %*i %*i %*i %*i %*i %*i %*i %*i %*i %i %i",
-			&shmid, &size, &rss, &swap) > 0) {
+			&shmid, &size, &rss, &swap) == 4) {
 		used_ids++;
 		shm_rss += rss/page_size;
 		shm_swp += swap/page_size;
-- 
2.20.1

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 3/4] syscalls/ipc: shmctl04: Use SAFE_FOPEN for /proc parsing
  2026-02-23  3:18 [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Guixiong Wei via ltp
  2026-02-23  3:19 ` [LTP] [PATCH 1/4] syscalls/ipc: shmctl04: Parse /proc/sysvipc/shm size as unsigned long Guixiong Wei via ltp
  2026-02-23  3:19 ` [LTP] [PATCH 2/4] syscalls/ipc: shmctl04: Require full fscanf match Guixiong Wei via ltp
@ 2026-02-23  3:19 ` Guixiong Wei via ltp
  2026-02-23 16:40   ` Cyril Hrubis
  2026-02-23  3:19 ` [LTP] [PATCH 4/4] syscalls/ipc: shmctl04: Fix shm_info print formats Guixiong Wei via ltp
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Guixiong Wei via ltp @ 2026-02-23  3:19 UTC (permalink / raw)
  To: ltp; +Cc: Guixiong Wei

Use SAFE_FOPEN/SAFE_FCLOSE when reading /proc/sysvipc/shm.

Signed-off-by: Guixiong Wei <weiguixiong@bytedance.com>
---
 testcases/kernel/syscalls/ipc/shmctl/shmctl04.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
index 967e5d4b2..97e84efb6 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <pwd.h>
 #include "tst_test.h"
+#include "tst_safe_stdio.h"
 #include "tst_safe_sysv_ipc.h"
 #include "tse_newipc.h"
 #include "lapi/shm.h"
@@ -42,7 +43,7 @@ static struct tcases {
 static void parse_proc_sysvipc(struct shm_info *info)
 {
 	int page_size = getpagesize();
-	FILE *f = fopen("/proc/sysvipc/shm", "r");
+	FILE *f = SAFE_FOPEN("/proc/sysvipc/shm", "r");
 	int used_ids = 0;
 	int shmid_max = 0;
 	unsigned long shm_rss = 0;
@@ -105,7 +106,7 @@ static void parse_proc_sysvipc(struct shm_info *info)
 		tst_res(TPASS, "shm_tot = %li", shm_tot);
 	}
 
-	fclose(f);
+	SAFE_FCLOSE(f);
 }
 
 static void verify_shminfo(unsigned int n)
-- 
2.20.1

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 4/4] syscalls/ipc: shmctl04: Fix shm_info print formats
  2026-02-23  3:18 [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Guixiong Wei via ltp
                   ` (2 preceding siblings ...)
  2026-02-23  3:19 ` [LTP] [PATCH 3/4] syscalls/ipc: shmctl04: Use SAFE_FOPEN for /proc parsing Guixiong Wei via ltp
@ 2026-02-23  3:19 ` Guixiong Wei via ltp
  2026-02-23 16:41   ` Cyril Hrubis
  2026-02-24 12:57 ` [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Andrea Cervesato via ltp
  2026-02-24 13:00 ` Andrea Cervesato via ltp
  5 siblings, 1 reply; 11+ messages in thread
From: Guixiong Wei via ltp @ 2026-02-23  3:19 UTC (permalink / raw)
  To: ltp; +Cc: Guixiong Wei

Use %lu when printing unsigned long counters parsed from /proc and
cast shm_info fields to match the format specifiers.

Signed-off-by: Guixiong Wei <weiguixiong@bytedance.com>
---
 testcases/kernel/syscalls/ipc/shmctl/shmctl04.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
index 97e84efb6..f436e763d 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
@@ -86,24 +86,24 @@ static void parse_proc_sysvipc(struct shm_info *info)
 	}
 
 	if (info->shm_rss != shm_rss) {
-		tst_res(TFAIL, "shm_rss = %li, expected %li",
+		tst_res(TFAIL, "shm_rss = %lu, expected %lu",
 			info->shm_rss, shm_rss);
 	} else {
-		tst_res(TPASS, "shm_rss = %li", shm_rss);
+		tst_res(TPASS, "shm_rss = %lu", shm_rss);
 	}
 
 	if (info->shm_swp != shm_swp) {
-		tst_res(TFAIL, "shm_swp = %li, expected %li",
+		tst_res(TFAIL, "shm_swp = %lu, expected %lu",
 			info->shm_swp, shm_swp);
 	} else {
-		tst_res(TPASS, "shm_swp = %li", shm_swp);
+		tst_res(TPASS, "shm_swp = %lu", shm_swp);
 	}
 
 	if (info->shm_tot != shm_tot) {
-		tst_res(TFAIL, "shm_tot = %li, expected %li",
+		tst_res(TFAIL, "shm_tot = %lu, expected %lu",
 			info->shm_tot, shm_tot);
 	} else {
-		tst_res(TPASS, "shm_tot = %li", shm_tot);
+		tst_res(TPASS, "shm_tot = %lu", shm_tot);
 	}
 
 	SAFE_FCLOSE(f);
-- 
2.20.1

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH 1/4] syscalls/ipc: shmctl04: Parse /proc/sysvipc/shm size as unsigned long
  2026-02-23  3:19 ` [LTP] [PATCH 1/4] syscalls/ipc: shmctl04: Parse /proc/sysvipc/shm size as unsigned long Guixiong Wei via ltp
@ 2026-02-23 16:39   ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2026-02-23 16:39 UTC (permalink / raw)
  To: Guixiong Wei; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH 2/4] syscalls/ipc: shmctl04: Require full fscanf match
  2026-02-23  3:19 ` [LTP] [PATCH 2/4] syscalls/ipc: shmctl04: Require full fscanf match Guixiong Wei via ltp
@ 2026-02-23 16:40   ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2026-02-23 16:40 UTC (permalink / raw)
  To: Guixiong Wei; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH 3/4] syscalls/ipc: shmctl04: Use SAFE_FOPEN for /proc parsing
  2026-02-23  3:19 ` [LTP] [PATCH 3/4] syscalls/ipc: shmctl04: Use SAFE_FOPEN for /proc parsing Guixiong Wei via ltp
@ 2026-02-23 16:40   ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2026-02-23 16:40 UTC (permalink / raw)
  To: Guixiong Wei; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH 4/4] syscalls/ipc: shmctl04: Fix shm_info print formats
  2026-02-23  3:19 ` [LTP] [PATCH 4/4] syscalls/ipc: shmctl04: Fix shm_info print formats Guixiong Wei via ltp
@ 2026-02-23 16:41   ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2026-02-23 16:41 UTC (permalink / raw)
  To: Guixiong Wei; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing
  2026-02-23  3:18 [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Guixiong Wei via ltp
                   ` (3 preceding siblings ...)
  2026-02-23  3:19 ` [LTP] [PATCH 4/4] syscalls/ipc: shmctl04: Fix shm_info print formats Guixiong Wei via ltp
@ 2026-02-24 12:57 ` Andrea Cervesato via ltp
  2026-02-24 13:00 ` Andrea Cervesato via ltp
  5 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato via ltp @ 2026-02-24 12:57 UTC (permalink / raw)
  To: Guixiong Wei, ltp

Hi!

LGTM the whole series. I'm gonna merge it.

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

-- 
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing
  2026-02-23  3:18 [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Guixiong Wei via ltp
                   ` (4 preceding siblings ...)
  2026-02-24 12:57 ` [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Andrea Cervesato via ltp
@ 2026-02-24 13:00 ` Andrea Cervesato via ltp
  5 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato via ltp @ 2026-02-24 13:00 UTC (permalink / raw)
  To: Guixiong Wei, ltp

Merged, thanks!

To 
   ..  master -> master

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-02-24 13:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23  3:18 [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Guixiong Wei via ltp
2026-02-23  3:19 ` [LTP] [PATCH 1/4] syscalls/ipc: shmctl04: Parse /proc/sysvipc/shm size as unsigned long Guixiong Wei via ltp
2026-02-23 16:39   ` Cyril Hrubis
2026-02-23  3:19 ` [LTP] [PATCH 2/4] syscalls/ipc: shmctl04: Require full fscanf match Guixiong Wei via ltp
2026-02-23 16:40   ` Cyril Hrubis
2026-02-23  3:19 ` [LTP] [PATCH 3/4] syscalls/ipc: shmctl04: Use SAFE_FOPEN for /proc parsing Guixiong Wei via ltp
2026-02-23 16:40   ` Cyril Hrubis
2026-02-23  3:19 ` [LTP] [PATCH 4/4] syscalls/ipc: shmctl04: Fix shm_info print formats Guixiong Wei via ltp
2026-02-23 16:41   ` Cyril Hrubis
2026-02-24 12:57 ` [LTP] [PATCH 0/4] syscalls/ipc: shmctl04: Fix /proc/sysvipc/shm parsing Andrea Cervesato via ltp
2026-02-24 13:00 ` Andrea Cervesato via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox