linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix 32-bit truncation of segment sizes in /proc/sysvipc/shm
@ 2008-06-11 20:30 Paul Menage
  0 siblings, 0 replies; only message in thread
From: Paul Menage @ 2008-06-11 20:30 UTC (permalink / raw)
  To: Andrew Morton, Mike Waychison; +Cc: linux-kernel, linux-mm

sysvipc_shm_proc_show() picks between format strings (based on the
expected maximum length of a SHM segment) in a way that prevents 
gcc from performing format checks on the seq_printf() parameters. This
hid two format errors - shp->shm_segsz and shp->shm_nattach are both
unsigned long, but were being printed as unsigned int and signed int
respectively. This leads to 32-bit truncation of SHM segment sizes 
reported in /proc/sysvipc/shm. (And for nattach, but that's less of a
problem for most users).

This patch makes the format string directly visible to gcc's format
specifier checker, and fixes the two broken format specifiers.

Signed-off-by: Paul Menage <menage@google.com>

---


 ipc/shm.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Index: shm-2.6.26-rc5-mm2/ipc/shm.c
===================================================================
--- shm-2.6.26-rc5-mm2.orig/ipc/shm.c
+++ shm-2.6.26-rc5-mm2/ipc/shm.c
@@ -1062,16 +1062,16 @@ asmlinkage long sys_shmdt(char __user *s
 static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
 {
 	struct shmid_kernel *shp = it;
-	char *format;
 
-#define SMALL_STRING "%10d %10d  %4o %10u %5u %5u  %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
-#define BIG_STRING   "%10d %10d  %4o %21u %5u %5u  %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
+#if BITS_PER_LONG <= 32
+#define SIZE_SPEC "%10lu"
+#else
+#define SIZE_SPEC "%21lu"
+#endif
 
-	if (sizeof(size_t) <= sizeof(int))
-		format = SMALL_STRING;
-	else
-		format = BIG_STRING;
-	return seq_printf(s, format,
+	return seq_printf(s,
+			  "%10d %10d  %4o " SIZE_SPEC " %5u %5u  "
+			  "%5lu %5u %5u %5u %5u %10lu %10lu %10lu\n",
 			  shp->shm_perm.key,
 			  shp->shm_perm.id,
 			  shp->shm_perm.mode,

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-11 20:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-11 20:30 [PATCH] Fix 32-bit truncation of segment sizes in /proc/sysvipc/shm Paul Menage

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