Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp661028imp; Thu, 21 Feb 2019 08:40:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IYLJ1J52mlKXYoyb6R/cOnuiMpIzrx0M5fIMwOqepWp5I97gFAUph5KJEYwLyOpB0CqNKZ/ X-Received: by 2002:a62:6702:: with SMTP id b2mr40611853pfc.244.1550767247544; Thu, 21 Feb 2019 08:40:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550767247; cv=none; d=google.com; s=arc-20160816; b=jUJzuz2aS5huEz4a4hoq957ADovknHIO19QVmcklKu7STgONWE/UHOxIWVOppPYELo EJsLKpMnY3q9SIpj0v26q6FuNJpRtBsmYRuqjurwvg6baDowUuiCU5Kda6PwsMZu51lG K9QywxDiTLXMm9V4UhNbd1NHAwxRGEwQ+AvdRIcHHwn6wk89Te8bb1u9cPJ9J4wz2YUk 8UCnnvGi5q+LuKykK7tqdZyl0XjOUZPTHCrdm33rLCHSRT3zCFfvhazmwDdwpyBDqg5Q PZ4UG8uG1W673/9WUsqzcFWHyg6Q8LkK2ZzCCQDBFRcBXIsZBtl2uQTFG9JprTMtgUm7 BX2Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=oUUaNAWEKXrWA7CoHeNhBNEez01JJHhKBXSilmyhjWs=; b=gHo9KkUjpcV6OLZAIbveipukHEVTRkwd5VxK2oPQWox85jCSZpltCg4Vz7Kle9DJp2 qZOm+FCwQ8z1xHMseONWnpbZuryRfTRcfagt3LQY8L3g7LiWPjNy7fyYKJAY4MivSboz eJ7COepNoZqDfR/OmfRBn1bzIV0DExKncLG5TMbh6W4igx5wmEDRTdZcueveKFthRZW3 +5I2K7YmpV+BqPKa3yLW5Q3JE17IWiApN1lec+LyzATAhcSqol+7jKDBpVA5kASUNHIG /S5veR0bBNyPgbdpjte9dV6JGfrHnXtHhTzhcZJZlXcTK34Qprt/SeZ44qdjYk23nFSg 4xUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=NO4fYVKx; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8si22893031plg.408.2019.02.21.08.40.30; Thu, 21 Feb 2019 08:40:47 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=NO4fYVKx; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726458AbfBUQkE (ORCPT + 99 others); Thu, 21 Feb 2019 11:40:04 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:44624 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725831AbfBUQkE (ORCPT ); Thu, 21 Feb 2019 11:40:04 -0500 Received: by mail-ed1-f65.google.com with SMTP id b20so23652129edw.11; Thu, 21 Feb 2019 08:40:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oUUaNAWEKXrWA7CoHeNhBNEez01JJHhKBXSilmyhjWs=; b=NO4fYVKxyeeUhgIoi8vqdB4NkFgwSomvUrr9AkFH/rXUB9MW9c1tHnFfqBG2ykiCrD KHnQ5GIlYM41O0CiFNDzNs136ffGIp3yekrFQoEygo6TtXjRzDx7RtgMkjj9nWTYM+rx yHK3GzxWFnp8MCvPinGF/JSIwSKFAYy5crqJQXDX85AWXwjnajxdTuOfelCst8gzKriO ESCHIftAB7H8N6lX4pVly32OunXeBCTdZ8Mpxm2zbH9V39m9KjhJ6tRsMjhTtHJWo16K kFyTJyWzvFKQO/cnXnUSz07pNJTEUVyYmeGlpgudhKz3qO5fAnw1B949lYophKxZiCcl 8avg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=oUUaNAWEKXrWA7CoHeNhBNEez01JJHhKBXSilmyhjWs=; b=eAytoVd3bJ9FTiBTY7A768WvfT4sA1SkkEOXPtPPIwmkBhSobjUGoF8To0sMAQ51Qz 04N1iY4STFygX9pMZCTE2Unv3YeifRHHfzDqLoHIaSc19yO9NgJwAIy/jdATa5V3nyVg i8Q+G1VqFd/rqa0ye53Ez0bAEz44qvsSun7tj5sKwqyKIsWOTjXTsUfCFi/p4d9UJyEP Ujj/CfoPYkSS9J6LQSmkVykA+nyJZ0ehXFIauU7Zx63J5iWBr/6eLYvBgZEk6pUqipOd cq9K2jMxzhloTS+r+ROrDnK/9bzn4AfOxUXhl0jFwxY6Wwia5YexVEq5Ex/Qt78AlMsy B0jA== X-Gm-Message-State: AHQUAub3Hxe0xirsbljD6tgRJGhhniCY5Ll2KEiOfuxqXyQNKdFRmVxg PDzvA1Q61dKYnaGkdEpI2emxt4MI0N4= X-Received: by 2002:a50:a978:: with SMTP id m53mr2558048edc.178.1550767202394; Thu, 21 Feb 2019 08:40:02 -0800 (PST) Received: from localhost.localdomain (ip5b402483.dynamic.kabel-deutschland.de. [91.64.36.131]) by smtp.gmail.com with ESMTPSA id b29sm4620061eda.48.2019.02.21.08.40.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Feb 2019 08:40:01 -0800 (PST) From: Alban Crequy X-Google-Original-From: Alban Crequy To: ast@kernel.org, daniel@iogearbox.net Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alban@kinvolk.io, iago@kinvolk.io Subject: [PATCH bpf-next v1] bpf, lpm: fix lookup bug in map_delete_elem Date: Thu, 21 Feb 2019 17:39:26 +0100 Message-Id: <20190221163926.15221-1-alban@kinvolk.io> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alban Crequy trie_delete_elem() was deleting an entry even though it was not matching if the prefixlen was correct. This patch adds a check on matchlen. Reproducer: $ sudo bpftool map create /sys/fs/bpf/mylpm type lpm_trie key 8 value 1 entries 128 name mylpm flags 1 $ sudo bpftool map update pinned /sys/fs/bpf/mylpm key hex 10 00 00 00 aa bb cc dd value hex 01 $ sudo bpftool map dump pinned /sys/fs/bpf/mylpm key: 10 00 00 00 aa bb cc dd value: 01 Found 1 element $ sudo bpftool map delete pinned /sys/fs/bpf/mylpm key hex 10 00 00 00 ff ff ff ff $ echo $? 0 $ sudo bpftool map dump pinned /sys/fs/bpf/mylpm Found 0 elements Signed-off-by: Alban Crequy --- kernel/bpf/lpm_trie.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c index abf1002080df..93a5cbbde421 100644 --- a/kernel/bpf/lpm_trie.c +++ b/kernel/bpf/lpm_trie.c @@ -471,6 +471,7 @@ static int trie_delete_elem(struct bpf_map *map, void *_key) } if (!node || node->prefixlen != key->prefixlen || + node->prefixlen != matchlen || (node->flags & LPM_TREE_NODE_FLAG_IM)) { ret = -ENOENT; goto out; -- 2.20.1