From patchwork Wed Nov 16 14:38:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101515 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp189105qge; Wed, 16 Nov 2016 06:39:08 -0800 (PST) X-Received: by 10.99.94.196 with SMTP id s187mr8918966pgb.107.1479307148024; Wed, 16 Nov 2016 06:39:08 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k13si15658410pgp.108.2016.11.16.06.39.07; Wed, 16 Nov 2016 06:39:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933438AbcKPOi6 (ORCPT + 26 others); 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 Received: from wuerfel.lan ([78.43.21.235]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0M0iAY-1cv7bo0tOY-00usGs; Wed, 16 Nov 2016 15:38:42 +0100 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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ence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.9.0 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