Patch "netfilter: ipset: Update byte and packet counters regardless of whether they match" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    netfilter: ipset: Update byte and packet counters regardless of whether they match

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     netfilter-ipset-update-byte-and-packet-counters-rega.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 57a78d3d928c7e5fc23bf388dff3e33386359d5c
Author: Stefano Brivio <sbrivio@xxxxxxxxxx>
Date:   Thu Oct 29 16:39:46 2020 +0100

    netfilter: ipset: Update byte and packet counters regardless of whether they match
    
    [ Upstream commit 7d10e62c2ff8e084c136c94d32d9a94de4d31248 ]
    
    In ip_set_match_extensions(), for sets with counters, we take care of
    updating counters themselves by calling ip_set_update_counter(), and of
    checking if the given comparison and values match, by calling
    ip_set_match_counter() if needed.
    
    However, if a given comparison on counters doesn't match the configured
    values, that doesn't mean the set entry itself isn't matching.
    
    This fix restores the behaviour we had before commit 4750005a85f7
    ("netfilter: ipset: Fix "don't update counters" mode when counters used
    at the matching"), without reintroducing the issue fixed there: back
    then, mtype_data_match() first updated counters in any case, and then
    took care of matching on counters.
    
    Now, if the IPSET_FLAG_SKIP_COUNTER_UPDATE flag is set,
    ip_set_update_counter() will anyway skip counter updates if desired.
    
    The issue observed is illustrated by this reproducer:
    
      ipset create c hash:ip counters
      ipset add c 192.0.2.1
      iptables -I INPUT -m set --match-set c src --bytes-gt 800 -j DROP
    
    if we now send packets from 192.0.2.1, bytes and packets counters
    for the entry as shown by 'ipset list' are always zero, and, no
    matter how many bytes we send, the rule will never match, because
    counters themselves are not updated.
    
    Reported-by: Mithil Mhatre <mmhatre@xxxxxxxxxx>
    Fixes: 4750005a85f7 ("netfilter: ipset: Fix "don't update counters" mode when counters used at the matching")
    Signed-off-by: Stefano Brivio <sbrivio@xxxxxxxxxx>
    Signed-off-by: Jozsef Kadlecsik <kadlec@xxxxxxxxxxxxx>
    Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index 133a3f1b6f56c..3cc4daa856d6b 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -485,13 +485,14 @@ ip_set_match_extensions(struct ip_set *set, const struct ip_set_ext *ext,
 	if (SET_WITH_COUNTER(set)) {
 		struct ip_set_counter *counter = ext_counter(data, set);
 
+		ip_set_update_counter(counter, ext, flags);
+
 		if (flags & IPSET_FLAG_MATCH_COUNTERS &&
 		    !(ip_set_match_counter(ip_set_get_packets(counter),
 				mext->packets, mext->packets_op) &&
 		      ip_set_match_counter(ip_set_get_bytes(counter),
 				mext->bytes, mext->bytes_op)))
 			return false;
-		ip_set_update_counter(counter, ext, flags);
 	}
 	if (SET_WITH_SKBINFO(set))
 		ip_set_get_skbinfo(ext_skbinfo(data, set),



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux