Thu Mar 5 02:02:08 2020 UTC ()
copyoutstr(9): return ENAMETOOLONG correctly when source string is
not NUL-terminated.


(rin)
diff -r1.7 -r1.8 src/sys/arch/powerpc/booke/copyout.c

cvs diff -r1.7 -r1.8 src/sys/arch/powerpc/booke/copyout.c (expand / switch to unified diff)

--- src/sys/arch/powerpc/booke/copyout.c 2020/03/05 00:33:56 1.7
+++ src/sys/arch/powerpc/booke/copyout.c 2020/03/05 02:02:08 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: copyout.c,v 1.7 2020/03/05 00:33:56 rin Exp $ */ 1/* $NetBSD: copyout.c,v 1.8 2020/03/05 02:02:08 rin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects 8 * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
9 * Agency and which was developed by Matt Thomas of 3am Software Foundry. 9 * Agency and which was developed by Matt Thomas of 3am Software Foundry.
10 * 10 *
11 * This material is based upon work supported by the Defense Advanced Research 11 * This material is based upon work supported by the Defense Advanced Research
12 * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under 12 * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
13 * Contract No. N66001-09-C-2073. 13 * Contract No. N66001-09-C-2073.
14 * Approved for Public Release, Distribution Unlimited 14 * Approved for Public Release, Distribution Unlimited
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: copyout.c,v 1.7 2020/03/05 00:33:56 rin Exp $"); 39__KERNEL_RCSID(0, "$NetBSD: copyout.c,v 1.8 2020/03/05 02:02:08 rin Exp $");
40 40
41#define __UFETCHSTORE_PRIVATE 41#define __UFETCHSTORE_PRIVATE
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/lwp.h> 44#include <sys/lwp.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46 46
47#include <powerpc/pcb.h> 47#include <powerpc/pcb.h>
48 48
49#include <powerpc/booke/cpuvar.h> 49#include <powerpc/booke/cpuvar.h>
50 50
51static inline void 51static inline void
52copyout_uint8(uint8_t *udaddr, uint8_t data, register_t ds_msr) 52copyout_uint8(uint8_t *udaddr, uint8_t data, register_t ds_msr)
@@ -422,33 +422,35 @@ copyoutstr(const void *ksaddr, void *uda @@ -422,33 +422,35 @@ copyoutstr(const void *ksaddr, void *uda
422 return rv; 422 return rv;
423 } 423 }
424 424
425 const register_t ds_msr = mfmsr() | PSL_DS; 425 const register_t ds_msr = mfmsr() | PSL_DS;
426 const uint8_t *ksaddr8 = ksaddr; 426 const uint8_t *ksaddr8 = ksaddr;
427 size_t copylen = 0; 427 size_t copylen = 0;
428 428
429 uint8_t *udaddr8 = (void *)udaddr; 429 uint8_t *udaddr8 = (void *)udaddr;
430 430
431 while (copylen++ < len) { 431 while (copylen++ < len) {
432 const uint8_t data = *ksaddr8++; 432 const uint8_t data = *ksaddr8++;
433 copyout_uint8(udaddr8++, data, ds_msr); 433 copyout_uint8(udaddr8++, data, ds_msr);
434 if (data == 0) 434 if (data == 0)
435 break; 435 goto out;
436 } 436 }
 437 rv = ENAMETOOLONG;
437 438
 439out:
438 pcb->pcb_onfault = NULL; 440 pcb->pcb_onfault = NULL;
439 if (done) 441 if (done)
440 *done = copylen; 442 *done = copylen;
441 return 0; 443 return rv;
442} 444}
443#else 445#else
444/* XXX This version of copyoutstr(9) has never beeen enabled so far. */ 446/* XXX This version of copyoutstr(9) has never beeen enabled so far. */
445int 447int
446copyoutstr(const void *ksaddr, void *udaddr, size_t len, size_t *lenp) 448copyoutstr(const void *ksaddr, void *udaddr, size_t len, size_t *lenp)
447{ 449{
448 struct pcb * const pcb = lwp_getpcb(curlwp); 450 struct pcb * const pcb = lwp_getpcb(curlwp);
449 struct faultbuf env; 451 struct faultbuf env;
450 452
451 if (__predict_false(len == 0)) { 453 if (__predict_false(len == 0)) {
452 if (lenp) 454 if (lenp)
453 *lenp = 0; 455 *lenp = 0;
454 return 0; 456 return 0;