29 May, 2017

2 commits


25 Apr, 2017

1 commit

  • We forget to free dummy elements when deleting the set. So when I was
    running nft-test.py, I saw many kmemleak warnings:
    kmemleak: 1344 new suspected memory leaks ...
    # cat /sys/kernel/debug/kmemleak
    unreferenced object 0xffff8800631345c8 (size 32):
    comm "nft", pid 9075, jiffies 4295743309 (age 1354.815s)
    hex dump (first 32 bytes):
    f8 63 13 63 00 88 ff ff 88 79 13 63 00 88 ff ff .c.c.....y.c....
    04 0c 00 00 00 00 00 00 00 00 00 00 08 03 00 00 ................
    backtrace:
    [] kmemleak_alloc+0x4a/0xa0
    [] __kmalloc+0x164/0x310
    [] nft_set_elem_init+0x3d/0x1b0 [nf_tables]
    [] nft_add_set_elem+0x45a/0x8c0 [nf_tables]
    [] nf_tables_newsetelem+0x105/0x1d0 [nf_tables]
    [] nfnetlink_rcv+0x414/0x770 [nfnetlink]
    [] netlink_unicast+0x1f6/0x310
    [] netlink_sendmsg+0x306/0x3b0
    ...

    Fixes: e920dde516088 ("netfilter: nft_set_bitmap: keep a list of dummy elements")
    Signed-off-by: Liping Zhang
    Signed-off-by: Pablo Neira Ayuso

    Liping Zhang
     

13 Mar, 2017

2 commits

  • Element comments may come without any prior set flag, so we have to keep
    a list of dummy struct nft_set_ext to keep this information around. This
    is only useful for set dumps to userspace. From the packet path, this
    set type relies on the bitmap representation. This patch simplifies the
    logic since we don't need to allocate the dummy nft_set_ext structure
    anymore on the fly at the cost of increasing memory consumption because
    of the list of dummy struct nft_set_ext.

    Fixes: 665153ff5752 ("netfilter: nf_tables: add bitmap set type")
    Signed-off-by: Pablo Neira Ayuso

    Pablo Neira Ayuso
     
  • Currently we just assume the element key as a u32 integer, regardless of
    the set key length.

    This is incorrect, for example, the tcp port number is only 16 bits.
    So when we use the nft_payload expr to get the tcp dport and store
    it to dreg, the dport will be stored at 0~15 bits, and 16~31 bits
    will be padded with zero.

    So the reg->data[dreg] will be looked like as below:
    0 15 31
    +-+-+-+-+-+-+-+-+-+-+-+-+
    | tcp dport | 0 |
    +-+-+-+-+-+-+-+-+-+-+-+-+
    But for these big-endian systems, if we treate this register as a u32
    integer, the element key will be larger than 65535, so the following
    lookup in bitmap set will cause out of bound access.

    Another issue is that if we add element with comments in bitmap
    set(although the comments will be ignored eventually), the element will
    vanish strangely. Because we treate the element key as a u32 integer, so
    the comments will become the part of the element key, then the element
    key will also be larger than 65535 and out of bound access will happen:
    # nft add element t s { 1 comment test }

    Since set->klen is 1 or 2, it's fine to treate the element key as a u8 or
    u16 integer.

    Fixes: 665153ff5752 ("netfilter: nf_tables: add bitmap set type")
    Signed-off-by: Liping Zhang
    Signed-off-by: Pablo Neira Ayuso

    Liping Zhang
     

27 Feb, 2017

1 commit


08 Feb, 2017

1 commit

  • This patch adds a new bitmap set type. This bitmap uses two bits to
    represent one element. These two bits determine the element state in the
    current and the future generation that fits into the nf_tables commit
    protocol. When dumping elements back to userspace, the two bits are
    expanded into a struct nft_set_ext object.

    If no NFTA_SET_DESC_SIZE is specified, the existing automatic set
    backend selection prefers bitmap over hash in case of keys whose size is

    Pablo Neira Ayuso