public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Bug in /proc/lvm/global (garbage printed)
@ 2001-11-10 11:06 Thorsten Kukuk
  2001-11-10 13:38 ` Luigi Genoni
  2001-11-11  0:55 ` Andreas Dilger
  0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Kukuk @ 2001-11-10 11:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: Heinz.Mauelshagen


Hi,

On UltraSPARC and IA64, an "cat /proc/lvm/global" returns only
garbage (it will print the contents of some random memory).

The problem is in the _proc_read_global function. This function does
not use the "page" parameter to return the data. Instead it allocates
it's own buffer and change to "start" parameter to point to it.
The "page" buffer will not be used. The culprint is now in the
proc_file_read() function:

                /* This is a hack to allow mangling of file pos independent
                 * of actual bytes read.  Simply place the data at page,
                 * return the bytes, and set `start' to the desired offset
                 * as an unsigned int. - Paul.Russell@rustcorp.com.au
                 */
                n -= copy_to_user(buf, start < page ? page : start, n);

In some cases (this cases seems to be always true on UltraSPARC and IA64
and I think it works only by accident on ix32) the data from page and not
from start is used -> page contains randam data which is printed by the
kernel.

I fixed this by the following patch (which works for me on UltraSPARC),
but I don't know if it really correct in all cases. But I think it is.
Don't return a pointer to the buffer, instead copy as far as possible
data to page. This should work as before, since we never returns the
full length of the data, but max. the length of the page buffer.

--- drivers/md/lvm-fs.c	2001/11/09 19:00:38	1.1
+++ drivers/md/lvm-fs.c	2001/11/09 20:50:16
@@ -482,11 +480,15 @@
 		buf = NULL;
 		return 0;
 	}
-	*start = &buf[pos];
-	if (sz - pos < count)
+	/* *start = &buf[pos]; */
+	if (sz - pos < count) {
+		memcpy (page, &buf[pos], sz - pos);
 		return sz - pos;
-	else
+        }
+	else {
+		memcpy (page, &buf[pos], count);
 		return count;
+	}
 
 #undef LVM_PROC_BUF
 }


-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk@suse.de
SuSE GmbH            Deutschherrenstr. 15-19       D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

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

end of thread, other threads:[~2001-11-11  7:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-11-10 11:06 Bug in /proc/lvm/global (garbage printed) Thorsten Kukuk
2001-11-10 13:38 ` Luigi Genoni
2001-11-11  0:55 ` Andreas Dilger
2001-11-11  7:36   ` Thorsten Kukuk

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