All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: 9p: avoid freeing uninit memory in p9pdu_vreadf
@ 2023-12-05  8:05 Fedor Pchelkin
  2023-12-05  9:07 ` Dominique Martinet
  0 siblings, 1 reply; 18+ messages in thread
From: Fedor Pchelkin @ 2023-12-05  8:05 UTC (permalink / raw)
  To: Eric Van Hensbergen
  Cc: Fedor Pchelkin, Latchesar Ionkov, Dominique Martinet,
	Christian Schoenebeck, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, v9fs, netdev, linux-kernel,
	Alexey Khoroshilov, lvc-project

If an error occurs while processing an array of strings in p9pdu_vreadf
then uninitialized members of *wnames array are freed.

Fix this by iterating over only lower indices of the array.

Found by Linux Verification Center (linuxtesting.org).

Fixes: ace51c4dd2f9 ("9p: add new protocol support code")
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
---
 net/9p/protocol.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/9p/protocol.c b/net/9p/protocol.c
index 4e3a2a1ffcb3..d33387e74a66 100644
--- a/net/9p/protocol.c
+++ b/net/9p/protocol.c
@@ -393,6 +393,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
 		case 'T':{
 				uint16_t *nwname = va_arg(ap, uint16_t *);
 				char ***wnames = va_arg(ap, char ***);
+				int i;
 
 				errcode = p9pdu_readf(pdu, proto_version,
 								"w", nwname);
@@ -406,8 +407,6 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
 				}
 
 				if (!errcode) {
-					int i;
-
 					for (i = 0; i < *nwname; i++) {
 						errcode =
 						    p9pdu_readf(pdu,
@@ -421,9 +420,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
 
 				if (errcode) {
 					if (*wnames) {
-						int i;
-
-						for (i = 0; i < *nwname; i++)
+						while (--i >= 0)
 							kfree((*wnames)[i]);
 					}
 					kfree(*wnames);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-01-07 10:26 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-05  8:05 [PATCH] net: 9p: avoid freeing uninit memory in p9pdu_vreadf Fedor Pchelkin
2023-12-05  9:07 ` Dominique Martinet
2023-12-05  9:19   ` [PATCH v2] " Fedor Pchelkin
2023-12-05  9:31     ` Dominique Martinet
2023-12-05 12:15       ` Fedor Pchelkin
2023-12-05 12:43         ` Dominique Martinet
2023-12-05 12:29     ` Christian Schoenebeck
2023-12-05 13:09       ` Fedor Pchelkin
2023-12-05 18:05         ` [PATCH v3] " Fedor Pchelkin
2023-12-06 13:12           ` Christian Schoenebeck
2023-12-06 20:09             ` [PATCH v4] " Fedor Pchelkin
2023-12-07 12:54               ` Christian Schoenebeck
2023-12-11 23:21                 ` Dominique Martinet
2024-01-07  7:56                   ` Vitaly Chikunov
2024-01-07  9:48                     ` Fedor Pchelkin
2024-01-07 10:14                       ` Vitaly Chikunov
2024-01-07 10:26                     ` Dominique Martinet
2023-12-11 13:51               ` Simon Horman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.