From: Steve Dickson <SteveD@redhat.com>
To: Susant Sahani <ssahani@redhat.com>,
Libtirpc-devel Mailing List
<libtirpc-devel@lists.sourceforge.net>
Cc: Linux NFS Mailing list <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH 1/1] data race in bindresvport_sa
Date: Fri, 22 Nov 2013 11:28:33 -0500 [thread overview]
Message-ID: <528F8631.2070604@RedHat.com> (raw)
In-Reply-To: <1384966173-6229-1-git-send-email-ssahani@redhat.com>
Hello,
Would it be possible to get a little better description as
to what this patch does and why its needed...
"data race in bindresvport_sa" have very little
meaning, at least to me...
More comments below...
On 20/11/13 11:49, Susant Sahani wrote:
> Signed-off-by: Susant Sahani <ssahani@redhat.com>
> ---
> src/bindresvport.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/src/bindresvport.c b/src/bindresvport.c
> index 6ce3e81..d26d754 100644
> --- a/src/bindresvport.c
> +++ b/src/bindresvport.c
> @@ -46,6 +46,7 @@
> #include <rpc/rpc.h>
>
> #include <string.h>
> +#include <reentrant.h>
>
> /*
> * Bind a socket to a privileged IP port
> @@ -79,17 +80,23 @@ bindresvport_sa(sd, sa)
> u_int16_t *portp;
> static u_int16_t port;
> static short startport = STARTPORT;
> + static pthread_mutex_t port_lock = PTHREAD_MUTEX_INITIALIZER;
How come you define this mutex statically instead in src/mt_misc.c
like the rest of the mutexes?
Would you mind moving this (and the other two in the patches)
to src/mt_misc.c and added a commit talking about what they
are protecting
tia!
steved.
> socklen_t salen;
> - int nports = ENDPORT - startport + 1;
> + int nports;
> int endport = ENDPORT;
> int i;
>
> + mutex_lock(&port_lock);
> + nports = ENDPORT - startport + 1;
> +
> if (sa == NULL) {
> salen = sizeof(myaddr);
> sa = (struct sockaddr *)&myaddr;
>
> - if (getsockname(sd, (struct sockaddr *)&myaddr, &salen) == -1)
> - return -1; /* errno is correctly set */
> + if (getsockname(sd, (struct sockaddr *)&myaddr, &salen) == -1) {
> + mutex_unlock(&port_lock);
> + return -1; /* errno is correctly set */
> + }
>
> af = myaddr.ss_family;
> } else
> @@ -112,6 +119,7 @@ bindresvport_sa(sd, sa)
> #endif
> default:
> errno = EPFNOSUPPORT;
> + mutex_unlock(&port_lock);
> return (-1);
> }
> sa->sa_family = af;
> @@ -137,6 +145,8 @@ bindresvport_sa(sd, sa)
> port = LOWPORT + port % (STARTPORT - LOWPORT);
> goto again;
> }
> + mutex_unlock(&port_lock);
> +
> return (res);
> }
> #else
>
next prev parent reply other threads:[~2013-11-22 16:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-20 16:49 [PATCH 1/1] data race in bindresvport_sa Susant Sahani
2013-11-20 16:49 ` [PATCH] __nc_error() does not check return value from malloc Susant Sahani
2013-11-25 20:09 ` [Libtirpc-devel] " Steve Dickson
2013-11-20 16:49 ` [PATCH 1/1] race in clnt_vc_create Susant Sahani
2013-11-20 16:49 ` [PATCH 1/1] Race in getnetconfig Susant Sahani
2013-11-22 16:28 ` Steve Dickson [this message]
2013-11-25 17:49 ` [PATCH 1/1] data race in bindresvport_sa Susant Sahani
2013-11-25 20:11 ` [Libtirpc-devel] " Steve Dickson
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=528F8631.2070604@RedHat.com \
--to=steved@redhat.com \
--cc=libtirpc-devel@lists.sourceforge.net \
--cc=linux-nfs@vger.kernel.org \
--cc=ssahani@redhat.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 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.