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=ham 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 1C552C64E7B for ; Thu, 3 Dec 2020 09:34:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B80882222E for ; Thu, 3 Dec 2020 09:34:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728912AbgLCJe2 (ORCPT ); Thu, 3 Dec 2020 04:34:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21606 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726003AbgLCJe1 (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-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-J5v12RT3Ok66QlYB08BkyQ-1; Thu, 03 Dec 2020 04:32:58 -0500 X-MC-Unique: J5v12RT3Ok66QlYB08BkyQ-1 Received: by mail-ed1-f71.google.com with SMTP id ca7so710086edb.12 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=TFgMUZc4gma7yh3FuANMCVO1rOekSsSm599XzrHyoKNEWT/3kG8plfeZlYhH2nCnVC gdc8tkLNpo6uB4gst4BLkhO4qvRI9rztXY7rBC4+7bQ3z2E6+29RAf7VxQnShYm1vsta Iiak8PYDTgYph022z+bQIDTOrGvjC+HJ39hTj/DQHGnx2k+S4UDAczBwKOUuwsedU8Ax jBvMidDDVQzagne8PkK3C3gg+Dc2vWxy/XYWQ5b8g7Nv/fzhHmiKJubTtJau9C/3lZUu f5IyZDfHl7/GB4D6ZyFw97R4wq7Cbpw9UXxhKBQQsogEZ6v9oldQWxzAaOpQYDjCoxbn 1N+A== X-Gm-Message-State: AOAM532Q00nfndf/bL84ag9di7NzCrnjzvPSf4qELCRkhIN8H/qSLMni KITSnIFrkJvRDcSSsJ3zT4fAq4h4MyqLgQ/PxAF0lsGL+1IyPZKAIirhcIBCPNhhRUOYzDMIhWh WIdqsisLM/wVeAF1/ X-Received: by 2002:a50:fe0e:: with SMTP id f14mr2036854edt.159.1606987977597; 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: netdev@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