From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4726EC64E7B for ; Thu, 3 Dec 2020 09:34:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E33A122201 for ; Thu, 3 Dec 2020 09:34:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728631AbgLCJe1 (ORCPT ); Thu, 3 Dec 2020 04:34:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32900 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725902AbgLCJe1 (ORCPT ); Thu, 3 Dec 2020 04:34:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606987980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3g3F7gTrTi/QUstjrUVhaful3N8U/mgwbVT0uMHzDhk=; b=XIgUeesO6FDIRoGOb+b9kYi3oy3+dQOKHF/PHusG+W+ZpkXGakaBNxQB6qDbvOYd7Ex1bO z0pKGwT2pQwRLC9Z5ob3XO0Tmx97iFPBqqNMIETVuzqbKdp+gEt9yjan6kYF2OsEQLk9XC vwLrdRtbwm/8pHAGaX1lcViWvL0vcyY= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-531-kZUL8cUwNq6BJqwiBbV0vQ-1; Thu, 03 Dec 2020 04:32:58 -0500 X-MC-Unique: kZUL8cUwNq6BJqwiBbV0vQ-1 Received: by mail-ed1-f72.google.com with SMTP id i15so708860edx.9 for ; Thu, 03 Dec 2020 01:32:58 -0800 (PST) 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:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=3g3F7gTrTi/QUstjrUVhaful3N8U/mgwbVT0uMHzDhk=; b=FEe+ut9mX+KLRg5vTnMt/vKemWVD0iGrC8xBCZllHtz/PXd72ACHwJ8/kXrYRyQj0K ojA9w/OPDInGBAKXz2BTPyyD6QuKdqOmgMzLPIlGoyciQ3Xpm3BZhJMkwzurLp621t5R d7jejxfCDvS113mzw6m/JSOfrcB4AbB90pp+TyGYHV2dKumF4XnqvgwNkpP4n8WqbVaB hkEBepslfAVqX43Ow9vbtwfHJ8ah4HmsJvybjU9nrGYfLQf0OudZg8hhqqgaS0pFgY4u cWxSiiOHrQY7HoeP9COLJ0FX0sP5OXNvX+8aVGK/QiV7E7lu24j71D8mfe5ak+aBZmla hEDQ== X-Gm-Message-State: AOAM533gdtrA7adP6U/KwTt70pRvUxw5vXUNtFeQZa49ksUHqguAZ79A CQFQPALdidAbIAvyFM2tvADVq4oXVgY8nIEaEu2QDbgDbNKpCist4VNkEHtGJ12MWhjh7wFXbvd 1EsAf1PhTmu7l X-Received: by 2002:a50:fe0e:: with SMTP id f14mr2036858edt.159.1606987977604; Thu, 03 Dec 2020 01:32:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8NAeyfpWvwHI5TE/eb4HCz3kP5TktuDHgQGhhJ6zrGQP7iMtFZFqAaxVimJ4lX5FXsGHcgw== X-Received: by 2002:a50:fe0e:: with SMTP id f14mr2036847edt.159.1606987977425; Thu, 03 Dec 2020 01:32:57 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id 1sm402954ejt.107.2020.12.03.01.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 01:32:56 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 4652E181CF8; Thu, 3 Dec 2020 10:32:56 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Andrii Nakryiko Cc: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , bpf , Networking Subject: Re: [PATCH bpf v2] libbpf: sanitise map names before pinning In-Reply-To: References: <20201202111816.92279-1-toke@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Thu, 03 Dec 2020 10:32:56 +0100 Message-ID: <878safcjzr.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Andrii Nakryiko writes: > On Wed, Dec 2, 2020 at 3:19 AM Toke H=C3=B8iland-J=C3=B8rgensen wrote: >> >> When we added sanitising of map names before loading programs to libbpf,= we >> still allowed periods in the name. While the kernel will accept these for >> the map names themselves, they are not allowed in file names when pinning >> maps. This means that bpf_object__pin_maps() will fail if called on an >> object that contains internal maps (such as sections .rodata). >> >> Fix this by replacing periods with underscores when constructing map pin >> paths. This only affects the paths generated by libbpf when >> bpf_object__ping_maps() is called with a path argument. Any pin paths set >> by bpf_map__set_pin_path() are unaffected, and it will still be up to the >> caller to avoid invalid characters in those. >> >> Fixes: 113e6b7e15e2 ("libbpf: Sanitise internal map names so they are no= t rejected by the kernel") >> Signed-off-by: Toke H=C3=B8iland-J=C3=B8rgensen >> --- >> v2: >> - Move string munging to helper function >> >> tools/lib/bpf/libbpf.c | 18 ++++++++++++++++-- >> 1 file changed, 16 insertions(+), 2 deletions(-) >> >> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c >> index 8d05132e1945..08ff7783fb93 100644 >> --- a/tools/lib/bpf/libbpf.c >> +++ b/tools/lib/bpf/libbpf.c >> @@ -7651,6 +7651,20 @@ bool bpf_map__is_pinned(const struct bpf_map *map) >> return map->pinned; >> } >> >> +static char *sanitize_pin_path(char *str) > > don't want to be unnecessarily nitpicky, but the return of char * > suggests that this function might be allocating new string, so it's a > bit misleading. doing void function and having non-const char *str > feels most appropriate for this. Nice side-benefit: the implementation > will be even shorter :) Hmm, fair enough. I added the return because I figured it was convenient to fold the call into the assignment of pin_path, but I don't have a strong preference either way; will send a v3 :) -Toke