Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9118060pxu; Mon, 28 Dec 2020 07:05:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJymcRq6KEh6tb2NH+Haebjv56KxTdK2ANdfT/0dEDbsa9LG+PLqPTShuAtNmz22LBy+Pi7d X-Received: by 2002:a05:6402:14c5:: with SMTP id f5mr41977719edx.232.1609167942390; Mon, 28 Dec 2020 07:05:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609167942; cv=none; d=google.com; s=arc-20160816; b=Rbd7WPV6C9bxTHU2OR/yt5duUj0e6g213VisXO+iOUofO1SXUn6qR9Gbd7i8zC/O3n s+YDcC1JECvqMUuc26ohU9SGK/VDIM7IPQlY5Y7r4jeyZNm8wiN3ejvlpsuoVsC7SWTg UzdtGLewv0Dgt/d01alxG6uQwgqEtzMemXrH5OPpISk9U0n4F02It9Tsi3bBcFY1KqK0 jQJPb02yNGtcNI4UFfsYn8Y031LWQUMAEQY1LRQU9Xb/ZwVu8fwElz3Tea8IdwsJ4WYu fSciueXxJ7yH+fmhTRwNmTlb8AYKuW3gSIeZjYIIvI4epRREGdzrXO+BmluHiZawp36b pwnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Vy20uJErhd7VuzF0ERYw7vDsRjMVWl9Y4Dtfcw3/i9U=; b=B+8/pDLtbPu1fbaPVz4MaVM+UZdLXnI6ji23FsUZQRuLHOVYzlSLyVgkpsguF1uKfS 41XeiFIp0nU5K83S9Qsek2zBRjhPhANoBXSeXxlhzGM7c3F3xO/KVRk+FwqhOcdQobAV 0qLoaY/dEnExWDTa/dqeJgUdvJYjesBibCUI3anHwF9wxH1/wk0CogSfTanxy9gtetnN aYQ6vJBozsneJRWNAVs9f62Bh76sAQNEtrSASFKldpkzy3x6tB40ZDETa7j+8MRKy/Vq YKU45GwlrYsggAFycQ0KC7I/k8oZLDmRZbbkIeoaC0PZX5STj9pVengjgt8rQ6svvb44 17YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ob7TbgR6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v19si20474286edr.303.2020.12.28.07.05.19; Mon, 28 Dec 2020 07:05:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ob7TbgR6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439278AbgL1ONF (ORCPT + 99 others); Mon, 28 Dec 2020 09:13:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:46920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440025AbgL1ONB (ORCPT ); Mon, 28 Dec 2020 09:13:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7A87220715; Mon, 28 Dec 2020 14:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164766; bh=VKYEzj05SS6rPByeJj52FbVIsJdMuJydcCABRJBa/9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ob7TbgR6xBRatEGlk/mqC0rwLzAwK4RXYyfp7ZMTEFdsRjig7eMJM2MbAECzd+5b/ JKYcq86GQvfM5dai53EnJukAISugTxDlX8GKHXzTojAMDM5TD2n/NQhpOI32tcA4+3 PYWiWkkcJfu4Dbq18F6fkOZ5/koc4m0kRCWVwOkY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.10 291/717] libbpf: Sanitise map names before pinning Date: Mon, 28 Dec 2020 13:44:49 +0100 Message-Id: <20201228125034.976777519@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Toke Høiland-Jørgensen [ Upstream commit 9cf309c56f7910a81fbe053b6f11c3b1f0987b12 ] 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__pin_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 not rejected by the kernel") Signed-off-by: Toke Høiland-Jørgensen Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20201203093306.107676-1-toke@redhat.com Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 28baee7ba1ca8..ad165e6e74bc0 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -7649,6 +7649,16 @@ bool bpf_map__is_pinned(const struct bpf_map *map) return map->pinned; } +static void sanitize_pin_path(char *s) +{ + /* bpffs disallows periods in path names */ + while (*s) { + if (*s == '.') + *s = '_'; + s++; + } +} + int bpf_object__pin_maps(struct bpf_object *obj, const char *path) { struct bpf_map *map; @@ -7678,6 +7688,7 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path) err = -ENAMETOOLONG; goto err_unpin_maps; } + sanitize_pin_path(buf); pin_path = buf; } else if (!map->pin_path) { continue; @@ -7722,6 +7733,7 @@ int bpf_object__unpin_maps(struct bpf_object *obj, const char *path) return -EINVAL; else if (len >= PATH_MAX) return -ENAMETOOLONG; + sanitize_pin_path(buf); pin_path = buf; } else if (!map->pin_path) { continue; -- 2.27.0