All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: Dan Smith <danms@us.ibm.com>
Cc: containers@lists.osdl.org, netdev@vger.kernel.org
Subject: Re: [PATCH 3/5] Add common socket helpers to unify the security hooks
Date: Tue, 4 Aug 2009 14:20:36 -0500	[thread overview]
Message-ID: <20090804192036.GC10275@us.ibm.com> (raw)
In-Reply-To: <1249331463-11887-4-git-send-email-danms@us.ibm.com>

Quoting 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>
> 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 2c0da92..43b9599 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -1572,6 +1572,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);

My only concern here is whether 0 should be passed in by the caller?
(Not sure, just wondering)

Otherwise this looks good, thanks.

Acked-by: Serge Hallyn <serue@us.ibm.com>

> +}
> +
> +/* 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 791d71a..65e7698 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;
> @@ -1610,11 +1605,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);
> @@ -1639,15 +1630,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.2.5
> 
> _______________________________________________
> Containers mailing list
> Containers@lists.linux-foundation.org
> https://lists.linux-foundation.org/mailman/listinfo/containers

  reply	other threads:[~2009-08-04 19:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-03 20:30 C/R support of UNIX sockets Dan Smith
     [not found] ` <1249331463-11887-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-08-03 20:30   ` [PATCH 1/5] Add an errno validation function (v2) Dan Smith
     [not found]     ` <1249331463-11887-2-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-08-04 19:10       ` Serge E. Hallyn
2009-08-03 20:31   ` [PATCH 2/5] Add a ckpt_read_string() " Dan Smith
     [not found]     ` <1249331463-11887-3-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-08-04 19:13       ` Serge E. Hallyn
     [not found]         ` <20090804191334.GB10275-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-08-04 19:20           ` Dan Smith
2009-08-03 20:31   ` [PATCH 4/5] Export fill_fname() as ckpt_fill_fname() Dan Smith
     [not found]     ` <1249331463-11887-5-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-08-04 19:24       ` Serge E. Hallyn
2009-08-03 20:31 ` [PATCH 3/5] Add common socket helpers to unify the security hooks Dan Smith
2009-08-04 19:20   ` Serge E. Hallyn [this message]
2009-08-04 19:43     ` Dan Smith
2009-08-04 19:58       ` Serge E. Hallyn
2009-08-03 20:31 ` [PATCH 5/5] c/r: Add AF_UNIX support (v7) Dan Smith
2009-08-04 19:57   ` Serge E. Hallyn
2009-08-04 20:52   ` Serge E. Hallyn
2009-08-04 21:02     ` Dan Smith
2009-08-04 21:17       ` Serge E. Hallyn
2009-08-04 22:24         ` Dan Smith
2009-08-04 22:31   ` Serge E. Hallyn
2009-08-04 22:47     ` Dan Smith
2009-08-05 13:29       ` Serge E. Hallyn
  -- strict thread matches above, loose matches on Subject: below --
2009-08-10 15:32 C/R support of UNIX sockets Dan Smith
2009-08-10 15:32 ` [PATCH 3/5] Add common socket helpers to unify the security hooks Dan Smith

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=20090804192036.GC10275@us.ibm.com \
    --to=serue@us.ibm.com \
    --cc=containers@lists.osdl.org \
    --cc=danms@us.ibm.com \
    --cc=netdev@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.