adjust /dev/{kmem,mem,port} write handlers
PATCH 1/1 adjust /dev/{kmem,mem,port} write handlers
The /dev/mem and /dev/kmem write handlers weren't fully POSIX compliant in that they wouldn't always force the file pointer to be updated when returning success status.
The /dev/port write handler was inconsistent with the /dev/mem and /dev/kmem handlers in that when encountering a -EFAULT condition after already having written a number of items it would return -EFAULT rather than the number of bytes written.
drivers/char/mem.c renamed from home/jbeulich/tmp/linux-2.6.16-rc5/drivers/char/mem.c +13 -15
@@ -216,11 +216,9 @@ static ssize_t write_mem(struct file * f copied =copy_from_user (ptr, buf, sz);if (copied) { -ssize_t ret; - - ret = written + (sz - copied); -if (ret) -return ret; + written += sz - copied; +if (written) +break ;return -EFAULT ; } buf += sz;
@@ -456,11 +454,9 @@ do_write_kmem(void *p, unsigned long rea copied =copy_from_user (ptr, buf, sz);if (copied) { -ssize_t ret; - - ret = written + (sz - copied); -if (ret) -return ret; + written += sz - copied; +if (written) +break ;return -EFAULT ; } buf += sz;
@@ -514,11 +510,10 @@ static ssize_t write_kmem(struct file *if (len) { written =copy_from_user (kbuf, buf, len);if (written) { -ssize_t ret; - +if (wrote + virtr) +break ;free_page ((unsigned long )kbuf); - ret = wrote + virtr + (len - written); -return ret ? ret : -EFAULT ; +return -EFAULT ; } } len =vwrite (kbuf, (char *)p, len);
@@ -563,8 +558,11 @@ static ssize_t write_port(struct file *return -EFAULT ;while (count-- >0 && i <65536 ) {char c; -if (__get_user (c, tmp)) +if (__get_user (c, tmp)) { +if (tmp > buf) +break ;return -EFAULT ; + }outb (c,i); i++; tmp++;
Quoted 3 lines · Jan Beulich
The
/dev/memand/dev/kmemwrite handlers weren't fully POSIX compliant in that they wouldn't always force the file pointer to be updated when returning success status.
should we instead just remove the /dev/mem and/or /dev/kmem write handlers entirely?
Quoted 7 lines · Arjan van de Ven
Quoted 3 lines · Jan Beulich
The
/dev/memand/dev/kmemwrite handlers weren't fully POSIX compliant in that they wouldn't always force the file pointer to be updated when returning success status.should we instead just remove the
/dev/memand/or/dev/kmemwrite handlers entirely?
As long as I can still mmap offsets and write directly, I don't think SGI will have any issue. For diagnostics, SGI uses mmap of architecture specific registers and injects errors to ensure signals get completely through and processed correctly. Of course, the last time I talked with anybody about that stuff was more than a year ago and things may have changed. I can ask around to see if anybody is using write, but I would be very surprised.
Thanks,
Robin Holt
Quoted 7 lines · Arjan van de Ven
Quoted 3 lines · Jan Beulich
The
/dev/memand/dev/kmemwrite handlers weren't fully POSIX compliant in that they wouldn't always force the file pointer to be updated when returning success status.should we instead just remove the
/dev/memand/or/dev/kmemwrite handlers entirely?
If you mmap it doesn't make any sense to not have read/write. And they are sometimes quite useful for debugging.
-Andi
Quoted 3 lines
If you mmap it doesn't make any sense to not have read/write. And they are sometimes quite useful for debugging.
Agreed, I use them quite a lot too.
Anton
Quoted 16 lines · Jan Beulich
The
/dev/memand/dev/kmemwrite handlers weren't fully POSIX compliant in that they wouldn't always force the file pointer to be updated when returning success status.
The/dev/portwrite handler was inconsistent with the/dev/memand/dev/kmemhandlers in that when encountering a-EFAULTcondition after already having written a number of items it would return-EFAULTrather than the number of bytes written....
(quoted diff) +0
-1@@ -514,11 +510,10 @@ static ssize_t write_kmem(struct file * if (len) { written = copy_from_user(kbuf, buf, len); if (written) { - ssize_t ret;
Review static ssize_t write_kmem(struct file * · line 519
Quoted 10 lines
(quoted diff) +3
-3- + if (wrote + virtr) + break; free_page((unsigned long)kbuf); - ret = wrote + virtr + (len - written); - return ret ? ret : -EFAULT; + return -EFAULT; } } len = vwrite(kbuf, (char *)p, len);
I think write_kmem() still isn't quie right - it needs to update `p' (and hence *ppos) to account for a partial copy_from_user(). (Please double-check)
drivers/char/mem.c renamed from drivers/char/mem.c~adjust-dev-kmemmemport-write-handlers-fix +4 -1
@@ -504,8 +504,11 @@ static ssize_t write_kmem(struct file *if (len) { written =copy_from_user (kbuf, buf, len);if (written) { -if (wrote + virtr) +if (wrote + virtr) { + p += len - written; + virtr += len - written;break ; + }free_page ((unsigned long )kbuf);return -EFAULT ; }
_
Quoted 11 lines
Quoted 11 lines
(quoted diff) +2
-4@@ -514,11 +510,10 @@ static ssize_t write_kmem(struct file * if (len) { written = copy_from_user(kbuf, buf, len); if (written) { - ssize_t ret; - + if (wrote + virtr) + break; free_page((unsigned long)kbuf); - ret = wrote + virtr + (len - written); - return ret ? ret : -EFAULT;
Quoted 8 lines
Review static ssize_t write_kmem(struct file * · line 519
Quoted 4 lines
(quoted diff) +1
-0+ return -EFAULT; } } len = vwrite(kbuf, (char *)p, len);I think
write_kmem()still isn't quie right - it needs to update `p' (and hence *ppos) to account for a partialcopy_from_user(). (Please double-check)
No, I disagree. The actual write happens with the call to vwrite(), independent of the reading of the user buffer. If any adjustment might be needed, then it would be to account for the potential of vwrite() (and similarly vread()) to return 0, resulting in no progress being possible to be made anymore.
Jan