mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] 9p: reject RERROR/RLERROR with zero errcode and guard 0-link drop_nlink()
@ 2026-09-19 22:17 Hui Peng
  0 siblings, 0 replies; only message in thread
From: Hui Peng @ 2026-09-19 22:17 UTC (permalink / raw)
  To: ericvh, lucho, asmadeus, linux_oss; +Cc: v9fs, linux-kernel

Fix two issues in 9p client and VFS inode handling:

1. In p9_check_errors() (net/9p/client.c), a malicious or buggy 9p
   server returning P9_RERROR or P9_RLERROR with ecode == 0 causes
   p9_check_errors() to return 0 (success) while leaving the unparsed
   response payload as if the expected reply message type succeeded. Map
   ecode == 0 on RERROR / RLERROR to -EPROTO.
2. In v9fs_dec_count() (fs/9p/vfs_inode.c), only call drop_nlink() when
   inode->i_nlink > 0 so unlinking an inode whose server-reported nlink
   was already 0 does not underflow i_nlink and trigger
   WARN_ON(inode->i_nlink == 0).

Fixes: bd238fb431f3 ("9p: Reorganization of 9p file system code")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 3829554ca369..12db5ff61554 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -503,7 +503,7 @@ static void v9fs_dec_count(struct inode *inode)
 
 	if (!(v9ses->cache & (CACHE_META | CACHE_LOOSE)))
 		return;
-	if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2)
+	if (S_ISDIR(inode->i_mode) ? inode->i_nlink > 2 : inode->i_nlink > 0)
 		drop_nlink(inode);
 }
 
diff --git a/net/9p/client.c b/net/9p/client.c
index ef64546c6d52..e63e8c2a853d 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -448,6 +448,9 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
 		p9_debug(P9_DEBUG_9P, "<<< RLERROR (%d)\n", -ecode);
 	}
 
+	if (!err)
+		err = -EPROTO;
+
 	return err;
 
 out_err:

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-19 22:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-19 22:17 [PATCH] 9p: reject RERROR/RLERROR with zero errcode and guard 0-link drop_nlink() Hui Peng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®