Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5032978pxb; Mon, 15 Feb 2021 07:50:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYv4EcFqrcXENc5kjvkVusrKjMXNuQG0pGvZRQu16fBR5plTdZXgU4H+Ok4brCwKMcHiVr X-Received: by 2002:a05:6402:11c7:: with SMTP id j7mr16239699edw.290.1613404250589; Mon, 15 Feb 2021 07:50:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613404250; cv=none; d=google.com; s=arc-20160816; b=Z+QsQapEM7vjuQWbuJo2qmvQT6EyTz065B754Us6Jz6wcBv2zrO1V5nETDJm4RtyRH IycqmGGhJnCYpXQ4D3n9BbDdLIxG4EE4cNfuVp6GTsjd1c7/G4jMvcUhmnApxJtSWU0G uZSF1HOcZii9A1b81N8jpobBXROOchdYnRW8faV25O04Ou3NklF02cdYlO1iEDj8aKlZ 3E4KkDYNJvmyftQk19DWv/5GazcKeN10BjnhRYkjWhH+Gh7Hy/rDdHZHXVv2YIBxLMkI W51IoxBYBocPp2Numsnfjit4+PHJ1oMIcGuRYWPGnh/FS9b7CPLQVy1ltZdiOW/Sn5bi 5KBA== 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=tk0Mmumc+h/tTNFTW5jejooQCFHDlEIxRxc8NEp5je8=; b=v2oj2DoBy4G7KCkkWHtpJKFFuUJ5Ua9tVjMunhWa1LWl/02lww80//5PRLwan8EMpx 3jFcpPJyy1gH5vhlxrtLimpg/8V7CMN44luDGAyz4WlGeRdpawdf5elrZuqTvr5hCU/p wKPDiuMsVUYha5FdZLicLVOd2wQQSlFv191Bys3wDrUsvIcyAVxh+loF2t/jVyDMdOQK l/kXRGRQ4O5srVCUi1NhsiI0uC9JlHdfQ1YAokzF/jFKnvfgqkQXEgOI3HHY+xloQRnh jwT/1tSAvRmu91ScfSGLlwgH8etYYB4qb8IqdR5Xall+38Ate3BvhY+HnEmtp2/XbpIO OnDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QvOc6A0F; 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 h25si5096696ejk.416.2021.02.15.07.50.27; Mon, 15 Feb 2021 07:50:50 -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=QvOc6A0F; 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 S231799AbhBOPrp (ORCPT + 99 others); Mon, 15 Feb 2021 10:47:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:46648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbhBOPbO (ORCPT ); Mon, 15 Feb 2021 10:31:14 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5D0B064E94; Mon, 15 Feb 2021 15:29:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613402943; bh=16jE04B3ZlS9IJ8ggLjrq7M7ViurPTWv6vSVW9LC03M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QvOc6A0FqRHhm0NPj3Fl1Kq8WOz5U2YJRSM3Yy9eGQPGxURDFqO07LhSh+n1wUZRk WFRQ9Ff3EQlws3hOOsc/TniG2bC1wq8mPBy7IpYEFes6k7Pz2OIawsmmonC/H67LE6 AHqESfG/LnzgSrgXXLZdhbLM42EEARzMjY+yTYXk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Reindl Harald , Jozsef Kadlecsik , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.4 29/60] netfilter: xt_recent: Fix attempt to update deleted entry Date: Mon, 15 Feb 2021 16:27:17 +0100 Message-Id: <20210215152716.285572820@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@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: Jozsef Kadlecsik [ Upstream commit b1bdde33b72366da20d10770ab7a49fe87b5e190 ] When both --reap and --update flag are specified, there's a code path at which the entry to be updated is reaped beforehand, which then leads to kernel crash. Reap only entries which won't be updated. Fixes kernel bugzilla #207773. Link: https://bugzilla.kernel.org/show_bug.cgi?id=207773 Reported-by: Reindl Harald Fixes: 0079c5aee348 ("netfilter: xt_recent: add an entry reaper") Signed-off-by: Jozsef Kadlecsik Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/xt_recent.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c index 6c2582a197667..3469b60736103 100644 --- a/net/netfilter/xt_recent.c +++ b/net/netfilter/xt_recent.c @@ -152,7 +152,8 @@ static void recent_entry_remove(struct recent_table *t, struct recent_entry *e) /* * Drop entries with timestamps older then 'time'. */ -static void recent_entry_reap(struct recent_table *t, unsigned long time) +static void recent_entry_reap(struct recent_table *t, unsigned long time, + struct recent_entry *working, bool update) { struct recent_entry *e; @@ -161,6 +162,12 @@ static void recent_entry_reap(struct recent_table *t, unsigned long time) */ e = list_entry(t->lru_list.next, struct recent_entry, lru_list); + /* + * Do not reap the entry which are going to be updated. + */ + if (e == working && update) + return; + /* * The last time stamp is the most recent. */ @@ -303,7 +310,8 @@ recent_mt(const struct sk_buff *skb, struct xt_action_param *par) /* info->seconds must be non-zero */ if (info->check_set & XT_RECENT_REAP) - recent_entry_reap(t, time); + recent_entry_reap(t, time, e, + info->check_set & XT_RECENT_UPDATE && ret); } if (info->check_set & XT_RECENT_SET || -- 2.27.0