Author: markj
Date: Mon Feb 25 15:50:59 2019
New Revision: 344521
URL: https://svnweb.freebsd.org/changeset/base/344521

Log:
  MFC r344232:
  Fix refcount leaks in the SGX Linux compat ioctl handler.

Modified:
  stable/12/sys/amd64/sgx/sgx_linux.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/amd64/sgx/sgx_linux.c
==============================================================================
--- stable/12/sys/amd64/sgx/sgx_linux.c Mon Feb 25 15:50:28 2019        
(r344520)
+++ stable/12/sys/amd64/sgx/sgx_linux.c Mon Feb 25 15:50:59 2019        
(r344521)
@@ -70,30 +70,26 @@ sgx_linux_ioctl(struct thread *td, struct linux_ioctl_
        cmd = args->cmd;
 
        args->cmd &= ~(LINUX_IOC_IN | LINUX_IOC_OUT);
-       if (cmd & LINUX_IOC_IN)
+       if ((cmd & LINUX_IOC_IN) != 0)
                args->cmd |= IOC_IN;
-       if (cmd & LINUX_IOC_OUT)
+       if ((cmd & LINUX_IOC_OUT) != 0)
                args->cmd |= IOC_OUT;
 
        len = IOCPARM_LEN(cmd);
        if (len > SGX_IOCTL_MAX_DATA_LEN) {
-               printf("%s: Can't copy data: cmd len is too big %d\n",
-                   __func__, len);
-               return (EINVAL);
+               error = EINVAL;
+               goto out;
        }
 
-       if (cmd & LINUX_IOC_IN) {
+       if ((cmd & LINUX_IOC_IN) != 0) {
                error = copyin((void *)args->arg, data, len);
-               if (error) {
-                       printf("%s: Can't copy data, error %d\n",
-                           __func__, error);
-                       return (EINVAL);
-               }
+               if (error != 0)
+                       goto out;
        }
 
-       error = (fo_ioctl(fp, args->cmd, (caddr_t)data, td->td_ucred, td));
+       error = fo_ioctl(fp, args->cmd, (caddr_t)data, td->td_ucred, td);
+out:
        fdrop(fp, td);
-
        return (error);
 }
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to