Skip to content

Commit 93a165c

Browse files
committed
Merge tag '9p-for-6.7-rc7' of https://github.com/martinetd/linux
Pull 9p fixes from Dominique Martinet: "Two small fixes scheduled for stable trees: A tracepoint fix that's been reading past the end of messages forever, but semi-recently also went over the end of the buffer. And a potential incorrectly freeing garbage in pdu parsing error path" * tag '9p-for-6.7-rc7' of https://github.com/martinetd/linux: net: 9p: avoid freeing uninit memory in p9pdu_vreadf 9p: prevent read overrun in protocol dump tracepoint
2 parents 24e0d2e + ff49bf1 commit 93a165c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

include/trace/events/9p.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,21 @@ TRACE_EVENT(9p_protocol_dump,
178178
__field( void *, clnt )
179179
__field( __u8, type )
180180
__field( __u16, tag )
181-
__array( unsigned char, line, P9_PROTO_DUMP_SZ )
181+
__dynamic_array(unsigned char, line,
182+
min_t(size_t, pdu->capacity, P9_PROTO_DUMP_SZ))
182183
),
183184

184185
TP_fast_assign(
185186
__entry->clnt = clnt;
186187
__entry->type = pdu->id;
187188
__entry->tag = pdu->tag;
188-
memcpy(__entry->line, pdu->sdata, P9_PROTO_DUMP_SZ);
189+
memcpy(__get_dynamic_array(line), pdu->sdata,
190+
__get_dynamic_array_len(line));
189191
),
190-
TP_printk("clnt %lu %s(tag = %d)\n%.3x: %16ph\n%.3x: %16ph\n",
192+
TP_printk("clnt %lu %s(tag = %d)\n%*ph\n",
191193
(unsigned long)__entry->clnt, show_9p_op(__entry->type),
192-
__entry->tag, 0, __entry->line, 16, __entry->line + 16)
194+
__entry->tag, __get_dynamic_array_len(line),
195+
__get_dynamic_array(line))
193196
);
194197

195198

net/9p/protocol.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
394394
uint16_t *nwname = va_arg(ap, uint16_t *);
395395
char ***wnames = va_arg(ap, char ***);
396396

397+
*wnames = NULL;
398+
397399
errcode = p9pdu_readf(pdu, proto_version,
398400
"w", nwname);
399401
if (!errcode) {
@@ -403,6 +405,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
403405
GFP_NOFS);
404406
if (!*wnames)
405407
errcode = -ENOMEM;
408+
else
409+
(*wnames)[0] = NULL;
406410
}
407411

408412
if (!errcode) {
@@ -414,20 +418,25 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
414418
proto_version,
415419
"s",
416420
&(*wnames)[i]);
417-
if (errcode)
421+
if (errcode) {
422+
(*wnames)[i] = NULL;
418423
break;
424+
}
419425
}
420426
}
421427

422428
if (errcode) {
423429
if (*wnames) {
424430
int i;
425431

426-
for (i = 0; i < *nwname; i++)
432+
for (i = 0; i < *nwname; i++) {
433+
if (!(*wnames)[i])
434+
break;
427435
kfree((*wnames)[i]);
436+
}
437+
kfree(*wnames);
438+
*wnames = NULL;
428439
}
429-
kfree(*wnames);
430-
*wnames = NULL;
431440
}
432441
}
433442
break;

0 commit comments

Comments
 (0)