From: Johannes Stezenbach <js@sig21.net>
To: barebox@lists.infradead.org
Subject: [PATCH 5/5] fs: limit flash erase and protect to the partiton boundary
Date: Wed, 6 Jun 2012 18:05:00 +0200 [thread overview]
Message-ID: <1338998700-23012-6-git-send-email-js@sig21.net> (raw)
In-Reply-To: <1338998700-23012-1-git-send-email-js@sig21.net>
Passing a too large size or offset to erase could
affect flash outside the partition boundary.
Addresses for SPI flash wrap around, thus giving a
count + offset going past the end of the flash would
wrap around and erase flash at offset 0.
Add the same check for protect.
Signed-off-by: Johannes Stezenbach <js@sig21.net>
---
fs/fs.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 9cda1d9..af73c8c 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -751,14 +751,13 @@ int erase(int fd, size_t count, unsigned long offset)
if (check_fd(fd))
return -errno;
+ if (offset >= f->size)
+ return 0;
+ if (count > f->size - offset)
+ count = f->size - offset;
dev = f->dev;
-
fsdrv = dev_to_fs_driver(dev);
-
- if (f->pos + count > f->size)
- count = f->size - f->pos;
-
if (fsdrv->erase)
ret = fsdrv->erase(dev, f, count, offset);
else
@@ -780,14 +779,13 @@ int protect(int fd, size_t count, unsigned long offset, int prot)
if (check_fd(fd))
return -errno;
+ if (offset >= f->size)
+ return 0;
+ if (count > f->size - offset)
+ count = f->size - offset;
dev = f->dev;
-
fsdrv = dev_to_fs_driver(dev);
-
- if (f->pos + count > f->size)
- count = f->size - f->pos;
-
if (fsdrv->protect)
ret = fsdrv->protect(dev, f, count, offset, prot);
else
--
1.7.10
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-06-06 16:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-06 16:04 [PATCH 0/5] minor SPI flash fixes Johannes Stezenbach
2012-06-06 16:04 ` [PATCH 1/5] m25p80: prevent endless loop in erase Johannes Stezenbach
2012-06-06 16:04 ` [PATCH 2/5] m25p80: allow erase to be interrupted Johannes Stezenbach
2012-06-06 16:04 ` [PATCH 3/5] m25p80: progressbar tweak Johannes Stezenbach
2012-06-06 16:04 ` [PATCH 4/5] devfs: don't erase past the end of the partition Johannes Stezenbach
2012-06-06 16:05 ` Johannes Stezenbach [this message]
2012-06-07 17:32 ` [PATCH 0/5] minor SPI flash fixes Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1338998700-23012-6-git-send-email-js@sig21.net \
--to=js@sig21.net \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox