Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1569389pxb; Mon, 22 Feb 2021 05:36:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkCvge+yTd3kpsVZx9A1NDCF6jHmcRGAhoBfAa6A1IVKNJV50XBF4bFRpuBH2NN2nt13QU X-Received: by 2002:a17:907:7667:: with SMTP id kk7mr9069018ejc.92.1614001017139; Mon, 22 Feb 2021 05:36:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614001017; cv=none; d=google.com; s=arc-20160816; b=AaYi1uK2FMtizxTYpaOvzBknZy80+XQ/5KWow6uiI2mas7Ax085GK809c5CEsOGuMd 9oP2Kr4y8vo83VV83VZ7FZRXTjUYTUYmWlFoRUX5asNGjC5dTg6TQKXhk8kRCL61CGv4 PH+C6B9DKqMn66NClwrnW+hX78y5plOD9P6i64on6A/o6jLgDGNa3Ccv8xVUw3cX2mpt 02tIzD5qfd7jRJTXe7CYGJA7ZIj0aO/9NofRkSgoLxpNgukQ7Ww+bhRhgm7ZoSXBs2Gc SXCuXA2HJy+aTZ/V2HqcodUbJ2SDDAayH1lzS8QulQ3fMRx6hPGIz1Rs4cpsTzY6K3fW vg+A== 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=qZLI/YXoeiiBBT8moNAH4oh+MWgWdfvGwryU7sdFk0I=; b=rFhc2Qk6sbyhLb2L6c3SqMfLklov5VV1TZjW+iOUAM9vebvrrG+SCJKp5CAJZqasSV 3CgOwLPCUeHHhICGiG+MWcZjXDTvbTxrLjIRqCs4hDt3iEAR1Hy59W++XlWvz30/xYXo 0IxnTi0vTJKsagbumPZHxV8/PDNbjLuuQ3MQOJui5sIYudlincMRV9rOlL0qRh/MesUs 9Zn4BjdJxls/xTBItmG0n3vAUpzv0xeqBVZSR13bSstGJOMUO0FsdA20CbpPYDs51KNe QoR580DTulyr7hsAS035nWrd2wPkm6mlqoiAxmPu+TBgFm/wAUNU2phooR7HpCa7PCUf gkQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a7D2nb6b; 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 mm22si12016543ejb.372.2021.02.22.05.36.34; Mon, 22 Feb 2021 05:36:57 -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=a7D2nb6b; 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 S231964AbhBVNc7 (ORCPT + 99 others); Mon, 22 Feb 2021 08:32:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:52868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231379AbhBVMmM (ORCPT ); Mon, 22 Feb 2021 07:42:12 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C4EFB64F28; Mon, 22 Feb 2021 12:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613997574; bh=ptm0Igm62iocqnuveZzTTYTeCPlKIaryCyRtOBi4g2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a7D2nb6bT9BR+J3ZHWkDk03fdG+Fzf5SXElLfcPpBdrfTtqlfCbD2il5ohm2PD3Z+ okq/B+twnS8HYVgZT1mP3YO+0lKWrkFcb2nmgcnF32m6J6/3RgUIOvi/iCUS7C4SqE camMMATHMpu+jpHsmDrYQIol/h1W2vacsT4YtGtk= 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 4.4 15/35] netfilter: xt_recent: Fix attempt to update deleted entry Date: Mon, 22 Feb 2021 13:36:11 +0100 Message-Id: <20210222121019.596937433@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210222121013.581198717@linuxfoundation.org> References: <20210222121013.581198717@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 cd53b861a15c1..ffe673c6a2485 100644 --- a/net/netfilter/xt_recent.c +++ b/net/netfilter/xt_recent.c @@ -156,7 +156,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; @@ -165,6 +166,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. */ @@ -307,7 +314,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