Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933434AbcKPOi6 (ORCPT ); Wed, 16 Nov 2016 09:38:58 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:52017 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932385AbcKPOiz (ORCPT ); Wed, 16 Nov 2016 09:38:55 -0500 From: Arnd Bergmann To: Alexei Starovoitov Cc: Arnd Bergmann , Martin KaFai Lau , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] bpf: fix possible uninitialized access in inactive rotation Date: Wed, 16 Nov 2016 15:38:21 +0100 Message-Id: <20161116143836.2448688-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:6HF6zxp/X2JuFu9j9Z7LNTiel6G7fMdhLo5JTxRE44S/kfiBZmt BcTD3kmit8Scab6BtfEK7x7XGXwiaATfzoEMNTm+uB8Vwjd28lnypfF7FlmHPzGGSngZ0YJ j4KYoUIsUvewjwxi4ImQ6dvPVCXNqScf3Xl/f5Fz1kbXiCaGzAP4myHyCNa+zaBWpLp2FRU eMc1CcDuG7m6ssPB/p/Sw== X-UI-Out-Filterresults: notjunk:1;V01:K0:Vb0A6UCRKm4=:7I1oi//lUDKlekrF+64dH6 BvUSduMZ19VxG00uBtBmdJ5KWa6OUnq2QXboS2FrfU6QN8+RuStK0bDdMTmJ1gscaJWJNKdjK c3p2rAaSZV3RTvmRyzSH7LRnA6uZbR/LlXkWxRgf5E4ZJ9kdH8BqtKsXLoFzDpRDWdD95OaXP LltbB5tlo4RBKW40n92Qo+yvPs6JH6+yjL4m40xB9TLyArF4J64W3aAvfXsxDysOnGaSsnCf6 FUdSTc1N428V9LZBsbYaubbyaC5smjk3UHwo+IdE6Ejvp2jSvPXe4VDePA9D6rIgSTVA1/6JS Kd8rbVd6fgCgm/pPegB9kodJ072CBYJrtPqEYd8HjvGSJFaNhDyTqz/+FZAzJI2XiRpeh6wC2 KTDMwpbtjK4s4Zqan5LFmBmPqUzMI6Oz2HCev0Tf1eLxrLIDGKBIE5jY4KrPay77A7twlWmtf ynFWVslNrSxzqh8rYzG3pks/JQbvEPrZhNtSZeucQqXSA0Prvd9pkEVS/qTtjA6+ciGhNRIyv X9FcdprZ9QnJTFPBgBpzPXM7rRNSApdd/jsMCa5Fw+LXwsEB4WE3PDG9iF/ElqH1tXUHhnq0u ZE1ObDx47QDbO/QbAbuZ8dw2KDr1q7Nd6DgB8ZxBLkQjb+3nYQH6+kVGGDj28sNRKsbQgycad njDxMtN/KZm28VKGZ9vFnAXaROkxDr59J6JOcT0IH87QE83kuqUedajU8gJsLrZ9W2Nw= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1317 Lines: 41 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 --- 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