* [PATCH] remove invalid reference to list iterator variable
@ 2012-07-08 13:19 Julia Lawall
2012-07-08 13:19 ` [PATCH] fs/ubifs/orphan.c: " Julia Lawall
2012-07-18 13:02 ` [PATCH] " Artem Bityutskiy
0 siblings, 2 replies; 5+ messages in thread
From: Julia Lawall @ 2012-07-08 13:19 UTC (permalink / raw)
To: Artem Bityutskiy; +Cc: linux-mtd, kernel-janitors, Adrian Hunter, linux-kernel
If list_for_each_entry, etc complete a traversal of the list, the iterator
variable ends up pointing to an address at an offset from the list head,
and not a meaningful structure. Thus this value should not be used after
the end of the iterator.
The complete semantic match that finds this problem is:
(http://coccinelle.lip6.fr/)
@@
identifier c,member;
expression E,x;
iterator name list_for_each_entry;
iterator name list_for_each_entry_reverse;
iterator name list_for_each_entry_continue;
iterator name list_for_each_entry_continue_reverse;
iterator name list_for_each_entry_from;
iterator name list_for_each_entry_safe;
iterator name list_for_each_entry_safe_continue;
iterator name list_for_each_entry_safe_from;
iterator name list_for_each_entry_safe_reverse;
iterator name hlist_for_each_entry;
iterator name hlist_for_each_entry_continue;
iterator name hlist_for_each_entry_from;
iterator name hlist_for_each_entry_safe;
statement S;
@@
(
list_for_each_entry(c,...,member) { ... when != break;
when forall
when strict
}
|
list_for_each_entry_reverse(c,...,member) { ... when != break;
when forall
when strict
}
|
list_for_each_entry_continue(c,...,member) { ... when != break;
when forall
when strict
}
|
list_for_each_entry_continue_reverse(c,...,member) { ... when != break;
when forall
when strict
}
|
list_for_each_entry_from(c,...,member) { ... when != break;
when forall
when strict
}
|
list_for_each_entry_safe(c,...,member) { ... when != break;
when forall
when strict
}
|
list_for_each_entry_safe_continue(c,...,member) { ... when != break;
when forall
when strict
}
|
list_for_each_entry_safe_from(c,...,member) { ... when != break;
when forall
when strict
}
|
list_for_each_entry_safe_reverse(c,...,member) { ... when != break;
when forall
when strict
}
)
...
(
list_for_each_entry(c,...) S
|
list_for_each_entry_reverse(c,...) S
|
list_for_each_entry_continue(c,...) S
|
list_for_each_entry_continue_reverse(c,...) S
|
list_for_each_entry_from(c,...) S
|
list_for_each_entry_safe(c,...) S
|
list_for_each_entry_safe(x,c,...) S
|
list_for_each_entry_safe_continue(c,...) S
|
list_for_each_entry_safe_continue(x,c,...) S
|
list_for_each_entry_safe_from(c,...) S
|
list_for_each_entry_safe_from(x,c,...) S
|
list_for_each_entry_safe_reverse(c,...) S
|
list_for_each_entry_safe_reverse(x,c,...) S
|
hlist_for_each_entry(c,...) S
|
hlist_for_each_entry_continue(c,...) S
|
hlist_for_each_entry_from(c,...) S
|
hlist_for_each_entry_safe(c,...) S
|
list_remove_head(x,c,...)
|
sizeof(<+...c...+>)
|
&c->member
|
c = E
|
*c
)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] fs/ubifs/orphan.c: remove invalid reference to list iterator variable
2012-07-08 13:19 [PATCH] remove invalid reference to list iterator variable Julia Lawall
@ 2012-07-08 13:19 ` Julia Lawall
2012-07-09 7:27 ` Julia Lawall
2012-07-18 13:02 ` [PATCH] " Artem Bityutskiy
1 sibling, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2012-07-08 13:19 UTC (permalink / raw)
To: Artem Bityutskiy; +Cc: linux-mtd, kernel-janitors, Adrian Hunter, linux-kernel
From: Julia Lawall <Julia.Lawall@lip6.fr>
If list_for_each_entry, etc complete a traversal of the list, the iterator
variable ends up pointing to an address at an offset from the list head,
and not a meaningful structure. Thus this value should not be used after
the end of the iterator. Replace a field access from orphan by NULL.
A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
identifier c;
expression E;
iterator name list_for_each_entry;
statement S;
@@
list_for_each_entry(c,...) { ... when != break;
when forall
when strict
}
...
(
c = E
|
*c
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
---
fs/ubifs/orphan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c
index b02734d..4b7860a 100644
--- a/fs/ubifs/orphan.c
+++ b/fs/ubifs/orphan.c
@@ -176,7 +176,7 @@ int ubifs_orphan_start_commit(struct ubifs_info *c)
*last = orphan;
last = &orphan->cnext;
}
- *last = orphan->cnext;
+ *last = NULL;
c->cmt_orphans = c->new_orphans;
c->new_orphans = 0;
dbg_cmt("%d orphans to commit", c->cmt_orphans);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] fs/ubifs/orphan.c: remove invalid reference to list iterator variable
2012-07-08 13:19 ` [PATCH] fs/ubifs/orphan.c: " Julia Lawall
@ 2012-07-09 7:27 ` Julia Lawall
2012-07-18 15:58 ` Artem Bityutskiy
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2012-07-09 7:27 UTC (permalink / raw)
To: Artem Bityutskiy; +Cc: linux-mtd, kernel-janitors, Adrian Hunter, linux-kernel
From: Julia Lawall <Julia.Lawall@lip6.fr>
If list_for_each_entry, etc complete a traversal of the list, the iterator
variable ends up pointing to an address at an offset from the list head,
and not a meaningful structure. Thus this value should not be used after
the end of the iterator. Replace a field access from orphan by NULL in two
places.
A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
identifier c;
expression E;
iterator name list_for_each_entry;
statement S;
@@
list_for_each_entry(c,...) { ... when != break;
when forall
when strict
}
...
(
c = E
|
*c
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
---
fs/ubifs/orphan.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c
index b02734d..cebf17e 100644
--- a/fs/ubifs/orphan.c
+++ b/fs/ubifs/orphan.c
@@ -176,7 +176,7 @@ int ubifs_orphan_start_commit(struct ubifs_info *c)
*last = orphan;
last = &orphan->cnext;
}
- *last = orphan->cnext;
+ *last = NULL;
c->cmt_orphans = c->new_orphans;
c->new_orphans = 0;
dbg_cmt("%d orphans to commit", c->cmt_orphans);
@@ -382,7 +382,7 @@ static int consolidate(struct ubifs_info *c)
last = &orphan->cnext;
cnt += 1;
}
- *last = orphan->cnext;
+ *last = NULL;
ubifs_assert(cnt = c->tot_orphans - c->new_orphans);
c->cmt_orphans = cnt;
c->ohead_lnum = c->orph_first;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] remove invalid reference to list iterator variable
2012-07-08 13:19 [PATCH] remove invalid reference to list iterator variable Julia Lawall
2012-07-08 13:19 ` [PATCH] fs/ubifs/orphan.c: " Julia Lawall
@ 2012-07-18 13:02 ` Artem Bityutskiy
1 sibling, 0 replies; 5+ messages in thread
From: Artem Bityutskiy @ 2012-07-18 13:02 UTC (permalink / raw)
To: Julia Lawall; +Cc: linux-mtd, kernel-janitors, Adrian Hunter, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 398 bytes --]
On Sun, 2012-07-08 at 15:19 +0200, Julia Lawall wrote:
> If list_for_each_entry, etc complete a traversal of the list, the iterator
> variable ends up pointing to an address at an offset from the list head,
> and not a meaningful structure. Thus this value should not be used after
> the end of the iterator.
Thanks Julia - this one is very useful!
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] fs/ubifs/orphan.c: remove invalid reference to list iterator variable
2012-07-09 7:27 ` Julia Lawall
@ 2012-07-18 15:58 ` Artem Bityutskiy
0 siblings, 0 replies; 5+ messages in thread
From: Artem Bityutskiy @ 2012-07-18 15:58 UTC (permalink / raw)
To: Julia Lawall; +Cc: linux-mtd, kernel-janitors, Adrian Hunter, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 504 bytes --]
On Mon, 2012-07-09 at 09:27 +0200, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
>
> If list_for_each_entry, etc complete a traversal of the list, the iterator
> variable ends up pointing to an address at an offset from the list head,
> and not a meaningful structure. Thus this value should not be used after
> the end of the iterator. Replace a field access from orphan by NULL in two
> places.
Pushed to linux-ubifs.git, thanks!
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-07-18 15:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-08 13:19 [PATCH] remove invalid reference to list iterator variable Julia Lawall
2012-07-08 13:19 ` [PATCH] fs/ubifs/orphan.c: " Julia Lawall
2012-07-09 7:27 ` Julia Lawall
2012-07-18 15:58 ` Artem Bityutskiy
2012-07-18 13:02 ` [PATCH] " Artem Bityutskiy
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).