grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* Add check when store disk cache
@ 2015-09-18  0:15 Arch Stack
  2015-09-18  4:03 ` Andrei Borzenkov
  0 siblings, 1 reply; 5+ messages in thread
From: Arch Stack @ 2015-09-18  0:15 UTC (permalink / raw)
  To: grub-devel


[-- Attachment #1.1: Type: text/plain, Size: 294 bytes --]

I found that the function *grub_disk_cache_store* didn't check for
*cache->lock* before free *cache->data*, and didn't set *cache->lock*
before memcpy something to *cache->data*. If multi thread handle with the
same cache at the same time, it will cause a fault. I have created a patch
for it.

[-- Attachment #1.2: Type: text/html, Size: 365 bytes --]

[-- Attachment #2: 0001-Add-check-when-store-disk-cache.patch --]
[-- Type: application/octet-stream, Size: 1112 bytes --]

From b31c94a60c841f61572c7f27afda1f688573f4c2 Mon Sep 17 00:00:00 2001
From: ArchStacker <ArchStacker@gmail.com>
Date: Thu, 17 Sep 2015 11:19:53 +0800
Subject: [PATCH] Add check when store disk cache

---
 grub-core/kern/disk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c
index 789f8c0..acd0894 100644
--- a/grub-core/kern/disk.c
+++ b/grub-core/kern/disk.c
@@ -124,10 +124,12 @@ grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id,
   cache_index = grub_disk_cache_get_index (dev_id, disk_id, sector);
   cache = grub_disk_cache_table + cache_index;
 
+  if(cache->lock)
+    return GRUB_ERR_NONE;
+
   cache->lock = 1;
   grub_free (cache->data);
   cache->data = 0;
-  cache->lock = 0;
 
   cache->data = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
   if (! cache->data)
@@ -138,6 +140,7 @@ grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id,
   cache->dev_id = dev_id;
   cache->disk_id = disk_id;
   cache->sector = sector;
+  cache->lock = 0;
 
   return GRUB_ERR_NONE;
 }
-- 
2.4.3


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

end of thread, other threads:[~2015-10-13 22:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-18  0:15 Add check when store disk cache Arch Stack
2015-09-18  4:03 ` Andrei Borzenkov
2015-09-18  9:07   ` Arch Stack
2015-09-19  7:00     ` Andrei Borzenkov
2015-10-13 22:55       ` Vladimir 'φ-coder/phcoder' Serbinenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).