Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp94581ybt; Tue, 7 Jul 2020 17:05:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAWvtoFzfVbV5RMtg7Ct55d1ulJ7WuQ+KwQsvudM4fNJ8DEFqueu7XSR059ToC4HbhBuDc X-Received: by 2002:aa7:c54f:: with SMTP id s15mr66255747edr.175.1594166730042; Tue, 07 Jul 2020 17:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594166730; cv=none; d=google.com; s=arc-20160816; b=GRrAhnDQtWTWP9DhVkScm85dB7PluFwQE7ekcMIIQe3p4l8sGZuztCpdtjNth/xaWf x+ZewNL018oLLQ1ExZYvAYST/Cpk9lAr3sFE6F3kgGGwR+ROlCAYP/iojQgDnZTduiHm vrSlEFisdvYOUWqdcjAseL2J6w1LvlYxRph51++r9KBtw2xQAQkdinUzpe82HlaDaUf6 gj5K8vPM7m02AlcGEIxBIwZL9GMP63K9H+qLOYv9axrolZkxJWOU+56/GYPZBR6Pednl m/4hi9kwobPCDc1R6TObyrgEfWwNsa1+OZsOFuOuVikfiDJUU/6MOOzC8QCBtNVDR3jn IrgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=qZu2YrAxLJN5D6sXoCYvO8Iu/F39Okm6v8mAVHruDYo=; b=jD4gZEutYTEQN18uhHxv0uSK8AZ5rwU0tdBiCTK1CEShKhSanP/Txc2y4Ds7AFxqvy MfVGcfrDVosGgqyX4oLvEarEV0uLEh8hjGO5mpQLMhOihS7WdZr3xn3fpKFGMB0nDRuj ncPwSRtqL1Q299bexW0+jvdJh4hAFNcOPiyfCQs8KF+Gg0oXjBK2UokFai94RTVXbyYU R6ajak9HIYPzB3gpMplvD96WMFfCuI69PNGrCLot77YZMJ5Hq86rkzBcczWVb5oBxjH3 cPdyF6FlOo3y68w8D0e05N2pJlK4wbMJljD3Rg1/gOepCvXYD8TojTrorg276gZP6isY lRiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w11si17450281edq.29.2020.07.07.17.05.06; Tue, 07 Jul 2020 17:05:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728716AbgGGXjO (ORCPT + 99 others); Tue, 7 Jul 2020 19:39:14 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:58612 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727945AbgGGXjO (ORCPT ); Tue, 7 Jul 2020 19:39:14 -0400 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.0.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1jsxAq-00026X-2I; Wed, 08 Jul 2020 09:38:53 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Wed, 08 Jul 2020 09:38:52 +1000 Date: Wed, 8 Jul 2020 09:38:52 +1000 From: Herbert Xu To: Pavel Machek Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Brian Moyles , Mauricio Faria de Oliveira Subject: Re: [PATCH 4.19 13/36] crypto: af_alg - fix use-after-free in af_alg_accept() due to bh_lock_sock() Message-ID: <20200707233851.GA8460@gondor.apana.org.au> References: <20200707145749.130272978@linuxfoundation.org> <20200707145749.760045378@linuxfoundation.org> <20200707212530.GA11158@amd> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200707212530.GA11158@amd> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 07, 2020 at 11:25:31PM +0200, Pavel Machek wrote: > > > @@ -308,12 +302,14 @@ int af_alg_accept(struct sock *sk, struc > > > > sk2->sk_family = PF_ALG; > > > > - if (nokey || !ask->refcnt++) > > + if (atomic_inc_return_relaxed(&ask->refcnt) == 1) > > sock_hold(sk); > > - ask->nokey_refcnt += nokey; > > + if (nokey) { > > + atomic_inc(&ask->nokey_refcnt); > > + atomic_set(&alg_sk(sk2)->nokey_refcnt, 1); > > + } > > Should we set the nokey_refcnt to 0 using atomic_set, too? > Aternatively, should the nokey_refcnt be initialized using > ATOMIC_INIT()? What are you asking for? It's already being set with atomic_set. Or are you asking it to be set to 0 instead of 1? No it needs to be 1 for the socket destructor. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt