Skip to content

Commit e659c96

Browse files
committed
nx-match: Fix use-after-free parsing matches.
Address pointed by header_ptr might be free'd due to realloc happened in ofpbuf_put_hex(). Reported by valgrind in the test 379: check TCP flags expression in OXM and NXM. Invalid write of size 4 nx_match_from_string_raw (nx-match.c:1510) nx_match_from_string (nx-match.c:1538) ofctl_parse_nxm__ (ovs-ofctl.c:3325) ovs_cmdl_run_command (command-line.c:121) main (ovs-ofctl.c:137) Address 0x7a2cc40 is 0 bytes inside a block of size 64 free'd free (vg_replace_malloc.c:530) ofpbuf_resize__ (ofpbuf.c:246) ofpbuf_put (ofpbuf.c:386) ofpbuf_put_hex (ofpbuf.c:414) nx_match_from_string_raw (nx-match.c:1488) nx_match_from_string (nx-match.c:1538) ofctl_parse_nxm__ (ovs-ofctl.c:3325) Reported-by: William Tu <u9012063@gmail.com> Signed-off-by: Joe Stringer <joe@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
1 parent f3ea2ad commit e659c96

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

lib/nx-match.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,6 @@ nx_match_from_string_raw(const char *s, struct ofpbuf *b)
14681468
const char *name;
14691469
uint64_t header;
14701470
ovs_be64 nw_header;
1471-
ovs_be64 *header_ptr;
14721471
int name_len;
14731472
size_t n;
14741473

@@ -1485,7 +1484,7 @@ nx_match_from_string_raw(const char *s, struct ofpbuf *b)
14851484

14861485
s += name_len + 1;
14871486

1488-
header_ptr = ofpbuf_put_uninit(b, nxm_header_len(header));
1487+
b->header = ofpbuf_put_uninit(b, nxm_header_len(header));
14891488
s = ofpbuf_put_hex(b, s, &n);
14901489
if (n != nxm_field_bytes(header)) {
14911490
const struct mf_field *field = mf_from_oxm_header(header);
@@ -1508,7 +1507,7 @@ nx_match_from_string_raw(const char *s, struct ofpbuf *b)
15081507
}
15091508
}
15101509
nw_header = htonll(header);
1511-
memcpy(header_ptr, &nw_header, nxm_header_len(header));
1510+
memcpy(b->header, &nw_header, nxm_header_len(header));
15121511

15131512
if (nxm_hasmask(header)) {
15141513
s += strspn(s, " ");

0 commit comments

Comments
 (0)