lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1425936003-24544-4-git-send-email-zenczykowski@gmail.com>
Date:	Mon,  9 Mar 2015 14:19:59 -0700
From:	Maciej Żenczykowski <zenczykowski@...il.com>
To:	Maciej Żenczykowski <maze@...gle.com>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>
Cc:	Theodore Ts'o <tytso@....edu>, netdev@...r.kernel.org
Subject: [PATCH 4/8] net/socket: sys_accept4 - reverse allocation order

From: Maciej Żenczykowski <maze@...gle.com>

Signed-off-by: Maciej Żenczykowski <maze@...gle.com>
---
 net/socket.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index a62c5cda5720..87fd36939778 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1473,38 +1473,37 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
 	 */
 	__module_get(newsock->ops->owner);
 
-	newfd = get_unused_fd_flags(flags);
-	if (unlikely(newfd < 0)) {
-		err = newfd;
-		sock_release(newsock);
-		goto out_put;
-	}
 	newfile = sock_alloc_file(newsock, flags, sock->sk->sk_prot_creator->name);
 	if (unlikely(IS_ERR(newfile))) {
 		err = PTR_ERR(newfile);
-		put_unused_fd(newfd);
 		sock_release(newsock);
 		goto out_put;
 	}
 
 	err = security_socket_accept(sock, newsock);
 	if (err)
-		goto out_fd;
+		goto out_fput;
 
 	err = sock->ops->accept(sock, newsock, sock->file->f_flags);
 	if (err < 0)
-		goto out_fd;
+		goto out_fput;
 
 	if (upeer_sockaddr) {
 		if (newsock->ops->getname(newsock, (struct sockaddr *)&address,
 					  &len, 2) < 0) {
 			err = -ECONNABORTED;
-			goto out_fd;
+			goto out_fput;
 		}
 		err = move_addr_to_user(&address,
 					len, upeer_sockaddr, upeer_addrlen);
 		if (err < 0)
-			goto out_fd;
+			goto out_fput;
+	}
+
+	newfd = get_unused_fd_flags(flags);
+	if (unlikely(newfd < 0)) {
+		err = newfd;
+		goto out_fput;
 	}
 
 	/* File flags are not inherited via accept() unlike another OSes. */
@@ -1516,9 +1515,8 @@ out_put:
 	fput_light(sock->file, fput_needed);
 out:
 	return err;
-out_fd:
+out_fput:
 	fput(newfile);
-	put_unused_fd(newfd);
 	goto out_put;
 }
 
-- 
2.2.0.rc0.207.ga3a616c

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ