netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: fix possible uninitialized access in inactive rotation
@ 2016-11-16 14:38 Arnd Bergmann
  2016-11-16 16:00 ` Daniel Borkmann
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2016-11-16 14:38 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Arnd Bergmann, Martin KaFai Lau, David S. Miller, netdev,
	linux-kernel

This newly added code causes a build warning:

kernel/bpf/bpf_lru_list.c: In function '__bpf_lru_list_rotate_inactive':
kernel/bpf/bpf_lru_list.c:201:28: error: 'next' may be used uninitialized in this function [-Werror=maybe-uninitialized]

The warning is plausible from looking at the code, though there might
be non-obvious external constraints that ensure it always works.

Moving the assignment of ->next_inactive_rotation inside of the
loop makes it obvious to the reader and the compiler when we
actually want to update ->next.

Fixes: 3a08c2fd7634 ("bpf: LRU List")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 kernel/bpf/bpf_lru_list.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/bpf_lru_list.c b/kernel/bpf/bpf_lru_list.c
index bfebff010ba9..f462e5f09703 100644
--- a/kernel/bpf/bpf_lru_list.c
+++ b/kernel/bpf/bpf_lru_list.c
@@ -192,13 +192,14 @@ static void __bpf_lru_list_rotate_inactive(struct bpf_lru *lru,
 		next = cur->prev;
 		if (bpf_lru_node_is_ref(node))
 			__bpf_lru_node_move(l, node, BPF_LRU_LIST_T_ACTIVE);
-		if (cur == last)
+		if (cur == last) {
+			l->next_inactive_rotation = next;
 			break;
+		}
 		cur = next;
 		i++;
 	}
 
-	l->next_inactive_rotation = next;
 }
 
 /* Shrink the inactive list.  It starts from the tail of the
-- 
2.9.0

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

* Re: [PATCH] bpf: fix possible uninitialized access in inactive rotation
  2016-11-16 14:38 [PATCH] bpf: fix possible uninitialized access in inactive rotation Arnd Bergmann
@ 2016-11-16 16:00 ` Daniel Borkmann
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2016-11-16 16:00 UTC (permalink / raw)
  To: Arnd Bergmann, Alexei Starovoitov
  Cc: Martin KaFai Lau, David S. Miller, netdev, linux-kernel

On 11/16/2016 03:38 PM, Arnd Bergmann wrote:
> This newly added code causes a build warning:
>
> kernel/bpf/bpf_lru_list.c: In function '__bpf_lru_list_rotate_inactive':
> kernel/bpf/bpf_lru_list.c:201:28: error: 'next' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> The warning is plausible from looking at the code, though there might
> be non-obvious external constraints that ensure it always works.
>
> Moving the assignment of ->next_inactive_rotation inside of the
> loop makes it obvious to the reader and the compiler when we
> actually want to update ->next.
>
> Fixes: 3a08c2fd7634 ("bpf: LRU List")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks a lot, Arnd, patch was already sent here though:

http://patchwork.ozlabs.org/patch/695202/

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

end of thread, other threads:[~2016-11-16 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-16 14:38 [PATCH] bpf: fix possible uninitialized access in inactive rotation Arnd Bergmann
2016-11-16 16:00 ` Daniel Borkmann

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).