Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tc/em_ipset: fix a crash on encoding #905

Merged
merged 1 commit into from
Apr 25, 2022
Merged

Conversation

ffourcot
Copy link
Collaborator

I found a new regression on master. Reproducer code is:

from pyroute2 import IPRoute
from pyroute2.wiset import WiSet, load_ipset

with WiSet(name="toto-temporary") as wiset:
    wiset.create()
ip = IPRoute()
match = [{"kind": "ipset", "index": load_ipset("toto-temporary").index, "mode": "src"}]
ip.tc("add-filter", "basic", 0, parent=0x10000, classid=0x10010, match=match)

with WiSet(name="toto-temporary") as wiset:
    wiset.destroy()

On master, I get this backtrace:

  File "/bisect", line 8, in <module>
    ip.tc("add-filter", "basic", 0, parent=0x10000, classid=0x10010, match=match)
  File "pyroute2_pkg/pr2modules/iproute/linux.py", line 1725, in tc
    opts = p.get_parameters(kwarg)
  File "pyroute2_pkg/pr2modules/netlink/rtnl/tcmsg/cls_basic.py", line 170, in get_parameters
    ret['attrs'].append(['TCA_BASIC_EMATCHES', get_tcf_ematches(kwarg)])
  File "pyroute2_pkg/pr2modules/netlink/rtnl/tcmsg/common_ematch.py", line 90, in get_tcf_ematches
    data.encode()
  File "pyroute2_pkg/pr2modules/netlink/rtnl/tcmsg/em_ipset.py", line 46, in encode
    nlmsg_base.encode(self)
  File "pyroute2_pkg/pr2modules/netlink/__init__.py", line 1079, in encode
    offset, diff = self.ft_encode(offset)
AttributeError: 'data' object has no attribute 'ft_encode'

On "old" pyroute2 version the reproduced probably return a "no such devices" since indexes are not matching.

I bisected the regression to b74c231,
"netlink: nlmsg_encoder_generic".

Moving class "data" to nlmsg instead of nlmsg_base
introduces another issue, with kernel returning EINVAL.
Only working solution I found was to inherit from nlmsg_encoder_generic

I found a new regression on master. Reproducer code is:

```python
from pyroute2 import IPRoute
from pyroute2.wiset import WiSet, load_ipset

with WiSet(name="toto-temporary") as wiset:
    wiset.create()
ip = IPRoute()
match = [{"kind": "ipset", "index": load_ipset("toto-temporary").index, "mode": "src"}]
ip.tc("add-filter", "basic", 0, parent=0x10000, classid=0x10010, match=match)

with WiSet(name="toto-temporary") as wiset:
    wiset.destroy()
```

On master, I get this backtrace:

```
  File "/bisect", line 8, in <module>
    ip.tc("add-filter", "basic", 0, parent=0x10000, classid=0x10010, match=match)
  File "pyroute2_pkg/pr2modules/iproute/linux.py", line 1725, in tc
    opts = p.get_parameters(kwarg)
  File "pyroute2_pkg/pr2modules/netlink/rtnl/tcmsg/cls_basic.py", line 170, in get_parameters
    ret['attrs'].append(['TCA_BASIC_EMATCHES', get_tcf_ematches(kwarg)])
  File "pyroute2_pkg/pr2modules/netlink/rtnl/tcmsg/common_ematch.py", line 90, in get_tcf_ematches
    data.encode()
  File "pyroute2_pkg/pr2modules/netlink/rtnl/tcmsg/em_ipset.py", line 46, in encode
    nlmsg_base.encode(self)
  File "pyroute2_pkg/pr2modules/netlink/__init__.py", line 1079, in encode
    offset, diff = self.ft_encode(offset)
AttributeError: 'data' object has no attribute 'ft_encode'
```

On "old" pyroute2 version the reproduced probably return a "no such devices" since indexes are not matching.

I bisected the regression to b74c231,
"netlink: nlmsg_encoder_generic".

Moving class "data" to ```nlmsg``` instead of ```nlmsg_base```
introduces another issue, with kernel returning EINVAL.
Only working solution I found was to inherit from nlmsg_encoder_generic
@svinota svinota merged commit 157f0a3 into svinota:master Apr 25, 2022
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Jul 7, 2022
https://build.opensuse.org/request/show/987191
by user dirkmueller + dimstar_suse
- update to 0.6.13:
  * iproute, ndb: use `pyroute2.requests` to filter and transform API call arguments
  * conntrack: fix exports: <svinota/pyroute2#900>
  * nftables: multiple fixes: <svinota/pyroute2#902>
  * tc: fix em_ipset crash: <svinota/pyroute2#905>
  * tests: integrated pre-commit, github actions and more
  * tests: support basic OpenBSD tests
  * pyroute2-cli: parser fixes

- Initial package (0.6.9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants