Blame SOURCES/0318-grub-core-disk-efi-efidisk.c-Limit-disk-read-or-writ.patch

f96e0b
From f63be03880f3667f2fb75acaa02f633e265e01e5 Mon Sep 17 00:00:00 2001
f96e0b
From: Peter Jones <pjones@redhat.com>
f96e0b
Date: Mon, 15 Apr 2013 09:12:14 +0200
f96e0b
Subject: [PATCH 318/482] 	* grub-core/disk/efi/efidisk.c: Limit disk
f96e0b
 read or write chunk to 0x500 	sectors. 	Based on patch by Peter Jones.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                    |  7 +++++++
f96e0b
 grub-core/disk/efi/efidisk.c | 50 +++++++++++++++++++++++++++++---------------
f96e0b
 2 files changed, 40 insertions(+), 17 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 2dcf1f5..6f33ff1 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,4 +1,11 @@
f96e0b
 2013-04-15  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+2013-04-15  Peter Jones <pjones@redhat.com>
f96e0b
+
f96e0b
+	* grub-core/disk/efi/efidisk.c: Limit disk read or write chunk to 0x500
f96e0b
+	sectors.
f96e0b
+	Based on patch by Peter Jones.
f96e0b
+
f96e0b
+2013-04-15  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
 	Fix DMRAID partition handling.
f96e0b
 
f96e0b
diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c
f96e0b
index 28b9fa1..5a6fc63 100644
f96e0b
--- a/grub-core/disk/efi/efidisk.c
f96e0b
+++ b/grub-core/disk/efi/efidisk.c
f96e0b
@@ -528,9 +528,9 @@ grub_efidisk_close (struct grub_disk *disk __attribute__ ((unused)))
f96e0b
   grub_dprintf ("efidisk", "closing %s\n", disk->name);
f96e0b
 }
f96e0b
 
f96e0b
-static grub_err_t
f96e0b
-grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
f96e0b
-		   grub_size_t size, char *buf)
f96e0b
+static grub_efi_status_t
f96e0b
+grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector,
f96e0b
+			grub_size_t size, char *buf, int wr)
f96e0b
 {
f96e0b
   /* For now, use the disk io interface rather than the block io's.  */
f96e0b
   struct grub_efidisk_data *d;
f96e0b
@@ -540,14 +540,38 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
f96e0b
   d = disk->data;
f96e0b
   bio = d->block_io;
f96e0b
 
f96e0b
+  while (size > 0)
f96e0b
+    {
f96e0b
+      grub_size_t len;
f96e0b
+      len = 0x500;
f96e0b
+      if (len > size)
f96e0b
+	len = size;
f96e0b
+      status = efi_call_5 ((wr ? bio->write_blocks : bio->read_blocks), bio,
f96e0b
+			   bio->media->media_id,
f96e0b
+			   (grub_efi_uint64_t) sector,
f96e0b
+			   (grub_efi_uintn_t) size << disk->log_sector_size,
f96e0b
+			   buf);
f96e0b
+      size -= len;
f96e0b
+      buf += len << disk->log_sector_size;
f96e0b
+      sector += len;
f96e0b
+      if (status != GRUB_EFI_SUCCESS)
f96e0b
+	return status;
f96e0b
+    }
f96e0b
+  return GRUB_EFI_SUCCESS;
f96e0b
+}
f96e0b
+
f96e0b
+static grub_err_t
f96e0b
+grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
f96e0b
+		   grub_size_t size, char *buf)
f96e0b
+{
f96e0b
+  grub_efi_status_t status;
f96e0b
+
f96e0b
   grub_dprintf ("efidisk",
f96e0b
 		"reading 0x%lx sectors at the sector 0x%llx from %s\n",
f96e0b
 		(unsigned long) size, (unsigned long long) sector, disk->name);
f96e0b
 
f96e0b
-  status = efi_call_5 (bio->read_blocks, bio, bio->media->media_id,
f96e0b
-		       (grub_efi_uint64_t) sector,
f96e0b
-		       (grub_efi_uintn_t) size << disk->log_sector_size,
f96e0b
-		       buf);
f96e0b
+  status = grub_efidisk_readwrite (disk, sector, size, buf, 0);
f96e0b
+
f96e0b
   if (status != GRUB_EFI_SUCCESS)
f96e0b
     return grub_error (GRUB_ERR_READ_ERROR,
f96e0b
 		       N_("failure reading sector 0x%llx from `%s'"),
f96e0b
@@ -561,22 +585,14 @@ static grub_err_t
f96e0b
 grub_efidisk_write (struct grub_disk *disk, grub_disk_addr_t sector,
f96e0b
 		    grub_size_t size, const char *buf)
f96e0b
 {
f96e0b
-  /* For now, use the disk io interface rather than the block io's.  */
f96e0b
-  struct grub_efidisk_data *d;
f96e0b
-  grub_efi_block_io_t *bio;
f96e0b
   grub_efi_status_t status;
f96e0b
 
f96e0b
-  d = disk->data;
f96e0b
-  bio = d->block_io;
f96e0b
-
f96e0b
   grub_dprintf ("efidisk",
f96e0b
 		"writing 0x%lx sectors at the sector 0x%llx to %s\n",
f96e0b
 		(unsigned long) size, (unsigned long long) sector, disk->name);
f96e0b
 
f96e0b
-  status = efi_call_5 (bio->write_blocks, bio, bio->media->media_id,
f96e0b
-		       (grub_efi_uint64_t) sector,
f96e0b
-		       (grub_efi_uintn_t) size << disk->log_sector_size,
f96e0b
-		       (void *) buf);
f96e0b
+  status = grub_efidisk_readwrite (disk, sector, size, (char *) buf, 1);
f96e0b
+
f96e0b
   if (status != GRUB_EFI_SUCCESS)
f96e0b
     return grub_error (GRUB_ERR_WRITE_ERROR,
f96e0b
 		       N_("failure writing sector 0x%llx to `%s'"),
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b