diff mbox series

[lvc-project] netfilter: xt_recent: Fix attempt to update removed entry

Message ID 20230209125831.2674811-1-Igor.A.Artemiev@mcst.ru (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [lvc-project] netfilter: xt_recent: Fix attempt to update removed entry | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 2 blamed authors not CCed: kaber@trash.net davem@davemloft.net; 5 maintainers not CCed: pabeni@redhat.com kaber@trash.net kuba@kernel.org edumazet@google.com davem@davemloft.net
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Igor Artemiev Feb. 9, 2023, 12:58 p.m. UTC
When both --remove and --update flag are specified, there's a code
path at which the entry to be updated is removed beforehand,
that leads to kernel crash. Update entry, if --remove flag
don't specified.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Igor Artemiev <Igor.A.Artemiev@mcst.ru>
Fixes: 404bdbfd242c ("[NETFILTER]: recent match: replace by rewritten version")
---
 net/netfilter/xt_recent.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Florian Westphal Feb. 9, 2023, 3:07 p.m. UTC | #1
Igor Artemiev <Igor.A.Artemiev@mcst.ru> wrote:
> When both --remove and --update flag are specified, there's a code
> path at which the entry to be updated is removed beforehand,
> that leads to kernel crash. Update entry, if --remove flag
> don't specified.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.

How did you manage to do this?  --update and --remove are supposed
to be mutually exclusive.
Jan Engelhardt Feb. 9, 2023, 4:09 p.m. UTC | #2
On Thursday 2023-02-09 16:07, Florian Westphal wrote:

>Igor Artemiev <Igor.A.Artemiev@mcst.ru> wrote:
>> When both --remove and --update flag are specified, there's a code
>> path at which the entry to be updated is removed beforehand,
>> that leads to kernel crash. Update entry, if --remove flag
>> don't specified.
>> 
>> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
>How did you manage to do this?  --update and --remove are supposed
>to be mutually exclusive.

I suppose the exclusivity is only checked at the iptables command-line
and neverwhere else.
Florian Westphal Feb. 9, 2023, 8:17 p.m. UTC | #3
Jan Engelhardt <jengelh@inai.de> wrote:
> On Thursday 2023-02-09 16:07, Florian Westphal wrote:
> 
> >Igor Artemiev <Igor.A.Artemiev@mcst.ru> wrote:
> >> When both --remove and --update flag are specified, there's a code
> >> path at which the entry to be updated is removed beforehand,
> >> that leads to kernel crash. Update entry, if --remove flag
> >> don't specified.
> >> 
> >> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> >
> >How did you manage to do this?  --update and --remove are supposed
> >to be mutually exclusive.
> 
> I suppose the exclusivity is only checked at the iptables command-line
> and neverwhere else.

Removing the userspace check gives me an -EINVAL from checkentry.
diff mbox series

Patch

diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index 7ddb9a78e3fc..189a413aa9d8 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -315,7 +315,8 @@  recent_mt(const struct sk_buff *skb, struct xt_action_param *par)
 	}
 
 	if (info->check_set & XT_RECENT_SET ||
-	    (info->check_set & XT_RECENT_UPDATE && ret)) {
+	    (info->check_set & XT_RECENT_UPDATE && ret &&
+	     !(info->check_set & XT_RECENT_REMOVE))) {
 		recent_entry_update(t, e);
 		e->ttl = ttl;
 	}