lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <47056565.50803@cybernetics.com>
Date:	Thu, 04 Oct 2007 18:12:53 -0400
From:	Tony Battersby <tonyb@...ernetics.com>
To:	James Morris <jmorris@...ei.org>
Cc:	netdev@...r.kernel.org, davem@...emloft.net
Subject: Re: [PATCH] net: fix kernel_accept() error path

James Morris wrote:
> On Thu, 4 Oct 2007, Tony Battersby wrote:
>
>   
>> If accept() returns an error, kernel_accept() releases the new socket
>> but passes a pointer to the released socket back to the caller.  Make it
>> pass back NULL instead.
>>
>> Signed-off-by: Tony Battersby <tonyb@...ernetics.com>
>> ---
>> --- linux-2.6.23-rc9/net/socket.c.bak	2007-10-04 15:21:17.000000000 -0400
>> +++ linux-2.6.23-rc9/net/socket.c	2007-10-04 15:21:22.000000000 -0400
>> @@ -2230,6 +2230,7 @@ int kernel_accept(struct socket *sock, s
>>  	err = sock->ops->accept(sock, *newsock, flags);
>>  	if (err < 0) {
>>  		sock_release(*newsock);
>> +		*newsock = NULL;
>>  		goto done;
>>  	}
>>  
>>     
>
> If you get an error back from kernel_accept, you should not be trying to 
> use newsock.
>
>   

Here is an example of what I would consider "reasonable code" that would
fail:

int example()
{
    struct socket *conn_socket = NULL;
    int err;

    ...

    if ((err = kernel_accept(sock, &conn_socket, 0)) < 0)
        goto out_cleanup;

    [do whatever with conn_socket]

 out_cleanup:

    if (conn_socket != NULL)
        sock_release(&conn_socket);

    return err;
}

Without the patch, the double sock_release() will cause a BUG().

Also compare to sock_create_lite(), which sets *res to NULL on error.

Tony

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ