From: <chengzhihao1@huawei.com>
To: <david.oberhollenzer@sigma-star.at>, <richard@nod.at>,
<boris.brezillon@bootlin.com>, <david@sigma-star.at>,
<artem.bityutskiy@linux.intel.com>, <yi.zhang@huawei.com>
Cc: <linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
<chengzhihao1@huawei.com>
Subject: [PATCH mtd-utils] ubi-tests: io_read: Filter invalid offset value before 'lseek' in io_read test
Date: Fri, 14 Jun 2019 20:18:16 +0800 [thread overview]
Message-ID: <1560514696-54824-1-git-send-email-chengzhihao1@huawei.com> (raw)
From: Zhihao Cheng <chengzhihao1@huawei.com>
There are many different offset values passed in 'lseek' during io_read
testing of ubi test. The offset value maybe a negative number or a big
number that exceeds the volume data size, which can lead to ubi tests
failure by passing invalid offset value to 'lseek'. For example:
Example 1: The data size of volume is 39525 bytes, offset = (sz) -
MAX_NAND_PAGE_SIZE - 1, where MAX_NAND_PAGE_SIZE is 65536. Here, offset
is a negative value passed to 'lseek', which leads to fail in io_read.
======================================================================
======================================================================
======================================================================
Test on mtdram, fastmap enabled, VID header offset factor 1
======================================================================
======================================================================
======================================================================
mtdram: 16MiB, PEB size 16KiB, fastmap enabled
Running mkvol_basic /dev/ubi0
Running mkvol_bad /dev/ubi0
Running mkvol_paral /dev/ubi0
Running rsvol /dev/ubi0
Running io_basic /dev/ubi0
Running io_read /dev/ubi0
[io_basic] test_read3():189: function seek() failed with error 22
(Invalid argument)
[io_basic] test_read3():190: len = 1
[io_basic] test_read2():237: offset = -26012
[io_basic] test_read1():303: length = 1
[io_basic] test_read():362: alignment = 7905
Error: io_read failed
FAILURE
Example 2: The data size of volume is 79035 bytes, offset = 2 *
MAX_NAND_PAGE_SIZE, where MAX_NAND_PAGE_SIZE is 65536. Here, offset is a
value exceeds volume size, which leads to fail in io_read.
======================================================================
======================================================================
======================================================================
Test on mtdram, fastmap enabled, VID header offset factor 1
======================================================================
======================================================================
======================================================================
mtdram: 16MiB, PEB size 16KiB, fastmap enabled
Running mkvol_basic /dev/ubi0
Running mkvol_bad /dev/ubi0
Running mkvol_paral /dev/ubi0
Running rsvol /dev/ubi0
Running io_basic /dev/ubi0
Running io_read /dev/ubi0
[io_basic] test_read3():185: function seek() failed with error 22
(Invalid argument)
[io_basic] test_read3():186: len = 1
[io_basic] test_read2():233: offset = 131072
[io_basic] test_read1():299: length = 1
[io_basic] test_read():358: alignment = 3
Error: io_read failed
FAILURE
This patch checks offset value before executing 'lseek', invalid offset
values are filtered.
----------------------------------------
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
tests/ubi-tests/io_read.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/ubi-tests/io_read.c b/tests/ubi-tests/io_read.c
index 3100ef1..f944a86 100644
--- a/tests/ubi-tests/io_read.c
+++ b/tests/ubi-tests/io_read.c
@@ -228,6 +228,10 @@ static int test_read2(const struct ubi_vol_info *vol_info, int len)
vol_info->data_bytes);
for (i = 0; i < sizeof(offsets)/sizeof(off_t); i++) {
+ /* Filter invalid offset value */
+ if (offsets[i] < 0 || offsets[i] > vol_info->data_bytes)
+ continue;
+
if (test_read3(vol_info, len, offsets[i])) {
errorm("offset = %d", offsets[i]);
return -1;
--
2.7.4
next reply other threads:[~2019-06-14 12:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-14 12:18 chengzhihao1 [this message]
2019-06-17 7:03 ` [PATCH mtd-utils] ubi-tests: io_read: Filter invalid offset value before 'lseek' in io_read test David Oberhollenzer
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=1560514696-54824-1-git-send-email-chengzhihao1@huawei.com \
--to=chengzhihao1@huawei.com \
--cc=artem.bityutskiy@linux.intel.com \
--cc=boris.brezillon@bootlin.com \
--cc=david.oberhollenzer@sigma-star.at \
--cc=david@sigma-star.at \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=yi.zhang@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).