Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5065804pxb; Mon, 15 Feb 2021 08:36:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxlFwDnazn7B9o24P4znqtWpNVXgBSmMKYi7/weWkruI5lBETh/EnbCG8ApAQ4vUM3fsEP X-Received: by 2002:a17:906:145b:: with SMTP id q27mr16692657ejc.432.1613406990977; Mon, 15 Feb 2021 08:36:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613406990; cv=none; d=google.com; s=arc-20160816; b=JUsAQkGvVBfn8IjyDQZYpmHcaW322yWa+5Q+qLTRwdC1nM1Tzr7dHKuzYUCYWrKDKA RD1dJ87XoWsoxCZhuNDmSuz7Cm4I9YpYfP+CFfnJ/EjUOb7G+clavpeFF0ir9xEc4Rpk oNmuBPOsBlK662k3Mrtryujv8WWuSo8L1P5ZPgLe06//iZpLrqZvy50CNC6Kp6npYNZx O197ueJ6R3ImUdv6Nl0SNZNe9RTdFaDxsrn3fmjPU0haWthwszOFGFNliQxA6w/8CswS unC4k3xgJo3Lp0o7LAKhrEroa72DNJ5T6LuoQVl9NTE2TyJX/viL++6KP4Aic2oDDuin k8vQ== 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=DWfPsE+gJLoz6gMREX8zMAbbUhoJOCp2FGQqk1lUcZs=; b=UlqQ+dM8jbsQon72LN+5USQVMXANBYUN5AqnI99v1cclzBonI47ig38o6fJrBBQoR2 qTuBzob+tK18X0tlL6J2gP/cKsDI4eI51P0volJQb9xNDOGGetU3iWFHASDlj4Xv3/cO vucgFqCD18l/S6CBX+DLjYaYmiUQocnINqAf2xtT8BhB7y18hJgtvYzvgoAjKeCM34aQ iMUU7cHZdPqmoXONrz/Ij0br7ExPJjJt6ZKJuSdzOKV4b8XuHhHX6fR5KzAGh29u1bzZ F6VWjdXhyrcpB12iWGarsUiOMGNVPwf6jXslyS84ybR1uxe+ah0bTfrQeFBpzbeNCu/D TZXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eY1EziUp; 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 hs7si14591675ejc.745.2021.02.15.08.36.05; Mon, 15 Feb 2021 08:36:30 -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=eY1EziUp; 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 S232020AbhBOQcw (ORCPT + 99 others); Mon, 15 Feb 2021 11:32:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:50042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbhBOPhi (ORCPT ); Mon, 15 Feb 2021 10:37:38 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B591264E8C; Mon, 15 Feb 2021 15:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403178; bh=7kN2c0zS43W1ezhJ8zKhzOvGb8nZLCzH8nWPCepBNY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eY1EziUpB09GOupDFgDx4oYPNPW8kmff+wno6nRGrImdXe9B696JE8Dp96cTUvvyi niGHnQDeHZ3J+M+aEtnQv8ENepqa5Yj32LZ+4M+TqJSMbiJFaEx3BOV9+CnS+XsT8T CQCsJkKvU1s955I+s99bm099thNj8MmD5dGe7p5U= 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.10 057/104] netfilter: xt_recent: Fix attempt to update deleted entry Date: Mon, 15 Feb 2021 16:27:10 +0100 Message-Id: <20210215152721.321534854@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@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 606411869698e..0446307516cdf 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