Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp743484imm; Wed, 1 Aug 2018 04:42:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdfoMj7T5TYGI0kRFWVgfBVyZnRraoOazwAp0Z5qUSVYZRopjtLpXEKrGx3Om+sKVj4OtHH X-Received: by 2002:a62:ce81:: with SMTP id y123-v6mr2776988pfg.95.1533123750459; Wed, 01 Aug 2018 04:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533123750; cv=none; d=google.com; s=arc-20160816; b=J/mCmCvSF9GvD0JJwUorSNu6R+ItWsIR6IHm5XHVy/aOimbgwiBJ/N5Ept2bWbwJsn V8e7XxyBFbBqnAGMK8k2Vshih0gwSwsfHI4ZDNZhS1Z2owFDT/Hv7XJjWNFG0zzIHtNv sTuy8en8JrVpfIXPhsxafH6GKLBD2zsxfuDgHnUkhGM7Lne1hnpQ9DZ2Fw7Cm/JELxa+ sy1877LsRCv9W3qaqNsHq7VGc9lBMWiYBwEFOxA2ko+a4g83QrwtYXG5Dt06Lr8Gomiy S5NmOwXyHVl+dAasbZaAaKE86/w0JPbWFPZHeIOipS7AeijD2AdCFT3jjuognGtgsjic R3lA== 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:arc-authentication-results; bh=iTsiEOqz9rq0e/HneCo4UXrc3vGchtOjK6Uov7OBq7M=; b=tGPcmy3N0di9Q/dViSlWKNyqwupd6vrHOYeKYy5IYaCkP4bbS/sx8bb3H5Wfpcd6a6 NJprdaHzAD2Xkl7jtpCa7U49NJBXx6E2YXo/DzUI0yvUxi34QsJitWrgmZ6WpNJdYt+9 lTGbpw5mgw9z7HO3beHE6xJ8G/jdOrennVL/I7xOQRnows8qpZ6NVyPKOtp7UX4QkUxH Yb6DZLOPF6Y+TXhODSDb0fVDlCunlDII5MO0pvqfRUZNVDVtkZDkWSgJqC1+4iW+CzGH LhCLPyoEsUfTHP2F9mdjzzwyj6so9LGHL32aYWt0pX4G3OCfQCFejVcg9AxQ46TgXGu4 JpqA== 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 d5-v6si14418820plo.3.2018.08.01.04.42.15; Wed, 01 Aug 2018 04:42:30 -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 S2388884AbeHAN0r (ORCPT + 99 others); Wed, 1 Aug 2018 09:26:47 -0400 Received: from Chamillionaire.breakpoint.cc ([146.0.238.67]:47042 "EHLO Chamillionaire.breakpoint.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387610AbeHAN0q (ORCPT ); Wed, 1 Aug 2018 09:26:46 -0400 Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.89) (envelope-from ) id 1fkpUm-0001QR-7g; Wed, 01 Aug 2018 13:40:48 +0200 Date: Wed, 1 Aug 2018 13:40:48 +0200 From: Florian Westphal To: Dmitry Vyukov Cc: Florian Westphal , Linus Torvalds , Christoph Lameter , Andrey Ryabinin , Theodore Ts'o , Jan Kara , linux-ext4@vger.kernel.org, Greg Kroah-Hartman , Pablo Neira Ayuso , Jozsef Kadlecsik , David Miller , NetFilter , coreteam@netfilter.org, Network Development , Gerrit Renker , dccp@vger.kernel.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Dave Airlie , intel-gfx , DRI , Eric Dumazet , Alexey Kuznetsov , Hideaki YOSHIFUJI , Ursula Braun , linux-s390 , Linux Kernel Mailing List , Andrew Morton , linux-mm , Andrey Konovalov Subject: Re: SLAB_TYPESAFE_BY_RCU without constructors (was Re: [PATCH v4 13/17] khwasan: add hooks implementation) Message-ID: <20180801114048.ufkr7zwmir7ps3vl@breakpoint.cc> References: <01000164f169bc6b-c73a8353-d7d9-47ec-a782-90aadcb86bfb-000000@email.amazonses.com> <20180801103537.d36t3snzulyuge7g@breakpoint.cc> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dmitry Vyukov wrote: > On Wed, Aug 1, 2018 at 12:35 PM, Florian Westphal wrote: > > Dmitry Vyukov wrote: > >> Still can't grasp all details. > >> There is state that we read without taking ct->ct_general.use ref > >> first, namely ct->state and what's used by nf_ct_key_equal. > >> So let's say the entry we want to find is in the list, but > >> ____nf_conntrack_find finds a wrong entry earlier because all state it > >> looks at is random garbage, so it returns the wrong entry to > >> __nf_conntrack_find_get. > > > > If an entry can be found, it can't be random garbage. > > We never link entries into global table until state has been set up. > > But... we don't hold a reference to the entry. So say it's in the > table with valid state, now ____nf_conntrack_find discovers it, now > the entry is removed and reused a dozen of times will all associated > state reinitialization. And nf_ct_key_equal looks at it concurrently > and decides if it's the entry we are looking for or now. I think > unless we hold a ref to the entry, it's state needs to be considered > random garbage for correctness reasoning. It checks if it might be the entry we're looking for. If this was complete random garbage, scheme would not work, as then we could have entry that isn't in table, has nonzero refcount, but has its confirmed bit set. I don't see how that would be possible, any reallocation makes sure ct->status has CONFIRMED bit clear before setting refcount to nonzero value. I think this is the scenario you hint at is: 1. nf_ct_key_equal is true 2. the entry is free'd (or was already free'd) 3. we return NULL to caller due to atomic_inc_not_zero() failure but i fail to see how thats wrong? Sure, we could restart lookup but how would that help? We'd not find the 'candidate' entry again. We might find entry that has been inserted at this very instant but newly allocated entries are only inserted into global table until the skb that created the nf_conn object has made it through the network stack (postrouting for fowarded, or input for local delivery). So, the likelyhood of such restart finding another candidate is close to 0, and won't prevent 'insert race' from happening.