Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp493035ybt; Fri, 19 Jun 2020 06:48:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8hhFrlRJSgwKwW3qUEgv5LTEtjFU3zXdaIl1/ItvnHnqGqmeKE/cjUDvE/TurBAiWT//3 X-Received: by 2002:aa7:d9d6:: with SMTP id v22mr3597579eds.66.1592574537554; Fri, 19 Jun 2020 06:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592574537; cv=none; d=google.com; s=arc-20160816; b=aPoPX0b1AEdRU0Zh7qrsUElk4Z2pX0S+MUZ4MrB5w3uh4Hw5cme4yGMBHJLpU64OSn GaQIqo67UORdpN539JS3VvjfS6VT1p59w93nEpQEC7DspNI7JGpIaMtX1+EMnLRg/c1W xrKDcRJqFKhgkH2qJmWdCeW3TQapW46/igDNEwq0unheGqIw22iK9mpbPWc6dMqlzztk 0D+962DJ7kLmRYG92sUZbPGCuqIE+3vF1i9O9obCLGbOGY/K2bHj/louwpIC7+TDXjCA jSZF8k7/xaMSmB8bF9XDOMWSzHLPPdvM5/2OUOnOvbM+IzKRJF+WkpTISFaPiZC2jkUP I5hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=mBr2Dog35BqG+RyTNPha2esLGVpTLQRGG3cv7MWSe60=; b=MuAPKLiTa3YCB5y/gfgOddhozIrbFJV++hDXxLmsVNVtAr60hFVixrZkhGG90kcd8Y MjYlISVbL0j6uZiZ1hAi0D99qMSzktaEbf0V0f7QamAvK2qbI8/A6f7je3d8E7NlxT4N AoBnN0Lm36OS18PAZPZ3Q/s6h/cmC1R+6bKFZS+s/HcF8AsOvxZWppNg5jCjy7L4SYZB iR7K+8yRVL+D2H5TZNY1YzYyTZ46rfXqswkTxePIx7jqZaauL340UtxkBf7cA9Wuhecm nB52aP3kqNaVwAZ5qUP6VWuniJqPbV7QRLrrff+Lt1bDMPWU8qJNON2bs7DjfC3IJG0i sVvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=soVACX5y; 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 m17si3930273eji.138.2020.06.19.06.48.34; Fri, 19 Jun 2020 06:48:57 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=soVACX5y; 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 S1732964AbgFSNqN (ORCPT + 99 others); Fri, 19 Jun 2020 09:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732695AbgFSNqL (ORCPT ); Fri, 19 Jun 2020 09:46:11 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AD94C06174E; Fri, 19 Jun 2020 06:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=mBr2Dog35BqG+RyTNPha2esLGVpTLQRGG3cv7MWSe60=; b=soVACX5yYdkb7jdgKOmo6zfik5 Jv2cxNQEL5SZgExWNYoWzXPVE4vzg5/Fmano1VHg6I1Jm+hIGkjgYY6w0ozdHzl8szyQioZnzuMMq hyxD4WgR5o1dzYTIFlcBTTsoJ+18t9KDnwbAr4vrg4zYVGF/T2THmjRU/FdwXdcq0msVmsyWiMa8w P2ivUKcPAyoi3iwGmDvwsM8LvDGOPu5sSoX2+UsiHjnBWo+gyZQrRrNjEiagUV2XbU+OfMA9zuE7l th7SQ/TWy8ee4vke7kIl9K3O32LvGlWCBxi33WQh7fHWFW7wKJyCEs8ttyoWHCk4wy9QQd/u+PcVU O6jz0y3w==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmHLM-0002ts-Tm; Fri, 19 Jun 2020 13:46:08 +0000 Date: Fri, 19 Jun 2020 06:46:08 -0700 From: Christoph Hellwig To: Dave Chinner Cc: Yu Kuai , darrick.wong@oracle.com, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com Subject: Re: [PATCH] xfs: fix use-after-free on CIL context on shutdown Message-ID: <20200619134608.GA32599@infradead.org> References: <20200611013952.2589997-1-yukuai3@huawei.com> <20200611022848.GQ2040@dread.disaster.area> <20200611024503.GR2040@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200611024503.GR2040@dread.disaster.area> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 11, 2020 at 12:45:03PM +1000, Dave Chinner wrote: > > From: Dave Chinner > > xlog_wait() on the CIL context can reference a freed context if the > waiter doesn't get scheduled before the CIL context is freed. This > can happen when a task is on the hard throttle and the CIL push > aborts due to a shutdown. This was detected by generic/019: > > thread 1 thread 2 > > __xfs_trans_commit > xfs_log_commit_cil > > xlog_wait > schedule > xlog_cil_push_work > wake_up_all > > xlog_cil_committed > kmem_free > > remove_wait_queue > spin_lock_irqsave --> UAF > > Fix it by moving the wait queue to the CIL rather than keeping it in > in the CIL context that gets freed on push completion. Because the > wait queue is now independent of the CIL context and we might have > multiple contexts in flight at once, only wake the waiters on the > push throttle when the context we are pushing is over the hard > throttle size threshold. > > Fixes: 0e7ab7efe7745 ("xfs: Throttle commits on delayed background CIL push") > Reported-by: Yu Kuai > Signed-off-by: Dave Chinner Looks good: Reviewed-by: Christoph Hellwig