Skip to contentSkip to conversation

ROMFS: romfs_lookup() shouldn't be doing a partial name comparison

PATCH New David Howells 1 participant 2 messages Apr 23, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ROMFS: romfs_lookup() shouldn't be doing a partial name comparison

romfs_lookup() should be using a routine akin to strcmp() on the backing store, rather than one akin to strncmp(). If it uses the latter, it's liable to match /bin/shutdown when looking up /bin/sh.

---

 fs/romfs/internal.h |    4 ++-
 fs/romfs/storage.c  |   67 +++++++++++++++++++++++++++++++++++++--------------
 fs/romfs/super.c    |    4 ++-
 3 files changed, 53 insertions(+), 22 deletions(-)
fs/romfs/internal.h +2 -2
index 06044a9..95217b8 100644
@@ -43,5 +43,5 @@ extern int romfs_dev_read(struct super_block *sb, unsigned long pos,
 			  void *buf, size_t buflen);
 extern ssize_t romfs_dev_strnlen(struct super_block *sb,
 				 unsigned long pos, size_t maxlen);
-extern int romfs_dev_strncmp(struct super_block *sb, unsigned long pos,
-			     const char *str, size_t size);
+extern int romfs_dev_strcmp(struct super_block *sb, unsigned long pos,
+			    const char *str, size_t size);
fs/romfs/storage.c +49 -18

129 lines not on this page · raw message

fs/romfs/super.c +2 -2
index 10ca7d9..c53b5ef 100644
@@ -240,8 +240,8 @@ static struct dentry *romfs_lookup(struct inode *dir, struct dentry *dentry,
 			goto error;
 
 		/* try to match the first 16 bytes of name */
-		ret = romfs_dev_strncmp(dir->i_sb, offset + ROMFH_SIZE, name,
-					len);
+		ret = romfs_dev_strcmp(dir->i_sb, offset + ROMFH_SIZE, name,
+				       len);
 		if (ret < 0)
 			goto error;
 		if (ret == 1)
#1 lore raw

PATCH 2/2 ROMFS: Advance destination buffer pointer when reading from a blockdev

RomFS should advance the destination buffer pointer when reading data from a blockdev source (the data may be split over multiple blocks, each requiring its own sb_read() call). Without this, all the data is copied to the beginning of the output buffer.

---

 fs/romfs/storage.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
fs/romfs/storage.c +1 -0
index 66ce9dd..b3208ad 100644
@@ -120,6 +120,7 @@ static int romfs_blk_read(struct super_block *sb, unsigned long pos,
 			return -EIO;
 		memcpy(buf, bh->b_data + offset, segment);
 		brelse(bh);
+		buf += segment;
 		buflen -= segment;
 		pos += segment;
 	}