Skip to content

Commit cae54f4

Browse files
committed
CVE-2016-7985,7986/fixup medsa_print()
The code in medsa_print() assumed that the MEDSA packet always follows an Ethernet header that is inside the allocated memory buffer. But this is not always the case, see commit 6bc4429 for rationale. Eliminate the Ethernet header pointer and just pass on the struct lladdr_info arguments provided.
1 parent 2cc01cb commit cae54f4

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

netdissect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ extern void lwapp_control_print(netdissect_options *, const u_char *, u_int, int
547547
extern void lwapp_data_print(netdissect_options *, const u_char *, u_int);
548548
extern void lwres_print(netdissect_options *, const u_char *, u_int);
549549
extern void m3ua_print(netdissect_options *, const u_char *, const u_int);
550-
extern void medsa_print(netdissect_options *, const u_char *, u_int, u_int);
550+
extern void medsa_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *);
551551
extern u_int mfr_print(netdissect_options *, register const u_char *, u_int);
552552
extern void mobile_print(netdissect_options *, const u_char *, u_int);
553553
extern int mobility_print(netdissect_options *, const u_char *, const u_char *);

print-ether.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ ethertype_print(netdissect_options *ndo,
439439
return (1);
440440

441441
case ETHERTYPE_MEDSA:
442-
medsa_print(ndo, p, length, caplen);
442+
medsa_print(ndo, p, length, caplen, src, dst);
443443
return (1);
444444

445445
case ETHERTYPE_LAT:

print-medsa.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,13 @@ medsa_print_full(netdissect_options *ndo,
138138

139139
void
140140
medsa_print(netdissect_options *ndo,
141-
const u_char *bp, u_int length, u_int caplen)
141+
const u_char *bp, u_int length, u_int caplen,
142+
const struct lladdr_info *src, const struct lladdr_info *dst)
142143
{
143-
register const struct ether_header *ep;
144144
const struct medsa_pkthdr *medsa;
145-
struct lladdr_info src, dst;
146145
u_short ether_type;
147146

148147
medsa = (const struct medsa_pkthdr *)bp;
149-
ep = (const struct ether_header *)(bp - sizeof(*ep));
150148
ND_TCHECK(*medsa);
151149

152150
if (!ndo->ndo_eflag)
@@ -159,14 +157,10 @@ medsa_print(netdissect_options *ndo,
159157
length -= 8;
160158
caplen -= 8;
161159

162-
src.addr = ESRC(ep);
163-
src.addr_string = etheraddr_string;
164-
dst.addr = EDST(ep);
165-
dst.addr_string = etheraddr_string;
166160
ether_type = EXTRACT_16BITS(&medsa->ether_type);
167161
if (ether_type <= ETHERMTU) {
168162
/* Try to print the LLC-layer header & higher layers */
169-
if (llc_print(ndo, bp, length, caplen, &src, &dst) < 0) {
163+
if (llc_print(ndo, bp, length, caplen, src, dst) < 0) {
170164
/* packet type not known, print raw packet */
171165
if (!ndo->ndo_suppress_default_print)
172166
ND_DEFAULTPRINT(bp, caplen);
@@ -177,8 +171,7 @@ medsa_print(netdissect_options *ndo,
177171
tok2str(ethertype_values, "Unknown",
178172
ether_type),
179173
ether_type));
180-
181-
if (ethertype_print(ndo, ether_type, bp, length, caplen, &src, &dst) == 0) {
174+
if (ethertype_print(ndo, ether_type, bp, length, caplen, src, dst) == 0) {
182175
/* ether_type not known, print raw packet */
183176
if (!ndo->ndo_eflag)
184177
ND_PRINT((ndo, "ethertype %s (0x%04x) ",

0 commit comments

Comments
 (0)