Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp730134imm; Thu, 13 Sep 2018 06:57:42 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY4Sjk9Pi5bBjne8jTb+zNQHo57POyq9FON18kbZUsq4+R/TW2HSW7HoCiPl1i6mLL0sSgz X-Received: by 2002:a17:902:694a:: with SMTP id k10-v6mr7404303plt.166.1536847062854; Thu, 13 Sep 2018 06:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847062; cv=none; d=google.com; s=arc-20160816; b=ET3EwE+RmYNvo+SFfuCO08nysCK1UMc4GLnpqfSwCBDD/zEFKibhopdI8DYufsNrs9 MPqgbbAbZgqO5E7rkw2On+aE1vI0Z1DvrgntltnXi1w3zdXXcSh3sIRWUrB5ZU7E/xU7 M90ftRqakruvvy/zcHpplfbVehDKZTvYaDkOCsHfmOaCv3avMBEmtjQ17C/6KViwb66K kzUUUu8RsBsW0EBxQKJ2Ic18OdRDrLy64nAFRFKLRTycNi599r6SD5NUROMUeoSQiEzY IbYzRRlkA+vbhs24k//CI7LzoiDI3XeQMUqteqlB01PK2b8KA+W+z6CCHygD9fO9wMss uMHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=t5/XeXAX6Geb3576PhEKl8gLEe5ITlQ/J+tew3SIwRU=; b=VnFC0l2MHWWUeQiY8Qdb3PGNncOzoD70g91sbEPRjmMGKisb2BtZudIG/j8OhfZF8N 6bbcZYAvTKtbFMGmdu1R8//2yT/obHIvggTPGDDpguWyUvk8fFpp0Ab6NMXt6sQGLFAX WljO9E9BN0589wa/COrCyOPUxb8LbXsA1NDu4f/oR21WbP6XBZz7Y5NyHHoTVkCnd5SL RnP0nU9l3Mzu6zMPJrcShT/flAQdsI0ywTRIsv5GRAZn6OLlGRLGqv0TR+jA8DGWlOtN elGhOKeGtbGUC8SNdaPymuua9wv+AjwjzopR4qLpzqFow3drHJYFl2LTrc8skrWaUSnw VaNg== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10-v6si4138205pfe.41.2018.09.13.06.57.26; Thu, 13 Sep 2018 06:57:42 -0700 (PDT) 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 S1731454AbeIMTG7 (ORCPT + 99 others); Thu, 13 Sep 2018 15:06:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34362 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731192AbeIMTG7 (ORCPT ); Thu, 13 Sep 2018 15:06:59 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 167E1D0E; Thu, 13 Sep 2018 13:57:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexei Starovoitov , Yonghong Song , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.18 097/197] bpf: fix bpffs non-array map seq_show issue Date: Thu, 13 Sep 2018 15:30:46 +0200 Message-Id: <20180913131845.418454675@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yonghong Song [ Upstream commit dc1508a579e682a1e5f1ed0753390e0aa7c23a97 ] In function map_seq_next() of kernel/bpf/inode.c, the first key will be the "0" regardless of the map type. This works for array. But for hash type, if it happens key "0" is in the map, the bpffs map show will miss some items if the key "0" is not the first element of the first bucket. This patch fixed the issue by guaranteeing to get the first element, if the seq_show is just started, by passing NULL pointer key to map_get_next_key() callback. This way, no missing elements will occur for bpffs hash table show even if key "0" is in the map. Fixes: a26ca7c982cb5 ("bpf: btf: Add pretty print support to the basic arraymap") Acked-by: Alexei Starovoitov Signed-off-by: Yonghong Song Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/inode.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/kernel/bpf/inode.c +++ b/kernel/bpf/inode.c @@ -196,19 +196,21 @@ static void *map_seq_next(struct seq_fil { struct bpf_map *map = seq_file_to_map(m); void *key = map_iter(m)->key; + void *prev_key; if (map_iter(m)->done) return NULL; if (unlikely(v == SEQ_START_TOKEN)) - goto done; + prev_key = NULL; + else + prev_key = key; - if (map->ops->map_get_next_key(map, key, key)) { + if (map->ops->map_get_next_key(map, prev_key, key)) { map_iter(m)->done = true; return NULL; } -done: ++(*pos); return key; }