Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3777632pxv; Mon, 28 Jun 2021 12:36:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYH1iH7cjC+jP2mdFS469sUxHNz7hUap28gDYuUER5PMUR+MPVRy/E7cnzRIkGa/y6pz0G X-Received: by 2002:a05:6e02:dcc:: with SMTP id l12mr14545157ilj.80.1624909009278; Mon, 28 Jun 2021 12:36:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624909009; cv=none; d=google.com; s=arc-20160816; b=nY91lb2ToOkW/IvRrVIbToSxRNiur4J+iuw8Hyvre4Zb1iodnsHt9wW+9vk5VrUbwm Z3ePID/0Kz32kWUrdylonK+hUpOoy9yXhzGQLcqS/2vzjmm4cHgui0D2nCRs8hRI9PO4 vxxOF95iNjmXgAuqQJc6PzmUXUSDcVEmskpOj7oKq9EkTuaRtuu+FQfZWSUuCBDhMiDF F4y9kKmcYYbNt1zwVQftg+CWobnrNkDEiKja524TvQZSz8QX+GuDd3lPoBD/4HSwCa2m CY6buuJMYIN0VV6YvISzQGRPoEe8DpRLfKcebrnaXvt/R70AzteVYAEulJsiA+1ZBxCZ gXGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m2OiDjhCHMcmDNzvhSjPI8X641Ic40fNdKM7X7+SlPo=; b=arBhi8GivFc+1236oPCqKnv0whdw2GJCYlqxSqzE3/8YNx0xTsByFPoO9YDlPGMgP0 9QC6bkWGs2wP2nO68E6sqPPu3EmLhtVskqIft84I81UsOPhw+ZQPqhw8iPtWN5goCchd cGjHV2UsPj3YTnhCbzlKc/Fn2fc7IHTbJXXG9dUvHQz9PuJWTS+F6wHBznGJQpj9j3B3 aVRiuqHBDJFR9hy4+taJ0iLTPKQJVmgsJe71D2RGRHRAAQjI22csUyYn4hjHlB+iKDKZ 1rtvRI/5fv+izgrV5uU8g6om69684+pY8N5Fx8JcyXg8MeZqRqxr0aJ2u3oBcXaw6U3Z ix3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TGgc4Eud; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u8si1843279jat.6.2021.06.28.12.36.36; Mon, 28 Jun 2021 12:36:49 -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=pass header.i=@kernel.org header.s=k20201202 header.b=TGgc4Eud; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233988AbhF1Ox5 (ORCPT + 99 others); Mon, 28 Jun 2021 10:53:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:43926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235524AbhF1OkE (ORCPT ); Mon, 28 Jun 2021 10:40:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D767061CDB; Mon, 28 Jun 2021 14:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624890795; bh=V97tR86Nvew23PXQnLz/t0q1lng34RfS+c2bpRefKR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TGgc4EudpcAZ8y8gY5rtZb4JdylyjvxuoLEHrBUfdgxH5drqADhGuxTH7EFB9CsWP 7pqJSFDFV8FHESY9ZDaoht733sxPwLf1xKNPxjxPecpeEzIBHrsabpRAliCxQNHUxU YhMNjxlRgSx2Fbt1krwodTfFEtTXjWtDW0Cy16N9NZTS+cUivGny0cY6aXD9JxnPhf DnQi4dQn79F6P5xE91wxRCLYLKYca8oCYkGQLbnHU2AKU4ygjCAG/SRYG72m/QwB2K NFQmr9KUvertDbe7W+HsWIVT43xv0vAmaVyWxRwmK63pySK0JXeUG9PN1dKtd6fEKl oP3SvMBiA2FVg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hillf Danton , syzbot , Andreas Gruenbacher , Sasha Levin Subject: [PATCH 4.19 009/109] gfs2: Fix use-after-free in gfs2_glock_shrink_scan Date: Mon, 28 Jun 2021 10:31:25 -0400 Message-Id: <20210628143305.32978-10-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143305.32978-1-sashal@kernel.org> References: <20210628143305.32978-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.196-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.196-rc1 X-KernelTest-Deadline: 2021-06-30T14:32+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hillf Danton [ Upstream commit 1ab19c5de4c537ec0d9b21020395a5b5a6c059b2 ] The GLF_LRU flag is checked under lru_lock in gfs2_glock_remove_from_lru() to remove the glock from the lru list in __gfs2_glock_put(). On the shrink scan path, the same flag is cleared under lru_lock but because of cond_resched_lock(&lru_lock) in gfs2_dispose_glock_lru(), progress on the put side can be made without deleting the glock from the lru list. Keep GLF_LRU across the race window opened by cond_resched_lock(&lru_lock) to ensure correct behavior on both sides - clear GLF_LRU after list_del under lru_lock. Reported-by: syzbot Signed-off-by: Hillf Danton Signed-off-by: Andreas Gruenbacher Signed-off-by: Sasha Levin --- fs/gfs2/glock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index c20d71d86812..14d11ccda868 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1457,6 +1457,7 @@ __acquires(&lru_lock) while(!list_empty(list)) { gl = list_entry(list->next, struct gfs2_glock, gl_lru); list_del_init(&gl->gl_lru); + clear_bit(GLF_LRU, &gl->gl_flags); if (!spin_trylock(&gl->gl_lockref.lock)) { add_back_to_lru: list_add(&gl->gl_lru, &lru_list); @@ -1502,7 +1503,6 @@ static long gfs2_scan_glock_lru(int nr) if (!test_bit(GLF_LOCK, &gl->gl_flags)) { list_move(&gl->gl_lru, &dispose); atomic_dec(&lru_count); - clear_bit(GLF_LRU, &gl->gl_flags); freed++; continue; } -- 2.30.2