From patchwork Mon Aug 31 06:50:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 32610 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 2F407B7088 for ; Mon, 31 Aug 2009 16:50:41 +1000 (EST) Received: by ozlabs.org (Postfix) id 1E1FBDDD04; Mon, 31 Aug 2009 16:50:41 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 9BDACDDD0C for ; Mon, 31 Aug 2009 16:50:40 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754445AbZHaGub (ORCPT ); Mon, 31 Aug 2009 02:50:31 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754192AbZHaGub (ORCPT ); Mon, 31 Aug 2009 02:50:31 -0400 Received: from gw1.cosmosbay.com ([212.99.114.194]:39589 "EHLO gw1.cosmosbay.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754278AbZHaGua (ORCPT ); Mon, 31 Aug 2009 02:50:30 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by gw1.cosmosbay.com (8.13.7/8.13.7) with ESMTP id n7V6oSd6010546; Mon, 31 Aug 2009 08:50:28 +0200 Message-ID: <4A9B72B1.2040908@gmail.com> Date: Mon, 31 Aug 2009 08:50:25 +0200 From: Eric Dumazet User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Jarek Poplawski CC: David Miller , netdev@vger.kernel.org Subject: Re: [PATCH] net: Fix sock freeing before sock_init_data() with __sk_free() References: <20090830222340.GA17454@ami.dom.local> <4A9B6D23.9090505@gmail.com> <20090831063648.GB5005@ff.dom.local> In-Reply-To: <20090831063648.GB5005@ff.dom.local> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (gw1.cosmosbay.com [0.0.0.0]); Mon, 31 Aug 2009 08:50:28 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Jarek Poplawski a écrit : > On Mon, Aug 31, 2009 at 08:26:43AM +0200, Eric Dumazet wrote: >> Jarek Poplawski a écrit : >>> After recent changes sk_free() frees socks conditionally and depends >>> on sk_wmem_alloc beeing set e.g. in sock_init_data(). But in some >>> cases sk_free() is called earlier, usually after other alloc errors. >>> This patch fixes it by exporting and using __sk_free() directly. > ... >> Very nice catch Jarek, but dont you think it would be cleaner to make sure >> we can call sk_free() right after sk_alloc() instead, and not exporting >> __sk_free() ? >> >> ie initialize wmem_alloc in sk_alloc() instead of initializing it in >> sock_init_data() ? >> > > Most probably it should be better. But I meant this fix for -net and > didn't wan't to break too much... So, if you're sure it's OK feel free > to send your version. (Or it could be changed like this in the -next.) Well, patch is yours, not mine, and I am confident it is OK. We should check that no sk_alloc() user did a blind memset() or something strange like that, before calling sock_init_data() or sk_free() Signed-off-by: Jarek Poplawski --- 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 diff --git a/net/core/sock.c b/net/core/sock.c index bbb25be..7633422 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1025,6 +1025,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority, sk->sk_prot = sk->sk_prot_creator = prot; sock_lock_init(sk); sock_net_set(sk, get_net(net)); + atomic_set(&sk->sk_wmem_alloc, 1); } return sk; @@ -1872,7 +1873,6 @@ void sock_init_data(struct socket *sock, struct sock *sk) */ smp_wmb(); atomic_set(&sk->sk_refcnt, 1); - atomic_set(&sk->sk_wmem_alloc, 1); atomic_set(&sk->sk_drops, 0); } EXPORT_SYMBOL(sock_init_data);