All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH 1/2] gfs2_edit: Don't hijack bh->b_data in read_master_dir
@ 2016-04-05 14:03 Andrew Price
  2016-04-05 14:03 ` [Cluster-devel] [PATCH 2/2] mkfs.gfs2: Open the target device with O_EXCL Andrew Price
  2016-04-05 17:11 ` [Cluster-devel] [PATCH 1/2] gfs2_edit: Don't hijack bh->b_data in read_master_dir Bob Peterson
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew Price @ 2016-04-05 14:03 UTC (permalink / raw)
  To: cluster-devel.redhat.com

read_master_dir() reads data that doesn't match the bh's metadata into
bh->b_data, which confuses display() later when it checks whether
re-reading the block is required. Use bread() in read_master_dir()
instead to keep the bh consistent, and make sure read_superblock()
doesn't leak the buffer earlier.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/edit/hexedit.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 1fea017..2ce111d 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -943,9 +943,6 @@ static int block_has_extended_info(void)
 	return FALSE;
 }
 
-/* ------------------------------------------------------------------------ */
-/* read_superblock - read the superblock                                    */
-/* ------------------------------------------------------------------------ */
 static void read_superblock(int fd)
 {
 	sbd1 = (struct gfs_sb *)&sbd.sd_sb;
@@ -1013,6 +1010,8 @@ static void read_superblock(int fd)
 			gfs2_lookupi(sbd.master_dir, "rindex", 6, &sbd.md.riinode);
 		}
 	}
+	brelse(bh);
+	bh = NULL;
 }
 
 static int read_rindex(void)
@@ -1032,26 +1031,17 @@ static int read_rindex(void)
 	return 0;
 }
 
-/* ------------------------------------------------------------------------ */
-/* read_master_dir - read the master directory                              */
-/* ------------------------------------------------------------------------ */
-static void read_master_dir(void)
+static int read_master_dir(void)
 {
 	ioctl(sbd.device_fd, BLKFLSBUF, 0);
-	lseek(sbd.device_fd, sbd.sd_sb.sb_master_dir.no_addr * sbd.bsize,
-	      SEEK_SET);
-	if (read(sbd.device_fd, bh->b_data, sbd.bsize) != sbd.bsize) {
-		fprintf(stderr, "read error: %s from %s:%d: "
-			"master dir block %lld (0x%llx)\n",
-			strerror(errno), __FUNCTION__,
-			__LINE__,
-			(unsigned long long)sbd.sd_sb.sb_master_dir.no_addr,
-			(unsigned long long)sbd.sd_sb.sb_master_dir.no_addr);
-		exit(-1);
-	}
+
+	bh = bread(&sbd, sbd.sd_sb.sb_master_dir.no_addr);
+	if (bh == NULL)
+		return 1;
 	gfs2_dinode_in(&di, bh); /* parse disk inode into structure */
 	do_dinode_extended(&di, bh); /* get extended data, if any */
 	memcpy(&masterdir, &indirect[0], sizeof(struct indirect_info));
+	return 0;
 }
 
 int display(int identify_only, int trunc_zeros, uint64_t flagref,
@@ -2535,8 +2525,8 @@ int main(int argc, char *argv[])
 	max_block = lseek(fd, 0, SEEK_END) / sbd.bsize;
 	if (sbd.gfs1)
 		edit_row[GFS2_MODE]++;
-	else
-		read_master_dir();
+	else if (read_master_dir() != 0)
+		exit(-1);
 
 	process_parameters(argc, argv, 1); /* get what to print from cmdline */
 
-- 
2.4.11



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-04-05 17:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-05 14:03 [Cluster-devel] [PATCH 1/2] gfs2_edit: Don't hijack bh->b_data in read_master_dir Andrew Price
2016-04-05 14:03 ` [Cluster-devel] [PATCH 2/2] mkfs.gfs2: Open the target device with O_EXCL Andrew Price
2016-04-05 14:14   ` Bob Peterson
2016-04-05 14:37     ` Andrew Price
2016-04-05 17:09       ` Bob Peterson
2016-04-05 17:11 ` [Cluster-devel] [PATCH 1/2] gfs2_edit: Don't hijack bh->b_data in read_master_dir Bob Peterson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.