linux syscall modify_ldt() returning wrong errno

View: New views
2 Messages — Rating Filter:   Alert me  

linux syscall modify_ldt() returning wrong errno

by Alexander Best :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi there,

i'm currently playing a bit with the linux test project (ltp). it seems the
linux syscall modify_ldt() isn't implemented correctly. the following code
should set errno to ENOSYS, but instead EINVAL is being returned:

int main(int ac, char **av)
{
        int lc;                 /* loop counter */
        char *msg;              /* message returned from parse_opts */

        void *ptr;
        int retval, func;

        int flag;
        int seg[4];

        /* parse standard options */
        if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char
        *)NULL) {
                tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
         /*NOTREACHED*/}

        setup();                /* global setup */

        /* The following loop checks looping state if -i option given */
        for (lc = 0; TEST_LOOPING(lc); lc++) {

                /* reset Tst_count in case we are looping */
                Tst_count = 0;

//block1:
                /*
                 * Check for ENOSYS.
                 */
                tst_resm(TINFO, "Enter block 1");
                flag = 0;
                ptr = (void *)malloc(10);
                func = 100;
                retval = modify_ldt(func, ptr, sizeof(ptr));
                if (retval < 0) {
                        if (errno != ENOSYS) {
                                tst_resm(TFAIL, "modify_ldt() set invalid "
                                         "errno, expected ENOSYS, got: %d",
                                         errno);
                                flag = FAILED;
                        }

here's the way linux does it:
http://fxr.watson.org/fxr/source/arch/x86_64/kernel/ldt.c?v=linux-2.6;im=bigexcerpts#L233

and this is how the syscall was implemented in freebsd:
http://fxr.watson.org/fxr/source/i386/linux/linux_machdep.c#L861

here's the modify_ldt() manual:
http://linux.about.com/library/cmd/blcmdl2_modify_ldt.htm

cheers.

oh...and we're talking HEAD of course. ;-)
_______________________________________________
freebsd-hackers@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@..."

Re: linux syscall modify_ldt() returning wrong errno

by John Baldwin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thursday 25 June 2009 6:25:31 pm Alexander Best wrote:
> hi there,
>
> i'm currently playing a bit with the linux test project (ltp). it seems the
> linux syscall modify_ldt() isn't implemented correctly. the following code
> should set errno to ENOSYS, but instead EINVAL is being returned:

It looks like this should fix it:

--- //depot/vendor/freebsd/src/sys/i386/linux/linux_machdep.c 2009/02/18 16:15:14
+++ //depot/user/jhb/acpipci/i386/linux/linux_machdep.c 2009/06/26 14:32:55
@@ -866,9 +866,6 @@
  union descriptor desc;
  int size, written;
 
- if (uap->ptr == NULL)
- return (EINVAL);
-
  switch (uap->func) {
  case 0x00: /* read_ldt */
  ldt.start = 0;
@@ -911,7 +908,7 @@
  error = i386_set_ldt(td, &ldt, &desc);
  break;
  default:
- error = EINVAL;
+ error = ENOSYS;
  break;
  }
 

--
John Baldwin
_______________________________________________
freebsd-hackers@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@..."