code: plan9front

Download patch

ref: 865a0f43f10f9df4e61bf235f95de6fd864d8c93
parent: 9bbbc13ce25dab109f640f469d1a633ae5024932
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri May 31 16:50:41 EDT 2024

hjfs: check mount spec (aname) in Tauth

Filesystems should ensure that the mount
spec (aname) is valid before handing out
an auth fid.

This avoids pointless authenticaiton
protocols being run just for the
mount later to fail.

This happens with our current /lib/namespace
file for the opportunistic line:

mount /srv/boot /n/other other

--- a/sys/src/cmd/hjfs/9p.c
+++ b/sys/src/cmd/hjfs/9p.c
@@ -13,8 +13,10 @@
 {
 	if((fsmain->flags & FSNOAUTH) != 0)
 		respond(req, "no authentication required");
-	else
+	else if(*req->ifcall.aname == 0 || strcmp(req->ifcall.aname, "dump") == 0)
 		auth9p(req);
+	else
+		respond(req, Ebadspec);
 }
 
 static void
@@ -30,12 +32,12 @@
 		respond(req, "no such user");
 		return;
 	}
-	if(req->ifcall.aname == nil || *req->ifcall.aname == 0)
+	if(*req->ifcall.aname == 0)
 		flags = 0;
 	else if(strcmp(req->ifcall.aname, "dump") == 0)
 		flags = CHFDUMP|CHFRO;
 	else{
-		respond(req, Einval);
+		respond(req, Ebadspec);
 		return;
 	}
 	ch = chanattach(fsmain, flags);
--- a/sys/src/cmd/hjfs/dat.h
+++ b/sys/src/cmd/hjfs/dat.h
@@ -231,6 +231,7 @@
 extern char Eperm[];
 extern char Eexists[];
 extern char Elocked[];
+extern char Ebadspec[];
 
 enum { /* getblk modes */
 	GBREAD = 0,
--- a/sys/src/cmd/hjfs/main.c
+++ b/sys/src/cmd/hjfs/main.c
@@ -12,6 +12,7 @@
 char Eperm[] = "permission denied";
 char Eexists[] = "file exists";
 char Elocked[] = "file locked";
+char Ebadspec[] = "bad attach specifier";
 
 int mainstacksize = 65536;