Skip to content

Commit 99af179

Browse files
Dominique Martinetgregkh
authored andcommitted
9p: p9dirent_read: check network-provided name length
[ Upstream commit ef5305f ] strcpy to dirent->d_name could overflow the buffer, use strscpy to check the provided string length and error out if the size was too big. While we are here, make the function return an error when the pdu parsing failed, instead of returning the pdu offset as if it had been a success... Link: http://lkml.kernel.org/r/[email protected] Addresses-Coverity-ID: 139133 ("Copy into fixed size buffer") Signed-off-by: Dominique Martinet <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent c01ddaa commit 99af179

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

net/9p/protocol.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,13 +622,19 @@ int p9dirent_read(struct p9_client *clnt, char *buf, int len,
622622
if (ret) {
623623
p9_debug(P9_DEBUG_9P, "<<< p9dirent_read failed: %d\n", ret);
624624
trace_9p_protocol_dump(clnt, &fake_pdu);
625-
goto out;
625+
return ret;
626626
}
627627

628-
strcpy(dirent->d_name, nameptr);
628+
ret = strscpy(dirent->d_name, nameptr, sizeof(dirent->d_name));
629+
if (ret < 0) {
630+
p9_debug(P9_DEBUG_ERROR,
631+
"On the wire dirent name too long: %s\n",
632+
nameptr);
633+
kfree(nameptr);
634+
return ret;
635+
}
629636
kfree(nameptr);
630637

631-
out:
632638
return fake_pdu.offset;
633639
}
634640
EXPORT_SYMBOL(p9dirent_read);

0 commit comments

Comments
 (0)