Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

9p/net: fix possible memory leak in p9_check_errors()

When p9pdu_readf() is called with "s?d" attribute, it allocates a pointer
that will store a string. But when p9pdu_readf() fails while handling "d"
then this pointer will not be freed in p9_check_errors().

Fixes: 51a87c552dfd ("9p: rework client code to use new protocol support functions")
Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com>
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
Message-ID: <20231027030302.11927-1-hbh25y@gmail.com>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>

authored by

Hangyu Hua and committed by
Dominique Martinet
ce070879 e02be639

+4 -2
+4 -2
net/9p/client.c
··· 540 540 return 0; 541 541 542 542 if (!p9_is_proto_dotl(c)) { 543 - char *ename; 543 + char *ename = NULL; 544 544 545 545 err = p9pdu_readf(&req->rc, c->proto_version, "s?d", 546 546 &ename, &ecode); 547 - if (err) 547 + if (err) { 548 + kfree(ename); 548 549 goto out_err; 550 + } 549 551 550 552 if (p9_is_proto_dotu(c) && ecode < 512) 551 553 err = -ecode;