Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Feb 2017 14:03:26 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r313283 - head/sys/compat/linux
Message-ID:  <201702051403.v15E3QwK001257@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Sun Feb  5 14:03:25 2017
New Revision: 313283
URL: https://svnweb.freebsd.org/changeset/base/313283

Log:
  Fix linux_pipe() and linux_pipe2() to close file descriptors on copyout
  error.
  
  Reviewed by:	dchagin
  MFC after:	2 weeks
  Sponsored by:	DARPA, AFRL
  Differential Revision:	https://reviews.freebsd.org/D9425

Modified:
  head/sys/compat/linux/linux_file.c

Modified: head/sys/compat/linux/linux_file.c
==============================================================================
--- head/sys/compat/linux/linux_file.c	Sun Feb  5 13:37:23 2017	(r313282)
+++ head/sys/compat/linux/linux_file.c	Sun Feb  5 14:03:25 2017	(r313283)
@@ -1537,11 +1537,16 @@ linux_pipe(struct thread *td, struct lin
 #endif
 
 	error = kern_pipe(td, fildes, 0, NULL, NULL);
-	if (error)
+	if (error != 0)
 		return (error);
 
-	/* XXX: Close descriptors on error. */
-	return (copyout(fildes, args->pipefds, sizeof(fildes)));
+	error = copyout(fildes, args->pipefds, sizeof(fildes));
+	if (error != 0) {
+		(void)kern_close(td, fildes[0]);
+		(void)kern_close(td, fildes[1]);
+	}
+
+	return (error);
 }
 
 int
@@ -1564,11 +1569,16 @@ linux_pipe2(struct thread *td, struct li
 	if ((args->flags & LINUX_O_CLOEXEC) != 0)
 		flags |= O_CLOEXEC;
 	error = kern_pipe(td, fildes, flags, NULL, NULL);
-	if (error)
+	if (error != 0)
 		return (error);
 
-	/* XXX: Close descriptors on error. */
-	return (copyout(fildes, args->pipefds, sizeof(fildes)));
+	error = copyout(fildes, args->pipefds, sizeof(fildes));
+	if (error != 0) {
+		(void)kern_close(td, fildes[0]);
+		(void)kern_close(td, fildes[1]);
+	}
+
+	return (error);
 }
 
 int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201702051403.v15E3QwK001257>