Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3740867pxv; Mon, 28 Jun 2021 11:37:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZPmWPO2UwM66zmfIcx3bIvod5rtT/oZcWBdAC6lBjvqPgD6bHSM82cuh0Q6hn0ZFMNlsA X-Received: by 2002:a5d:8b85:: with SMTP id p5mr640869iol.43.1624905443398; Mon, 28 Jun 2021 11:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624905443; cv=none; d=google.com; s=arc-20160816; b=s8rgVBqcBZ55WBWa51lDW3v3LuC6K84vlx1eAApJZXnMEeuw9TGbDmRo05YtBxTMj+ HEs4qJKbIfhPh01CGzONl270rYxJ+9JOQ1wozu8Hby1WI4Fd6ErAfZaYosFxmt9tD40d ef596R9SRn3j7ddbtFKS1P+fAemBZHR54pWwQCRXAp0wsQVj9sMiaTh7yF+phCPx+ycx vAKTGlCZsBKFCaeRflUc3H1GZYiwdUg1CL4jrsAFENGGS7AvzUBnNJmq+dRoHvBEqRws 0pSsmJc8vHu+WP1KW1pfoJpbcQoA5uSAJy1+iIrJeMGg7vnzGcKt6y+vVxSIVx6qTojK 9+Yg== 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=FVWxZ+JOeNZRhHUWIPVtE7fkqy+wi8UIQTCNOlF7xdE=; b=wZ2JZa9XxYOMsAB27g3xNC5Gwzn2jh6oKNPdhBT5u+2W2pWdqisV27EnG8Tz0WGX9y Iwu2JpHca9M2sRYiBSRbfhNlWGQvnMtKXLPNmjVKI2PrFW/8riE3KMlkMgEU8FgIBW9C rVB7vc8fbT7p88wtF4/3qfLNC1wJrmpbw7LcOZ7VPcCKMUX9T9QwAqmRlrc9pkwmDTUI QIMzKK9iZIwWzFL+zXCNxrk5reGbNzHbS5RuKcMSIkHzFqqTdBZGLOvhV/wp7xmgBG3g AYspV9lyqIk5N6nVPJDYO0TtjWUV4CwDWITw5zVBY64JHqe+VDoj3jEcegFyHhyJMCRE xIyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ozb23m+3; 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 a3si9741332ilr.11.2021.06.28.11.37.07; Mon, 28 Jun 2021 11:37:23 -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=ozb23m+3; 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 S235607AbhF1PIc (ORCPT + 99 others); Mon, 28 Jun 2021 11:08:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:53668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236326AbhF1OrW (ORCPT ); Mon, 28 Jun 2021 10:47:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5FE1561CAA; Mon, 28 Jun 2021 14:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624890997; bh=d7nE31LJFpcfz49ymhPQllVtbPahLzAtfQD5AovH9jM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ozb23m+3TZ/32GKbuvpvv/R1Rv10umo5yBkM0YMwXiSFHMDKcFpwU+LR4i/poBChj 2UVljQsUaPso35S6DOQo0R/ExqPHaAr7G0pP9FJfsX6NOJCITkNI0LPVqN2qV2oW1k yXJ8tvoV4EaSi3CAkXLgueMT14d2hCdwhifgYABAidVV+jH9ddOtQ40z5AZizGQbbD qcTkENYsQE0i2GePpLNy5CiqKu/DM2544tZxl/ukuXmAsytK/xi8o0j84P4wB3oWae 4nV7pWDsujJ6t5vtUuk7q6VtClyj2FsTustyzPQ9nxTA8RoXgCU79Jo6kamlpCTxjF TRbayXVLcpXKA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hillf Danton , syzbot , Andreas Gruenbacher , Sasha Levin Subject: [PATCH 4.14 07/88] gfs2: Fix use-after-free in gfs2_glock_shrink_scan Date: Mon, 28 Jun 2021 10:35:07 -0400 Message-Id: <20210628143628.33342-8-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+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 0a0dd3178483..be969f24ccf0 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1456,6 +1456,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); @@ -1501,7 +1502,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