RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2033505 - tc u32 ematch configuration might fail even nexthdr offset is aligned to 4
Summary: tc u32 ematch configuration might fail even nexthdr offset is aligned to 4
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: iproute
Version: 8.7
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: 8.7
Assignee: Andrea Claudi
QA Contact: liujian
URL:
Whiteboard:
Depends On: 2074607
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-12-17 03:24 UTC by Alfred Yang
Modified: 2022-11-14 09:13 UTC (History)
4 users (show)

Fixed In Version: iproute-5.18.0-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-11-08 10:52:53 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-106061 0 None None None 2021-12-17 03:25:00 UTC
Red Hat Product Errata RHBA-2022:7752 0 None None None 2022-11-08 10:53:10 UTC

Description Alfred Yang 2021-12-17 03:24:24 UTC
Description of problem:
tc u32 ematch configuration might fail even nexthdr offset is aligned to 4

Version-Release number of selected component (if applicable):
We've tested iproute-4.11.0-30.el7.x86_64 and -25 and -14 version.

How reproducible:
I use a simple script to constantly reproduce it. (Note: it is a dead loop)
#!/bin/sh

tc qdisc del dev dummy0 root
tc qdisc add dev dummy0 root handle 1: htb r2q 1 default 1
tc class add dev dummy0 parent 1:1 classid 1:108 htb quantum 1000000 rate 1.00mbit ceil 10.00mbit burst 6k

TC="valgrind -q tc"
TC=tc
#TC=./tc

c=0
while true; do
if ! $TC filter add dev dummy0 protocol all parent 1: prio 1 basic match "meta(vlan mask 0xfff eq 1)" and "u32(u32 0x20011002 0xffffffff at nexthdr+8)" flowid 1:108; then
  echo add $c
  exit 0
fi
if ! $TC filter del dev dummy0 protocol all parent 1: prio 1 basic match "meta(vlan mask 0xfff eq 1)" and "u32(u32 0x20011002 0xffffffff at nexthdr+8)" flowid 1:108; then
  echo del $c
  exit 0
fi
c=$(expr $c + 1)
done

Steps to Reproduce:
1. modprobe dummy
2. run above script

Actual results:
script will fail and exit.

Expected results:
no fail, run forever.

Additional info:
Error output is:
u32: invalid offset alignment, must be aligned to 4.
... meta(vlan mask 0xfff eq 1) and >>u32(u32 0x20011002 0xffffffff at nexthdr+8)<< ...
... u32(u32 0x20011002 0xffffffff at >>nexthdr+8<<)...
Usage: u32(ALIGN VALUE MASK at [ nexthdr+ ] OFFSET)
where: ALIGN  := { u8 | u16 | u32 }

Example: u32(u16 0x1122 0xffff at nexthdr+4)
Illegal "ematch"

Comment 3 Alfred Yang 2021-12-18 01:34:55 UTC
From investigation and run by valgrind with debug info, we can see below output, of coz, if it is run by valgrind, the issue cannot be reproduced.
==29412== Use of uninitialised value of size 8
==29412==    at 0x53786CD: ____strtoul_l_internal (strtol_l.c:461)
==29412==    by 0x43246C: u32_parse_eopt (em_u32.c:89)
==29412==    by 0x412921: parse_tree (m_ematch.c:216)
==29412==    by 0x412921: parse_ematch (m_ematch.c:352)
==29412==    by 0x42197D: basic_parse_opt (f_basic.c:65)
==29412==    by 0x40B915: tc_filter_modify (tc_filter.c:196)
==29412==    by 0x407B3F: main (tc.c:348)

the codes are in em_u32.c, the function u32_parse_eopt()

     83         nh_len = strlen("nexthdr+");
     84         if (a->len > nh_len && !memcmp(a->data, "nexthdr+", nh_len)) {
     85                 char buf[a->len - nh_len + 1];
     86         memset(buf, 0, a->len - nh_len + 1);   <<<- this line is added by me to fix the issue
     87                 offmask = -1;
     88                 memcpy(buf, a->data + nh_len, a->len - nh_len);
     89                 offset = strtoul(buf, NULL, 0);
     90         } else if (!bstrcmp(a, "nexthdr+")) {

We can see with line 86, buf might contain dirty data, line 88 only copy string but not the null terminator. This causes reading uninitialized data.
Oh, just find a simpler and more efficient fix might be explicitly set buf[a-len - nh_len] = 0 before strtoul.

Comment 6 Andrea Claudi 2022-05-06 12:57:41 UTC
This issue is still present on rhel-8.7, but is not critical enough to qualify for a rhel-7 fix. I'm moving this to rhel-8.7 to have this fixed there.

Comment 13 Mingyu Shi 2022-06-15 08:38:34 UTC
A TC-related bug, Liu Jian will help to deal with it.

Hi Liu Jian,
Sorry for the late reaction, please set an acceptable ITM for you.

Comment 16 errata-xmlrpc 2022-11-08 10:52:53 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (iproute bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:7752


Note You need to log in before you can comment on or make changes to this bug.