Skip to contentSkip to conversation

module: static checker complains about negative values

PATCH In review Dan Carpenter 2 participants 3 messages May 19, 2014 – May 20, 2014 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 module: static checker complains about negative values

We cap "stat.size" at INT_MAX but we don't check for negative values so my static checker complains. At this point, you already have control of the kernel and if you start passing negative values here then you deserve what happens next.

On 64 bit systems the vmalloc() will definitely fail. On 32 bit systems we truncate the upper 32 bits away so that could succeed. I haven't followed it further than that.

kernel/module.c +1 -1
index 626d164..26e0d15 100644
@@ -2536,7 +2536,7 @@ static int copy_module_from_fd(int fd, struct load_info *info)
 	}
 
 	/* Don't hand 0 to vmalloc, it whines. */
-	if (stat.size = 0) {
+	if (stat.size <= 0) {
 		err = -EINVAL;
 		goto out;
 	}
#1 lore raw
Quoted 10 lines · Dan Carpenter

We cap "stat.size" at INT_MAX but we don't check for negative values so my static checker complains. At this point, you already have control of the kernel and if you start passing negative values here then you deserve what happens next.

On 64 bit systems the vmalloc() will definitely fail. On 32 bit systems we truncate the upper 32 bits away so that could succeed. I haven't followed it further than that.

If vfs_getattr() returns a negative stat.size, we have worse problems.

I'd rather see you sprinkle assertions like that into the code, so we can make sure that can't happen for any fs's getattr().

Cheers,
Rusty.

#2 lore raw
Quoted 11 lines · Rusty Russell
Quoted 9 lines · Dan Carpenter

We cap "stat.size" at INT_MAX but we don't check for negative values so my static checker complains. At this point, you already have control of the kernel and if you start passing negative values here then you deserve what happens next.

On 64 bit systems the vmalloc() will definitely fail. On 32 bit systems we truncate the upper 32 bits away so that could succeed. I haven't followed it further than that.

Quoted 6 lines
Quoted 1 line

If vfs_getattr() returns a negative stat.size, we have worse problems.

I'd rather see you sprinkle assertions like that into the code, so we can make sure that can't happen for any fs's getattr().

Yeah. I was lazy. Sorry. I can just hand edit my database to say that i_size_read() returns a reasonable number...

regards,
dan carpenter