Skip to contentSkip to conversation

minix: bug widening a binary "not" operation

PATCH In review Dan Carpenter 2 participants 3 messages May 16, 2013 – May 30, 2013 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 minix: bug widening a binary "not" operation

"chunk_size" is an unsigned int and "pos" is an unsigned long. The "& ~(chunk_size-1)" operation clears the high 32 bits unintentionally.

The ALIGN() macro does the correct thing.

fs/minix/dir.c +1 -1
index a9ed6f3..09b0c96 100644
@@ -95,7 +95,7 @@ static int minix_readdir(struct file * filp, void * dirent, filldir_t filldir)
 	char *name;
 	__u32 inumber;
 
-	pos = (pos + chunk_size-1) & ~(chunk_size-1);
+	pos = ALIGN(pos, chunk_size);
 	if (pos >= inode->i_size)
 		goto done;
 
#1 lore raw
Quoted 8 lines · On Thu, 16 May 2013 10:51:49 +0300 Dan Carpenter <[email protected]>…

"chunk_size" is an unsigned int and "pos" is an unsigned long. The "& ~(chunk_size-1)" operation clears the high 32 bits unintentionally.

The ALIGN() macro does the correct thing.

...

fs/minix/dir.c static int minix_readdir(struct file * filp, void * dirent, filldir_t filldir) · line 101

Quoted 8 lines
fs/minix/dir.c +1 -1
@@ -95,7 +95,7 @@ static int minix_readdir(struct file * filp, void * dirent, filldir_t filldir)
 	char *name;
 	__u32 inumber;
 
-	pos = (pos + chunk_size-1) & ~(chunk_size-1);
+	pos = ALIGN(pos, chunk_size);
 	if (pos >= inode->i_size)
 		goto done;
 

I'm suspecting there aren't many minix filesystems out there with a >4G directory ;)

But we should fix it to set a good example, and to quieten whatever-tool-i-suspect-you-were-using(?).

#2 lore raw
Quoted 2 lines · Andrew Morton

But we should fix it to set a good example, and to quieten whatever-tool-i-suspect-you-were-using(?).

Linus wrote some Sparse patches that check for this but they haven't been merged yet.

regards,
dan carpenter