Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp404826pxb; Wed, 3 Mar 2021 06:20:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSu+PxkhUgS68oj+iX4HP0hFuMwt1k9dApg7nt5f9CCt/F7C9cEsQiQspKLEfTb0pacybz X-Received: by 2002:a17:906:2816:: with SMTP id r22mr25665915ejc.2.1614781202420; Wed, 03 Mar 2021 06:20:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614781202; cv=none; d=google.com; s=arc-20160816; b=oBQw3oEhZIuYVlgQzjvDWG+ryopojCkxPRYw9Wy+9gcOUvb4Wby4A8jW+mA1/xOy1p eWDC1weVzCQqcrGyj+l1eTR2Yxmo0VTPTkCjgcKwJZXV5YM0xqgaORnNUmJji+Y6UVgn +r/If3Zkfg0rzz8fiklnrNu5SyrcnPu3iC9A8rnpeWdaSx68BEVSpa6WZr6TOrZKrMJf 8vQX/dA/BQXVuGgxq9GW2U4tmT1K8zLC0a14TN4HH7Ccv2rbtK1XYQfwhtIeVX1D3mUZ J0k2kgSIZFVy8HKSwvYwKbpBDhv3NEt+hphSgxP0hoJwiPRw+T+lvewt18wfRf98BIH5 DFEQ== 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=Qk91FkgmRPBd4RbxZsnJj0TQMSWSIxQg9T1Z/TzHnqk=; b=HVu2pCiMn3reFaXfdI716zmaw8ipN5ot4cYpLs2flKdO6PHJVqLL7K++AXay95ep6e Vu6pNHNseYqj635ECISs5CmoygVO0Uy+igq/HhyYKPRaRB4AznNL+gfBYvNhZu7ABHs2 HFI0s+2OABA8zm59xxtq/V5QGODKJ1zKkH4EMv8uFF3bO8+0tY/76kHuZHd2LN/Hu+X/ ltDYNjrlvekvjbssXr6fKcW3EbyEMYPMDrqxUgWtV5B1qK4tHtL/JhRci+c+k8ieZtPH kB6EJmbIIUXDRMPy56Mh3ATunspbv44j42dJXg9l7whv0MbSK6GGMkldjfo328y8Vi3G IFUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="qqn0J/Xm"; 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 by17si11435155ejc.260.2021.03.03.06.19.34; Wed, 03 Mar 2021 06:20:02 -0800 (PST) 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="qqn0J/Xm"; 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 S244049AbhCAVDT (ORCPT + 99 others); Mon, 1 Mar 2021 16:03:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:49744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237389AbhCARMN (ORCPT ); Mon, 1 Mar 2021 12:12:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3C8C865025; Mon, 1 Mar 2021 16:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617006; bh=YqHQVm7+f4A89ADrFwcoRaKNkrrJHnrkGfkflwBx8fQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qqn0J/XmA6e+d5ETj1caETfWy4vIsJjTv6heQdWRoJpWcw0Bfe60AwK7in0uiBrDg Ze6lF/tlZiyGoqQHmR80vPbSxXZgmtO0jqqXJV69gcjtxI6Lt2Y6vFVOIaHP/PMWpM WVCtYmVBQYCV4dSlwdOyH/tleZU3lkDf9MP6uJe0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Gang He , Jun Piao , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 170/247] ocfs2: fix a use after free on error Date: Mon, 1 Mar 2021 17:13:10 +0100 Message-Id: <20210301161039.982897170@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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: Dan Carpenter [ Upstream commit c57d117f2b2f2a19b570c36f2819ef8d8210af20 ] The error handling in this function frees "reg" but it is still on the "o2hb_all_regions" list so it will lead to a use after freew. Joseph Qi points out that we need to clear the bit in the "o2hb_region_bitmap" as well Link: https://lkml.kernel.org/r/YBk4M6HUG8jB/jc7@mwanda Fixes: 1cf257f51191 ("ocfs2: fix memory leak") Signed-off-by: Dan Carpenter Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Gang He Cc: Jun Piao Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/ocfs2/cluster/heartbeat.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index 9b2ed62dd6385..19b0d358a0d6e 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c @@ -2154,7 +2154,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g o2hb_nego_timeout_handler, reg, NULL, ®->hr_handler_list); if (ret) - goto free; + goto remove_item; ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key, sizeof(struct o2hb_nego_msg), @@ -2173,6 +2173,12 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g unregister_handler: o2net_unregister_handler_list(®->hr_handler_list); +remove_item: + spin_lock(&o2hb_live_lock); + list_del(®->hr_all_item); + if (o2hb_global_heartbeat_active()) + clear_bit(reg->hr_region_num, o2hb_region_bitmap); + spin_unlock(&o2hb_live_lock); free: kfree(reg); return ERR_PTR(ret); -- 2.27.0