copyinstr()

Oliver Pinter oliver.pntr at gmail.com
Tue Apr 9 17:15:59 UTC 2013


On 4/9/13, Vijay Singh <vijju.singh at gmail.com> wrote:
> Hi, I was looking for some help with copyinstr() on an amd64 platform.
>
> My from address happens to be in the kernel (stack). I am getting an
> EFAULT, and I am wondering how to fix that.
>
> Would using memory from malloc() make a difference?

The copyinstr check the address before do anything.

amd64/support.S:

/*
 * copyinstr(from, to, maxlen, int *lencopied) - MP SAFE
 *           %rdi, %rsi, %rdx, %rcx
 *
 *      copy a string from from to to, stop when a 0 character is reached.
 *      return ENAMETOOLONG if string is longer than maxlen, and
 *      EFAULT on protection violations. If lencopied is non-zero,
 *      return the actual length in *lencopied.
 */
ENTRY(copyinstr)
        movq    %rdx,%r8                        /* %r8 = maxlen */
        movq    %rcx,%r9                        /* %r9 = *len */
        xchgq   %rdi,%rsi                       /* %rdi = from, %rsi = to */
        movq    PCPU(CURPCB),%rcx
        movq    $cpystrflt,PCB_ONFAULT(%rcx)

        movq    $VM_MAXUSER_ADDRESS,%rax

        /* make sure 'from' is within bounds */
        subq    %rsi,%rax
        jbe     cpystrfl

       [...]

       cpystrflt:
        movq    $EFAULT,%rax

       [...]

Try copyout() instead of copyinstr(), as there in amd64 are no copyoutstr().

>
> -vijay
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
>


More information about the freebsd-hackers mailing list