From patchwork Fri Jul 24 09:06:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 1335523 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=isovalent.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=isovalent-com.20150623.gappssmtp.com header.i=@isovalent-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=jZYU8ziU; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCjxZ699Kz9sRN for ; Fri, 24 Jul 2020 19:06:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727784AbgGXJGl (ORCPT ); Fri, 24 Jul 2020 05:06:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726801AbgGXJGk (ORCPT ); Fri, 24 Jul 2020 05:06:40 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BA99C0619D3 for ; Fri, 24 Jul 2020 02:06:40 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id y3so7608409wrl.4 for ; Fri, 24 Jul 2020 02:06:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GxnENee526BbPSGY0XIg65zijlPPPf1JtIkirCUkaeM=; b=jZYU8ziUDsm6BLSBzqtCVam8YZrRh70sG8YF1AnDFCuQORNHbvnOSD8Gj5IkMI3KWu 9rM1IfyqlbJ5Ae3dztZpC0SmHcn2vPrRIhJ3IzrBMt7qMAiZ+HPdKDqY/AP4odMKbV2o rnnqLmlGY7p3jsSaw8JtS9Wy6IYB3E7I3bkqCEOr0Owxrwa2SKg3GFzWjjsK3GCy7kdu QMZSRjseaHK3idSPGrSZLP7qI8/11vlMW2CH+CoA9Hu3XplpyZHIegqJ8Es0uEIV2NXO L+3xUDG8SnxmpIC44G/ujkacS8evrpLHo9Bkuo4eLxJzJPp0/5ac/65e9IqBrZi6HUC/ LaEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GxnENee526BbPSGY0XIg65zijlPPPf1JtIkirCUkaeM=; b=n3ukox5jNISE2aTVOuqhmrAMna/MvK81dC0Hq78yVbVkm72afB1PwHdZ2k3By6YlSo e4J+OrSdKMH24b8iutkt6GWgo47fJ3NIjK3+ELGzgbSQT4A4e2R+hXSgF/W6dIM+mfsY 0LXU1JC4pQidwfvjSkFCXvPGCHcrwCFMlJxEFpP2XpLS7t9lh02plVNj1OeMX+JzAvvW 3Mq/AQOmjdbiwQLTyetgmJRoMjG3Nr9pmWoGVrSjSMeWLoK6vQItXyGFlNBplE3Xi6MX d/xzgn8ttVGXc2sxuaQVCMA8JrMZADaHuNADHn5OGY+V+PmDQF2IV+MMy7rRNOkB2Nv7 gFhQ== X-Gm-Message-State: AOAM531x2UKsenx9tfRk0miJpY/XknmM6gfeRV3JCQbVHA0VxbkVTe6v jki6xizx4Wz1lY+HaI+klKNakQ== X-Google-Smtp-Source: ABdhPJykogI7r1ZL819tuTUD/yZ5fQo9cg9lTQkKWDytZ/lmue7R90FEXnSRtTQ2d50zVZ9zSlPF8w== X-Received: by 2002:adf:f248:: with SMTP id b8mr8132157wrp.247.1595581598896; Fri, 24 Jul 2020 02:06:38 -0700 (PDT) Received: from localhost.localdomain ([194.35.117.75]) by smtp.gmail.com with ESMTPSA id t11sm527915wrs.66.2020.07.24.02.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 02:06:38 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Paul Chaignon , Quentin Monnet Subject: [PATCH bpf-next 1/2] tools: bpftool: skip type probe if name is not found Date: Fri, 24 Jul 2020 10:06:17 +0100 Message-Id: <20200724090618.16378-2-quentin@isovalent.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200724090618.16378-1-quentin@isovalent.com> References: <20200724090618.16378-1-quentin@isovalent.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For probing program and map types, bpftool loops on type values and uses the relevant type name in prog_type_name[] or map_type_name[]. To ensure the name exists, we exit from the loop if we go over the size of the array. However, this is not enough in the case where the arrays have "holes" in them, program or map types for which they have no name, but not at the end of the list. This is currently the case for BPF_PROG_TYPE_LSM, not known to bpftool and which name is a null string. When probing for features, bpftool attempts to strlen() that name and segfaults. Let's fix it by skipping probes for "unknown" program and map types, with an informational message giving the numeral value in that case. Fixes: 93a3545d812a ("tools/bpftool: Add name mappings for SK_LOOKUP prog and attach type") Reported-by: Paul Chaignon Signed-off-by: Quentin Monnet Acked-by: Song Liu --- tools/bpf/bpftool/feature.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c index 1cd75807673e..a43a6f10b564 100644 --- a/tools/bpf/bpftool/feature.c +++ b/tools/bpf/bpftool/feature.c @@ -504,6 +504,10 @@ probe_prog_type(enum bpf_prog_type prog_type, bool *supported_types, supported_types[prog_type] |= res; + if (!prog_type_name[prog_type]) { + p_info("program type name not found (type %d)", prog_type); + return; + } maxlen = sizeof(plain_desc) - strlen(plain_comment) - 1; if (strlen(prog_type_name[prog_type]) > maxlen) { p_info("program type name too long"); @@ -533,6 +537,10 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix, * check required for unprivileged users */ + if (!map_type_name[map_type]) { + p_info("map type name not found (type %d)", map_type); + return; + } maxlen = sizeof(plain_desc) - strlen(plain_comment) - 1; if (strlen(map_type_name[map_type]) > maxlen) { p_info("map type name too long"); From patchwork Fri Jul 24 09:06:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 1335525 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=isovalent.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=isovalent-com.20150623.gappssmtp.com header.i=@isovalent-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=XMCJbv0C; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCjxb6v1Pz9sTC for ; Fri, 24 Jul 2020 19:06:43 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727819AbgGXJGm (ORCPT ); Fri, 24 Jul 2020 05:06:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726783AbgGXJGl (ORCPT ); Fri, 24 Jul 2020 05:06:41 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28A43C0619E5 for ; Fri, 24 Jul 2020 02:06:41 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id j18so7288505wmi.3 for ; Fri, 24 Jul 2020 02:06:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GKVJys15g3u/YKtwc9L0yZgVW6hScrCMx0azVfWiPc4=; b=XMCJbv0C6jPPPJ3GsMp/UwRxhK7HLwNcPU4KACk1wP03/BGWyKM0q49zlbosAajUoq Ezy/FhobjjtIopFsBZC/CRQEc65dFWakhxndATkLNhVunsX59FszzIsmoJjvvsMmEwJ2 m6K4QBTB4jrKAtaMqSE6wp02Yv4wXHwqFCpqH4iGAlwYuJBgnq/5oKu7HWt/6xU7p8mv e/h9ESAjb9Jbd2S36dOy7aY5f4iDsNcJAN2rcaiqaQLiIHUi/a6ZNWve7/lcvUwza1bY +G4DeWVWcPRUpEF9avCoLX73PHb+e3qcIBfEmFBwdwMk/Px4K7h5k91BRudkcOVFIBjt hMqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GKVJys15g3u/YKtwc9L0yZgVW6hScrCMx0azVfWiPc4=; b=ADe1UGoPJtWnGJgA1rocoBBtGYuxrpsPMJ3Q2vhoK9PS5ONYo9CiCi9ZlsIg830+HT izx3Cw3wyH9PgvKow9UH0sjRdfsqT2ETGAlHX7ZAo5soizS5pD2SwvHL6HHuV6W1dXdE LU9+aas+2rko5tUZMve0/k3ix5IbCOIqYGynphbnLB9kHpR9D5Xy3n5NKCqodM2ZOmih ni6Xq6AQL9wMhNVbyI0rMv6qIoK/7Jb5bG9lDfbnrivtMN3vZqeO/On5Msc2M+H+NbrF ccseGVTTlmg91C9TuWMyIU0g6ynzkJjAsJP9TESfjxH/9dub89rAgV9M4j0f1e6uxd+o LzwA== X-Gm-Message-State: AOAM530/+irwOT7P+J+GSnteR5okAOHqW9+g3elm5wJU4lrConFvqq+z VR/8i2TVfOskE5Hu7GB9izPqpr5EVDckPn5u X-Google-Smtp-Source: ABdhPJwzFR/1IwAyTe5ZwMTdZv3fdjYVZg12eQLNXCXJRylXdo1ZEPysLjeoxioWQp1AczKegZ0UQQ== X-Received: by 2002:a1c:3142:: with SMTP id x63mr7558652wmx.62.1595581599822; Fri, 24 Jul 2020 02:06:39 -0700 (PDT) Received: from localhost.localdomain ([194.35.117.75]) by smtp.gmail.com with ESMTPSA id t11sm527915wrs.66.2020.07.24.02.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 02:06:39 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Paul Chaignon , Quentin Monnet Subject: [PATCH bpf-next 2/2] tools: bpftool: add LSM type to array of prog names Date: Fri, 24 Jul 2020 10:06:18 +0100 Message-Id: <20200724090618.16378-3-quentin@isovalent.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200724090618.16378-1-quentin@isovalent.com> References: <20200724090618.16378-1-quentin@isovalent.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Assign "lsm" as a printed name for BPF_PROG_TYPE_LSM in bpftool, so that it can use it when listing programs loaded on the system or when probing features. Signed-off-by: Quentin Monnet Acked-by: Song Liu --- tools/bpf/bpftool/prog.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 3e6ecc6332e2..158995d853b0 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -59,6 +59,7 @@ const char * const prog_type_name[] = { [BPF_PROG_TYPE_TRACING] = "tracing", [BPF_PROG_TYPE_STRUCT_OPS] = "struct_ops", [BPF_PROG_TYPE_EXT] = "ext", + [BPF_PROG_TYPE_LSM] = "lsm", [BPF_PROG_TYPE_SK_LOOKUP] = "sk_lookup", };