Commit b1bdde33 authored by Jozsef Kadlecsik's avatar Jozsef Kadlecsik Committed by Pablo Neira Ayuso

netfilter: xt_recent: Fix attempt to update deleted entry

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=207773Reported-by: default avatarReindl Harald <h.reindl@thelounge.net>
Fixes: 0079c5ae ("netfilter: xt_recent: add an entry reaper")
Signed-off-by: default avatarJozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 44a674d6
...@@ -152,7 +152,8 @@ static void recent_entry_remove(struct recent_table *t, struct recent_entry *e) ...@@ -152,7 +152,8 @@ static void recent_entry_remove(struct recent_table *t, struct recent_entry *e)
/* /*
* Drop entries with timestamps older then 'time'. * 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; struct recent_entry *e;
...@@ -161,6 +162,12 @@ static void recent_entry_reap(struct recent_table *t, unsigned long time) ...@@ -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); 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. * The last time stamp is the most recent.
*/ */
...@@ -303,7 +310,8 @@ recent_mt(const struct sk_buff *skb, struct xt_action_param *par) ...@@ -303,7 +310,8 @@ recent_mt(const struct sk_buff *skb, struct xt_action_param *par)
/* info->seconds must be non-zero */ /* info->seconds must be non-zero */
if (info->check_set & XT_RECENT_REAP) 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 || if (info->check_set & XT_RECENT_SET ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment