Received: by 10.192.165.148 with SMTP id m20csp1534316imm; Sat, 5 May 2018 14:48:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrPVmgc5g02Df0Etx3fVFW6vDlz4xf3whnMphuC3xFdFRsCEW9e6nBI7VatfOhjTVt2SjIa X-Received: by 2002:a63:6dc8:: with SMTP id i191-v6mr25442505pgc.291.1525556939064; Sat, 05 May 2018 14:48:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525556939; cv=none; d=google.com; s=arc-20160816; b=gHwPmeKbh5HLBMM61Fp9LcajBu7chxyYoaoB8D0Rk5Mz7JvhccEBOL2Go+qf/VEdo9 cNLOL28XJrx/q7Ht0W9hWWnTi6iKco5m1+K3nmVXM/zDIWoj5R7pQENovwgZ6THv3sds EX6b94/lYxGPEeKFF8psIYVN+yb5GYeUEijLcW6BWwO+pRlNdZJvH0swx5GiIsKMMYqp 0LXO6NcvdLAcuV4GIR7RiUk1PF3eGcLVwvDVW2ur2ICrwtmTzM4NcStELt6fSGTbju/f ekwEABHqzi8zhPPfOA0oWidRqskTfn0rg/1Hgml9SlQsW4YADpX81Lt35x13V6t6E2p7 SAjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:references :in-reply-to:subject:cc:date:to:from:arc-authentication-results; bh=oQFFcrnbOaJeTZxqbd9DmMznwzw3N+GAy1IQePBYyEc=; b=N4xAC7ixrOl5y0Fhcf9ACRh7kU+2Wi6m/8dfrxqZrKU7whoG6YCQQevmoqxz2JzeZF Euelur/KFV0xq5pnAoSSQa+E6PRTdp5k4J/j7375OhB+rKBFNjn8/nNWiqcOlp/q1IpV axdNz8R8S73NpGa//yz1zoQfIxPa94fYy1locAwgNX8OlsvAXqfRpiW5cTrnPwKY7QCM WbTIZH458kKuKu4clGyljDW307v5KKLcp74ErwEcm5yf2mypQZdwCHpP6/eugLZwYWJs IWwFhHgTV0QMfgR77IpPap0KGY0ERjFYZTIJPKQ7m367NaUFaa4ZxMjEFxjnBbXUr2Eu 7Xww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w20-v6si19558706plp.7.2018.05.05.14.48.44; Sat, 05 May 2018 14:48:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751899AbeEEVsa (ORCPT + 99 others); Sat, 5 May 2018 17:48:30 -0400 Received: from mx2.suse.de ([195.135.220.15]:47120 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751767AbeEEVs2 (ORCPT ); Sat, 5 May 2018 17:48:28 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1C88EAF5D; Sat, 5 May 2018 21:48:27 +0000 (UTC) From: NeilBrown To: Herbert Xu Date: Sun, 06 May 2018 07:48:20 +1000 Cc: Thomas Graf , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/8] rhashtable: fix race in nested_table_alloc() In-Reply-To: <20180505092907.2qa3scf6bzvubmtt@gondor.apana.org.au> References: <152540595840.18473.11298241115621799037.stgit@noble> <152540605432.18473.11813271279255176724.stgit@noble> <20180505092907.2qa3scf6bzvubmtt@gondor.apana.org.au> Message-ID: <871sepepuj.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sat, May 05 2018, Herbert Xu wrote: > On Fri, May 04, 2018 at 01:54:14PM +1000, NeilBrown wrote: >> If two threads run nested_table_alloc() at the same time >> they could both allocate a new table. >> Best case is that one of them will never be freed, leaking memory. >> Worst case is hat entry get stored there before it leaks, >> and the are lost from the table. >>=20 >> So use cmpxchg to detect the race and free the unused table. >>=20 >> Fixes: da20420f83ea ("rhashtable: Add nested tables") >> Cc: stable@vger.kernel.org # 4.11+ >> Signed-off-by: NeilBrown > > What about the spinlock that's meant to be held around this > operation? The spinlock protects 2 or more buckets. The nested table contains at least 512 buckets, maybe more. It is quite possible for two insertions into 2 different buckets to both get their spinlock and both try to instantiate the same nested table. Thanks, NeilBrown --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlruJqQACgkQOeye3VZi gbncaw//dHfQNoKtso8SIK8DEzqWAxTaFg/l8aifrgNi6xjs4mG0CJJekQtGIN16 JbE5uXo7Z2bLOQ/GXa+g3JUMyTy+zNCKKar3F6XLtVvPz8WSqyNxPDI0W9YDmrgA xXfKzJZaS/rdBM4KDA0JPNlya3bP/n3Ga89F8XvD5tARs3DEG3VgM0w9dQt0fRko 59Egn9D6rFPZAzLqmqmqc3YhfLsW8ignG2lInl9qRao9U0pmOQNHeKYUFBlA0iFy Z7LDYr1fzOlDMyQ3ByeZmRtvtpGpy1YBULSEFxjJc1Y7YtNuxr1kvmHDAJcQRIQN C2eajctoCCZyKcgGvUqlOlUVYHh9Ek1BqcBHah/hMGJVdU9CjDzYcxIkuRQNpczt IqekiwAiAn4eeoH1FVLAEM1H2a2r1WfFm5ytpji0NYsqyn5jETKwiFQCSbdgAs+O WfZMjA4kRj1eNu7oVeJAYIXVDCCMA5nE2nIyyT66aQl3v0dK8DTMocI6HPPBixso /pWAQ5+jG0rThFa4DrMonY1Mi50Yjl5k8xm2QXIjPr2MDboiUD26JyJ4wJkej9CD w6AeHjMoLg17+9UcAZUZuh9ArvTicQoQbuNYOHYbuTHC//b7pXu6Uf7GQ+BS531B 51pkLMsTg8BSdk5LSmAJjtz//p3/xbkv0kKUjb3rPEBv9JVtewE= =FdAp -----END PGP SIGNATURE----- --=-=-=--