Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3420160pxf; Mon, 29 Mar 2021 01:31:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAqS/FflAR/wddQc2Dc6CEkIGmqZTn220oEzgehtDvNgQVZGxceI5I38oLOaD2EQHhFEa5 X-Received: by 2002:aa7:c3c4:: with SMTP id l4mr27088891edr.335.1617006719129; Mon, 29 Mar 2021 01:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617006719; cv=none; d=google.com; s=arc-20160816; b=kDamQwIIomr+j/LL4Tq0H8Psy4nAjV+0timRVUWjDIlVAA7+CDVbzRurJn3B75/tsd /pZyJVN1RTWx0wT3VbpQM9lq47T+rTTqZ6QfZfe+OdFx0/CGu3YAxzeLZKu7/O/7HLje xEsKMopyJCftAxFBTJS2LT5iedkmymAWSmbaK/cDARjts8a4WiFZE7W8MFo+QxmCZVIt TX4UO61ZpJHlwcgBTlwb7v39hGHeHk3KbiiiKA0uwAsq+EFsOfazGIfyO7m3SoQfSdsO 39jgk+fZLCeqDXFexK+9hA4K30AK4T6VlqI/z5+F0bxjLWTBUod02vGymSFVz2OjSS2+ 2Veg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TTA2EnC3GqSAMH4sqcgbNN2pImZqkgyXWju0q/SJPO0=; b=NsmN0HIPIb1hHdrJpLWpgUU0L27xG1/uavybMUZ6ejwaTKL4rIAY5pI9MiJpmR1/8r 5EPiPb68+E4AWxeLwNMHYLRYw3qSUlDUAYm97k5TQSxf++72tq0KzHmOXzE1Jcg8Ab6N WtLEVHse8XDkCj6X/PNNxLsCKAjyMEihWqP6T1AetsPWhbkzWALnkwPXLL4fsdN266x5 zfS0+nW4XGpqixNKlLfCCsMyDaEg41QNQ8fIU1p+DdfWX2EenVQZUbP887Vyh4zBIY6j 73x3l80Ck+OtCjWqnBNa+mAXojPhAkSIrcAr9tjbFRKgiLx0uvUnfeMUR5WQ1xWeqcTh DNjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sTu54aZd; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si12240174ejy.263.2021.03.29.01.31.36; Mon, 29 Mar 2021 01:31:59 -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=@linuxfoundation.org header.s=korg header.b=sTu54aZd; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233919AbhC2I1e (ORCPT + 99 others); Mon, 29 Mar 2021 04:27:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:58580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233273AbhC2IRY (ORCPT ); Mon, 29 Mar 2021 04:17:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E81F26193A; Mon, 29 Mar 2021 08:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617005824; bh=kGD9Zz7cfSBPI5bkMvB6A+uKjgg/mNyjnW8fvUtKCUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sTu54aZd8xqYpuUyo0mFb3ggsIGAyUZq7EkXdeTa4YjpibHzpZRt9s+XDvudPSFfJ T0thg2mS05P7jbTlKFBcF65jrZGvBpLl7zyd85io8QSn1yYmNx9CFQgnpR6azRvuP+ YprhOhOznJVzWHFJlfO2XotQbYKrxxtm1YrjGXWw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Price , Bob Peterson , Andreas Gruenbacher , Sasha Levin Subject: [PATCH 5.10 019/221] gfs2: fix use-after-free in trans_drain Date: Mon, 29 Mar 2021 09:55:50 +0200 Message-Id: <20210329075629.827560716@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bob Peterson [ Upstream commit 1a5a2cfd34c17db73c53ef127272c8c1ae220485 ] This patch adds code to function trans_drain to remove drained bd elements from the ail lists, if queued, before freeing the bd. If we don't remove the bd from the ail, function ail_drain will try to reference the bd after it has been freed by trans_drain. Thanks to Andy Price for his analysis of the problem. Reported-by: Andy Price Signed-off-by: Bob Peterson Signed-off-by: Andreas Gruenbacher Signed-off-by: Sasha Levin --- fs/gfs2/log.c | 4 ++++ fs/gfs2/trans.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 2e9314091c81..1955dea999f7 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -935,12 +935,16 @@ static void trans_drain(struct gfs2_trans *tr) while (!list_empty(head)) { bd = list_first_entry(head, struct gfs2_bufdata, bd_list); list_del_init(&bd->bd_list); + if (!list_empty(&bd->bd_ail_st_list)) + gfs2_remove_from_ail(bd); kmem_cache_free(gfs2_bufdata_cachep, bd); } head = &tr->tr_databuf; while (!list_empty(head)) { bd = list_first_entry(head, struct gfs2_bufdata, bd_list); list_del_init(&bd->bd_list); + if (!list_empty(&bd->bd_ail_st_list)) + gfs2_remove_from_ail(bd); kmem_cache_free(gfs2_bufdata_cachep, bd); } } diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c index 6d4bf7ea7b3b..7f850ff6a05d 100644 --- a/fs/gfs2/trans.c +++ b/fs/gfs2/trans.c @@ -134,6 +134,8 @@ static struct gfs2_bufdata *gfs2_alloc_bufdata(struct gfs2_glock *gl, bd->bd_bh = bh; bd->bd_gl = gl; INIT_LIST_HEAD(&bd->bd_list); + INIT_LIST_HEAD(&bd->bd_ail_st_list); + INIT_LIST_HEAD(&bd->bd_ail_gl_list); bh->b_private = bd; return bd; } -- 2.30.1