Skip to contentSkip to conversation

UBIFS: fix assertion in layout_in_gaps()

PATCH In review Vincent Stehlé 3 participants 4 messages Aug 12, 2016 – Aug 16, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 UBIFS: fix assertion in layout_in_gaps()

An assertion in layout_in_gaps() verifies that the gap_lebs pointer is below the maximum bound. When computing this maximum bound the idx_lebs count is multiplied by sizeof(int), while C pointers arithmetic does take into account the size of the pointed elements implicitly already. Remove the multiplication to fix the assertion.

Fixes 1e51764a3c2ac05a ("UBIFS: add new flash file system")
Cc Artem Bityutskiy <[email protected]>
---
 fs/ubifs/tnc_commit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ubifs/tnc_commit.c +1 -1
index b45345d..51157da 100644
@@ -370,7 +370,7 @@ static int layout_in_gaps(struct ubifs_info *c, int cnt)
 
 	p = c->gap_lebs;
 	do {
-		ubifs_assert(p < c->gap_lebs + sizeof(int) * c->lst.idx_lebs);
+		ubifs_assert(p < c->gap_lebs + c->lst.idx_lebs);
 		written = layout_leb_in_gaps(c, p);
 		if (written < 0) {
 			err = written;
Signature · 1 line
2.8.1
#1 lore raw
Quoted 10 lines · Vincent Stehlé

An assertion in layout_in_gaps() verifies that the gap_lebs pointer is
below the maximum bound. When computing this maximum bound the idx_lebs
count is multiplied by sizeof(int), while C pointers arithmetic does take
into account the size of the pointed elements implicitly already. Remove
the multiplication to fix the assertion.

Quoted 3 lines
Fixes 1e51764a3c2ac05a ("UBIFS: add new flash file system")
Cc Artem Bityutskiy <[email protected]>

Thanks!

--
Best Regards,
Artem Bityutskiy

#2 lore raw
In reply to Vincent Stehlé

Vincent,

Quoted 18 lines · Vincent Stehlé

An assertion in layout_in_gaps() verifies that the gap_lebs pointer is below the maximum bound. When computing this maximum bound the idx_lebs count is multiplied by sizeof(int), while C pointers arithmetic does take into account the size of the pointed elements implicitly already. Remove the multiplication to fix the assertion.

Fixes 1e51764a3c2ac05a ("UBIFS: add new flash file system")
Cc Artem Bityutskiy <[email protected]>
---
 fs/ubifs/tnc_commit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ubifs/tnc_commit.c +0 -0
index b45345d..51157da 100644

fs/ubifs/tnc_commit.c static int layout_in_gaps(struct ubifs_info *c, int cnt) · line 373

Quoted 5 lines
fs/ubifs/tnc_commit.c +1 -1
@@ -370,7 +370,7 @@ static int layout_in_gaps(struct ubifs_info *c, int cnt)
 
        p = c->gap_lebs;
        do {
-               ubifs_assert(p < c->gap_lebs + sizeof(int) * c->lst.idx_lebs);
+               ubifs_assert(p < c->gap_lebs + c->lst.idx_lebs);

Good catch! Did you hit this assertion or was it found by review? I bet the latter since it is here since ever and given the wrongness it is unlikely to trigger.

Signature · 2 lines
Thanks,
//richard
#3 lore raw

On Sun, Aug 14, 2016 at 11:00:33AM +0200, Richard Weinberger wrote:
..

Quoted 3 lines

Good catch! Did you hit this assertion or was it found by review? I bet the latter since it is here since ever and given the wrongness it is unlikely to trigger.

Dear Richard,

It was found with a static checker and later review to confirm.

Best regards,

Vincent.