From: Oren Laadan <orenl@cs.columbia.edu>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-api@vger.kernel.org, Serge Hallyn <serue@us.ibm.com>,
Ingo Molnar <mingo@elte.hu>,
containers@lists.linux-foundation.org,
Dan Smith <danms@us.ibm.com>,
netdev@vger.kernel.org
Subject: [C/R v20][PATCH 74/96] Add common socket helpers to unify the security hooks
Date: Wed, 17 Mar 2010 12:09:02 -0400 [thread overview]
Message-ID: <1268842164-5590-75-git-send-email-orenl@cs.columbia.edu> (raw)
In-Reply-To: <1268842164-5590-74-git-send-email-orenl@cs.columbia.edu>
From: Dan Smith <danms@us.ibm.com>
This moves the meat out of the bind(), getsockname(), and getpeername() syscalls
into helper functions that performs security_socket_bind() and then the
sock->ops->call(). This allows a unification of this behavior between the
syscalls and the pending socket restart logic.
Signed-off-by: Dan Smith <danms@us.ibm.com>
Acked-by: Serge E. Hallyn <serue@us.ibm.com>
Tested-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: netdev@vger.kernel.org
---
include/net/sock.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
net/socket.c | 29 ++++++-----------------------
2 files changed, 54 insertions(+), 23 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 3f1a480..623eb19 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1616,6 +1616,54 @@ 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);
+}
+
+/* getname() helper shared between any callers needing to perform a getname on
+ * behalf of userspace (syscall and restart) with the security hooks.
+ */
+static inline int sock_getname(struct socket *sock,
+ struct sockaddr *addr,
+ int *addr_len)
+{
+ int err;
+
+ err = security_socket_getsockname(sock);
+ if (err)
+ return err;
+ else
+ return sock->ops->getname(sock, addr, addr_len, 0);
+}
+
+/* getpeer() helper shared between any callers needing to perform a getpeer on
+ * behalf of userspace (syscall and restart) with the security hooks.
+ */
+static inline int sock_getpeer(struct socket *sock,
+ struct sockaddr *addr,
+ int *addr_len)
+{
+ int err;
+
+ err = security_socket_getpeername(sock);
+ if (err)
+ return err;
+ else
+ return sock->ops->getname(sock, addr, addr_len, 1);
+}
+
/*
* Enable debug/info messages
*/
diff --git a/net/socket.c b/net/socket.c
index 769c386..4d4fdc2 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1421,15 +1421,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;
@@ -1608,11 +1603,7 @@ SYSCALL_DEFINE3(getsockname, int, fd, struct sockaddr __user *, usockaddr,
if (!sock)
goto out;
- err = security_socket_getsockname(sock);
- if (err)
- goto out_put;
-
- err = sock->ops->getname(sock, (struct sockaddr *)&address, &len, 0);
+ err = sock_getname(sock, (struct sockaddr *)&address, &len);
if (err)
goto out_put;
err = move_addr_to_user((struct sockaddr *)&address, len, usockaddr, usockaddr_len);
@@ -1637,15 +1628,7 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
sock = sockfd_lookup_light(fd, &err, &fput_needed);
if (sock != NULL) {
- err = security_socket_getpeername(sock);
- if (err) {
- fput_light(sock->file, fput_needed);
- return err;
- }
-
- err =
- sock->ops->getname(sock, (struct sockaddr *)&address, &len,
- 1);
+ err = sock_getpeer(sock, (struct sockaddr *)&address, &len);
if (!err)
err = move_addr_to_user((struct sockaddr *)&address, len, usockaddr,
usockaddr_len);
--
1.6.3.3
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next parent reply other threads:[~2010-03-17 16:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1268842164-5590-1-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-2-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-3-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-4-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-5-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-6-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-7-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-8-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-9-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-10-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-11-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-12-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-13-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-14-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-15-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-16-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-17-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-18-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-19-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-20-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-21-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-22-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-23-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-24-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-25-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-26-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-27-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-28-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-29-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-30-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-31-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-32-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-33-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-34-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-35-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-36-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-37-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-38-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-39-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-40-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-41-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-42-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-43-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-44-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-45-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-46-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-47-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-48-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-49-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-50-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-51-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-52-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-53-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-54-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-55-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-56-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-57-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-58-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-59-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-60-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-61-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-62-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-63-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-64-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-65-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-66-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-67-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-68-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-69-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-70-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-71-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-72-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-73-git-send-email-orenl@cs.columbia.edu>
[not found] ` <1268842164-5590-74-git-send-email-orenl@cs.columbia.edu>
2010-03-17 16:09 ` Oren Laadan [this message]
[not found] ` <1268842164-5590-76-git-send-email-orenl@cs.columbia.edu>
2010-03-17 16:09 ` [C/R v20][PATCH 76/96] c/r: Add AF_UNIX support (v12) Oren Laadan
[not found] ` <1268842164-5590-78-git-send-email-orenl@cs.columbia.edu>
2010-03-17 16:09 ` [C/R v20][PATCH 78/96] c/r: add support for connected INET sockets (v5) Oren Laadan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1268842164-5590-75-git-send-email-orenl@cs.columbia.edu \
--to=orenl@cs.columbia.edu \
--cc=akpm@linux-foundation.org \
--cc=containers@lists.linux-foundation.org \
--cc=danms@us.ibm.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@elte.hu \
--cc=netdev@vger.kernel.org \
--cc=serue@us.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox