From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp134-25.sina.com.cn (smtp134-25.sina.com.cn [180.149.134.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CEF81A38EE for ; Thu, 4 Jul 2024 10:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=180.149.134.25 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720089342; cv=none; b=T/z30EHLjqgO1JdWUQnm1w059Gc89kXXyzgBheH7BX634KuEg9h2d1sAKrpYX/WSRZ+An9jrFWXZR7+BmGacEoSyBKe5PpUPi3A3i+IDudCUgqxIiOi1FmorMgG1p95CN6Bgpbk7W2EtXXPQJ9cLFT5BN/13ZE4IcP95SR0Q5X8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720089342; c=relaxed/simple; bh=F0U+LFngqNZTjEjSJVQJ9Hzl5vylWxE0tv1FzcykhCY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q1SjaPMsI6oHS+MXAwP3Nnh91olZhN4R9ZBQhZ/7TUaMmZuShMw3K97HaWmEwV9/f18BoJXR0v14qwop4o5e6ED5ZEBPUMw5BejahJsDe0Xm+hLGYrY2rbm83isYp1XXof7xVvrTv5aomMmAebsjN1gioPNN537wfnk5wZEEy34= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com; spf=pass smtp.mailfrom=sina.com; arc=none smtp.client-ip=180.149.134.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.com X-SMAIL-HELO: localhost.localdomain Received: from unknown (HELO localhost.localdomain)([113.118.65.201]) by sina.com (10.185.250.21) with ESMTP id 66867AEB00007F26; Thu, 4 Jul 2024 18:35:25 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com Authentication-Results: sina.com; spf=none smtp.mailfrom=hdanton@sina.com; dkim=none header.i=none; dmarc=none action=none header.from=hdanton@sina.com X-SMAIL-MID: 6097673408358 X-SMAIL-UIID: BAA4D347F2CB48EBA17B1782EB4B3DA7-20240704-183525-1 From: Hillf Danton To: Florian Westphal Cc: netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com, syzbot+4fd66a69358fc15ae2ad@syzkaller.appspotmail.com Subject: Re: [PATCH nf] netfilter: nf_tables: unconditionally flush pending work before notifier Date: Thu, 4 Jul 2024 18:35:14 +0800 Message-Id: <20240704103514.3035-1-hdanton@sina.com> In-Reply-To: <20240703130107.GB29258@breakpoint.cc> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Wed, 3 Jul 2024 15:01:07 +0200 Florian Westphal > Hillf Danton wrote: > > On Wed, 3 Jul 2024 12:52:15 +0200 Florian Westphal > > > Hillf Danton wrote: > > > > Given trans->table goes thru the lifespan of trans, your proposal is a bandaid > > > > if trans outlives table. > > > > > > trans must never outlive table. > > > > > What is preventing trans from being freed after closing sock, given > > trans is freed in workqueue? > > > > close sock > > queue work > > The notifier acquires the transaction mutex, locking out all other > transactions, so no further transactions requests referencing > the table can be queued. > As per the syzbot report, trans->table could be instantiated before notifier acquires the transaction mutex. And in fact the lock helps trans outlive table even with your patch. cpu1 cpu2 --- --- transB->table = A lock trans mutex flush work free A unlock trans mutex queue work to free transB > The work queue is flushed before potentially ripping the table > out. After this, no transactions referencing the table can exist > anymore; the only transactions than can still be queued are those > coming from a different netns, and tables are scoped per netns. > > Table is torn down. Transaction mutex is released. > > Next transaction from userspace can't find the table anymore (its gone), > so no more transactions can be queued for this table. > > As I wrote in the commit message, the flush is dumb, this should first > walk to see if there is a matching table to be torn down, and then flush > work queue once before tearing the table down. > > But its better to clearly split bug fix and such a change.