[Devel] [PATCH 4/5] Add a common sock_bind() helper to unify the security hook

Dan Smith danms at us.ibm.com
Wed Jul 22 13:41:40 PDT 2009


This moves the meat out of the bind() syscall into a helper function that
performs security_socket_bind() and then sock->ops->bind().  This allows a
unification of this behavior between the syscall and the pending socket
restart logic.

Signed-off-by: Dan Smith <danms at us.ibm.com>
---
 include/net/sock.h |   16 ++++++++++++++++
 net/socket.c       |   13 ++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 2c0da92..d435dc1 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1572,6 +1572,22 @@ extern void sock_enable_timestamp(struct sock *sk, int flag);
 extern int sock_get_timestamp(struct sock *, struct timeval __user *);
 extern int sock_get_timestampns(struct sock *, struct timespec __user *);
 
+/* bind() helper shared between any callers needing to perform a bind on
+ * behalf of userspace (syscall and restart) with the security hooks.
+ */
+static inline int sock_bind(struct socket *sock,
+			    struct sockaddr *addr,
+			    int addr_len)
+{
+	int err;
+
+	err = security_socket_bind(sock, addr, addr_len);
+	if (err)
+		return err;
+	else
+		return sock->ops->bind(sock, addr, addr_len);
+}
+
 /* 
  *	Enable debug/info messages 
  */
diff --git a/net/socket.c b/net/socket.c
index 791d71a..017f6e6 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1414,15 +1414,10 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
 	sock = sockfd_lookup_light(fd, &err, &fput_needed);
 	if (sock) {
 		err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
-		if (err >= 0) {
-			err = security_socket_bind(sock,
-						   (struct sockaddr *)&address,
-						   addrlen);
-			if (!err)
-				err = sock->ops->bind(sock,
-						      (struct sockaddr *)
-						      &address, addrlen);
-		}
+		if (err >= 0)
+			err = sock_bind(sock,
+					(struct sockaddr *)&address,
+					addrlen);
 		fput_light(sock->file, fput_needed);
 	}
 	return err;
-- 
1.6.2.5

_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list