Patchwork [-next] sctp: fix error return code in __sctp_connect()

login
register
mail settings
Submitter Wei Yongjun
Date April 3, 2013, 1:02 p.m.
Message ID <CAPgLHd-X5Qw64BnaSMr2ny6==jXGpRAYC7_1MGhP2v_GcVeApQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/233443/
State Accepted
Delegated to: David Miller
Headers show

Comments

Wei Yongjun - April 3, 2013, 1:02 p.m.
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Fix to return a negative error code from the error handling
case instead of 0, as returned elsewhere in this function.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 net/sctp/socket.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Neil Horman - April 3, 2013, 1:51 p.m.
On Wed, Apr 03, 2013 at 09:02:28PM +0800, Wei Yongjun wrote:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> Fix to return a negative error code from the error handling
> case instead of 0, as returned elsewhere in this function.
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> ---
>  net/sctp/socket.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index dd21ae3..f631c5f 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1119,9 +1119,10 @@ static int __sctp_connect(struct sock* sk,
>  		/* Make sure the destination port is correctly set
>  		 * in all addresses.
>  		 */
> -		if (asoc && asoc->peer.port && asoc->peer.port != port)
> +		if (asoc && asoc->peer.port && asoc->peer.port != port) {
> +			err = -EINVAL;
>  			goto out_free;
> -
> +		}
>  
>  		/* Check if there already is a matching association on the
>  		 * endpoint (other than the one created here).
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
Actually, I think you can remove that entire if statement (as well as some
checks further down).  Looking at the net-next trees __sctp_connect, it appears
that asoc is set to NULL at the top of the function, and not assigned to
anything else until the call to sctp_association_new much farther down (line
1201).  That means the above if statement, as well as this:
 if (asoc2 && asoc2 != asoc) {
and this:
if (!asoc) {
will always be false, false, and true, respectively.

Regards
Neil

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vlad Yasevich - April 3, 2013, 2:52 p.m.
On 04/03/2013 09:51 AM, Neil Horman wrote:
> On Wed, Apr 03, 2013 at 09:02:28PM +0800, Wei Yongjun wrote:
>> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>>
>> Fix to return a negative error code from the error handling
>> case instead of 0, as returned elsewhere in this function.
>>
>> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>> ---
>>   net/sctp/socket.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
>> index dd21ae3..f631c5f 100644
>> --- a/net/sctp/socket.c
>> +++ b/net/sctp/socket.c
>> @@ -1119,9 +1119,10 @@ static int __sctp_connect(struct sock* sk,
>>   		/* Make sure the destination port is correctly set
>>   		 * in all addresses.
>>   		 */
>> -		if (asoc && asoc->peer.port && asoc->peer.port != port)
>> +		if (asoc && asoc->peer.port && asoc->peer.port != port) {
>> +			err = -EINVAL;
>>   			goto out_free;
>> -
>> +		}
>>
>>   		/* Check if there already is a matching association on the
>>   		 * endpoint (other than the one created here).
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
> Actually, I think you can remove that entire if statement (as well as some
> checks further down).  Looking at the net-next trees __sctp_connect, it appears
> that asoc is set to NULL at the top of the function, and not assigned to
> anything else until the call to sctp_association_new much farther down (line
> 1201).  That means the above if statement, as well as this:
>   if (asoc2 && asoc2 != asoc) {
> and this:
> if (!asoc) {
> will always be false, false, and true, respectively.

No, I don't think you can.  Consider a case of sctp_connectx() where 
each address specified in connectx has a different destination port.

First time through the loop, we'll create the association and set the 
peer.port.  The second time through the loop, we'll compare the that 
port to the port specified in the second address.  If the ports do not 
match, we need to stop.

-vlad
>
> Regards
> Neil
>

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vlad Yasevich - April 3, 2013, 2:52 p.m.
On 04/03/2013 09:02 AM, Wei Yongjun wrote:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>
> Fix to return a negative error code from the error handling
> case instead of 0, as returned elsewhere in this function.
>
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Acked-by: Vlad Yasevich <vyasevich@gmail.com>

-vlad

> ---
>   net/sctp/socket.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index dd21ae3..f631c5f 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1119,9 +1119,10 @@ static int __sctp_connect(struct sock* sk,
>   		/* Make sure the destination port is correctly set
>   		 * in all addresses.
>   		 */
> -		if (asoc && asoc->peer.port && asoc->peer.port != port)
> +		if (asoc && asoc->peer.port && asoc->peer.port != port) {
> +			err = -EINVAL;
>   			goto out_free;
> -
> +		}
>
>   		/* Check if there already is a matching association on the
>   		 * endpoint (other than the one created here).
>

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Neil Horman - April 3, 2013, 2:59 p.m.
On Wed, Apr 03, 2013 at 10:52:16AM -0400, Vlad Yasevich wrote:
> On 04/03/2013 09:51 AM, Neil Horman wrote:
> >On Wed, Apr 03, 2013 at 09:02:28PM +0800, Wei Yongjun wrote:
> >>From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> >>
> >>Fix to return a negative error code from the error handling
> >>case instead of 0, as returned elsewhere in this function.
> >>
> >>Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> >>---
> >>  net/sctp/socket.c | 5 +++--
> >>  1 file changed, 3 insertions(+), 2 deletions(-)
> >>
> >>diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> >>index dd21ae3..f631c5f 100644
> >>--- a/net/sctp/socket.c
> >>+++ b/net/sctp/socket.c
> >>@@ -1119,9 +1119,10 @@ static int __sctp_connect(struct sock* sk,
> >>  		/* Make sure the destination port is correctly set
> >>  		 * in all addresses.
> >>  		 */
> >>-		if (asoc && asoc->peer.port && asoc->peer.port != port)
> >>+		if (asoc && asoc->peer.port && asoc->peer.port != port) {
> >>+			err = -EINVAL;
> >>  			goto out_free;
> >>-
> >>+		}
> >>
> >>  		/* Check if there already is a matching association on the
> >>  		 * endpoint (other than the one created here).
> >>
> >>--
> >>To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> >>the body of a message to majordomo@vger.kernel.org
> >>More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >>
> >Actually, I think you can remove that entire if statement (as well as some
> >checks further down).  Looking at the net-next trees __sctp_connect, it appears
> >that asoc is set to NULL at the top of the function, and not assigned to
> >anything else until the call to sctp_association_new much farther down (line
> >1201).  That means the above if statement, as well as this:
> >  if (asoc2 && asoc2 != asoc) {
> >and this:
> >if (!asoc) {
> >will always be false, false, and true, respectively.
> 
> No, I don't think you can.  Consider a case of sctp_connectx() where
> each address specified in connectx has a different destination port.
> 
> First time through the loop, we'll create the association and set
> the peer.port.  The second time through the loop, we'll compare the
> that port to the port specified in the second address.  If the ports
> do not match, we need to stop.
> 
> -vlad
Ah, you're right, I missed the while loop, apologies

Acked-by: Neil Horman <nhorman@tuxdriver.com>

> >
> >Regards
> >Neil
> >
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - April 7, 2013, 9:04 p.m.
From: Wei Yongjun <weiyj.lk@gmail.com>
Date: Wed, 3 Apr 2013 21:02:28 +0800

> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> Fix to return a negative error code from the error handling
> case instead of 0, as returned elsewhere in this function.
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

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

Patch

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index dd21ae3..f631c5f 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1119,9 +1119,10 @@  static int __sctp_connect(struct sock* sk,
 		/* Make sure the destination port is correctly set
 		 * in all addresses.
 		 */
-		if (asoc && asoc->peer.port && asoc->peer.port != port)
+		if (asoc && asoc->peer.port && asoc->peer.port != port) {
+			err = -EINVAL;
 			goto out_free;
-
+		}
 
 		/* Check if there already is a matching association on the
 		 * endpoint (other than the one created here).