Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc/ibm4xx copy{in,out}str: Correctly return EN...



details:   https://anonhg.NetBSD.org/src/rev/b4627d58d303
branches:  trunk
changeset: 1007930:b4627d58d303
user:      rin <rin%NetBSD.org@localhost>
date:      Thu Mar 05 01:10:57 2020 +0000

description:
copy{in,out}str: Correctly return ENAMETOOLONG if source is not
NUL-terminated.

diffstat:

 sys/arch/powerpc/ibm4xx/copyinstr.c  |  21 ++++++++++++---------
 sys/arch/powerpc/ibm4xx/copyoutstr.c |  21 ++++++++++++---------
 2 files changed, 24 insertions(+), 18 deletions(-)

diffs (139 lines):

diff -r fd91823870d9 -r b4627d58d303 sys/arch/powerpc/ibm4xx/copyinstr.c
--- a/sys/arch/powerpc/ibm4xx/copyinstr.c       Thu Mar 05 00:54:13 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/copyinstr.c       Thu Mar 05 01:10:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: copyinstr.c,v 1.10 2020/03/05 00:54:13 rin Exp $       */
+/*     $NetBSD: copyinstr.c,v 1.11 2020/03/05 01:10:57 rin Exp $       */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyinstr.c,v 1.10 2020/03/05 00:54:13 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyinstr.c,v 1.11 2020/03/05 01:10:57 rin Exp $");
 
 #include <sys/param.h>
 #include <uvm/uvm_extern.h>
@@ -46,7 +46,8 @@
 copyinstr(const void *udaddr, void *kaddr, size_t len, size_t *done)
 {
        struct pmap *pm = curproc->p_vmspace->vm_map.pmap;
-       int rv, msr, pid, tmp, ctx;
+       size_t resid;
+       int rv, msr, pid, data, ctx;
        struct faultbuf env;
 
        if (__predict_false(len == 0)) {
@@ -68,6 +69,7 @@
                ctx = pm->pm_ctx;
        }
 
+       resid = len;
        __asm volatile(
                "mtctr %3;"                     /* Set up counter */
                "mfmsr %0;"                     /* Save MSR */
@@ -76,8 +78,6 @@
                "mfpid %1;"                     /* Save old PID */
                "sync; isync;"
 
-               "li %3,0;"                      /* Clear len */
-
                "1: "
                "mtpid %4; sync;"               /* Load user ctx */
                "lbz %2,0(%5); addi %5,%5,1;"   /* Load byte */
@@ -86,16 +86,19 @@
                "stb %2,0(%6); dcbf 0,%6; addi %6,%6,1;"
                                                /* Store kernel byte */
                "sync; isync;"
-               "addi %3,%3,1;"                 /* Inc len */
                "or. %2,%2,%2;"
                "bdnzf 2,1b;"                   /* while(ctr-- && !zero) */
                "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
                "sync; isync;"
-               : "=&r" (msr), "=&r" (pid), "=&r" (tmp), "+b" (len)
+               "mfctr %3;"                     /* Restore resid */
+               : "=&r" (msr), "=&r" (pid), "=&r" (data), "+r" (resid)
                : "r" (ctx), "b" (udaddr), "b" (kaddr));
 
        curpcb->pcb_onfault = NULL;
        if (done)
-               *done = len;
-       return 0;
+               *done = len - resid;
+       if (resid == 0 && (char)data != '\0')
+               return ENAMETOOLONG;
+       else
+               return 0;
 }
diff -r fd91823870d9 -r b4627d58d303 sys/arch/powerpc/ibm4xx/copyoutstr.c
--- a/sys/arch/powerpc/ibm4xx/copyoutstr.c      Thu Mar 05 00:54:13 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/copyoutstr.c      Thu Mar 05 01:10:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: copyoutstr.c,v 1.10 2020/03/05 00:54:13 rin Exp $      */
+/*     $NetBSD: copyoutstr.c,v 1.11 2020/03/05 01:10:57 rin Exp $      */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyoutstr.c,v 1.10 2020/03/05 00:54:13 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyoutstr.c,v 1.11 2020/03/05 01:10:57 rin Exp $");
 
 #include <sys/param.h>
 #include <uvm/uvm_extern.h>
@@ -46,7 +46,8 @@
 copyoutstr(const void *kaddr, void *udaddr, size_t len, size_t *done)
 {
        struct pmap *pm = curproc->p_vmspace->vm_map.pmap;
-       int rv, msr, pid, tmp, ctx;
+       size_t resid;
+       int rv, msr, pid, data, ctx;
        struct faultbuf env;
 
        if (__predict_false(len == 0)) {
@@ -68,6 +69,7 @@
                ctx = pm->pm_ctx;
        }
 
+       resid = len;
        __asm volatile(
                "mtctr %3;"                     /* Set up counter */
                "mfmsr %0;"                     /* Save MSR */
@@ -76,8 +78,6 @@
                "mfpid %1;"                     /* Save old PID */
                "sync; isync;"
 
-               "li %3,0;"                      /* Clear len */
-
                "1:"
                "mtpid %1;sync;"
                "lbz %2,0(%6); addi %6,%6,1;"   /* Store kernel byte */
@@ -86,17 +86,20 @@
                "stb %2,0(%5); dcbf 0,%5; addi %5,%5,1;"
                                                /* Load byte */
                "sync; isync;"
-               "addi %3,%3,1;"                 /* Inc len */
                "or. %2,%2,%2;"
                "bdnzf 2,1b;"                   /* while(ctr-- && !zero) */
 
                "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
                "sync; isync;"
-               : "=&r" (msr), "=&r" (pid), "=&r" (tmp), "+b" (len)
+               "mfctr %3;"                     /* Restore resid */
+               : "=&r" (msr), "=&r" (pid), "=&r" (data), "+r" (resid)
                : "r" (ctx), "b" (udaddr), "b" (kaddr));
 
        curpcb->pcb_onfault = NULL;
        if (done)
-               *done = len;
-       return 0;
+               *done = len - resid;
+       if (resid == 0 && (char)data != '\0')
+               return ENAMETOOLONG;
+       else
+               return 0;
 }



Home | Main Index | Thread Index | Old Index