Skip to contentSkip to conversation

9p: change an int to unsigned int

PATCH In review Dan Carpenter 3 participants 3 messages Aug 26, 2011 – Sep 7, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 9p: change an int to unsigned int

The size of things should be unsigned because negative sizes are silly. My concern is the the limit checks don't take negative values into consideration in p9_client_create()

	if (clnt->msize > clnt->trans_mod->maxsize)
		clnt->msize = clnt->trans_mod->maxsize;
and in p9_tag_alloc()
	int alloc_msize = min(c->msize, max_size);

I don't know if this is exported to user space? Hopefully it's not too late to change this.

include/net/9p/client.h +1 -1
index 55ce72c..d479d7d 100644
@@ -151,7 +151,7 @@ struct p9_req_t {
 
 struct p9_client {
 	spinlock_t lock; /* protect client structure */
-	int msize;
+	unsigned int msize;
 	unsigned char proto_version;
 	struct p9_trans_module *trans_mod;
 	enum p9_trans_status status;
#1 lore raw
Quoted 10 lines · Dan Carpenter

The size of things should be unsigned because negative sizes are silly. My concern is the the limit checks don't take negative values into consideration in p9_client_create()

	if (clnt->msize > clnt->trans_mod->maxsize)
		clnt->msize = clnt->trans_mod->maxsize;
and in p9_tag_alloc()
	int alloc_msize = min(c->msize, max_size);

I don't know if this is exported to user space? Hopefully it's not too late to change this.

The change is also needed to make sure large msize value (429496729) works Without the change it cause a server crash with Qemu 9p server.

Quoted 8 lines
include/net/9p/client.h +0 -0
index 55ce72c..d479d7d 100644

include/net/9p/client.h struct p9_req_t { · line 157

Quoted 8 lines
include/net/9p/client.h +1 -1
@@ -151,7 +151,7 @@ struct p9_req_t {
 
 struct p9_client {
 	spinlock_t lock; /* protect client structure */
-	int msize;
+	unsigned int msize;
 	unsigned char proto_version;
 	struct p9_trans_module *trans_mod;
 	enum p9_trans_status status;

I applied this with comment update to
git://git.kernel.org/pub/scm/linux/kernel/git/kvaneesh/v9fs.git for-upstream-next-merge

-aneesh

Reviewed-by on v1 2/2
#2 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Dan Carpenter

The size of things should be unsigned because negative sizes are silly. My concern is the the limit checks don't take negative values into consideration in p9_client_create()

	if (clnt->msize>  clnt->trans_mod->maxsize)
		clnt->msize = clnt->trans_mod->maxsize;
and in p9_tag_alloc()
	int alloc_msize = min(c->msize, max_size);

I don't know if this is exported to user space? Hopefully it's not too late to change this.

It is not exported to user space but the other way is true;
msize can be populate from mount option. It should be fine.

Quoted 2 lines
Quoted 14 lines
include/net/9p/client.h +1 -1
index 55ce72c..d479d7d 100644
@@ -151,7 +151,7 @@ struct p9_req_t {
 
  struct p9_client {
  	spinlock_t lock; /* protect client structure */
-	int msize;
+	unsigned int msize;
  	unsigned char proto_version;
  	struct p9_trans_module *trans_mod;
  	enum p9_trans_status status;