Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp906934rwi; Wed, 19 Oct 2022 04:35:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7kpYPtKKK/4v4j0TAWjAmbFFo1m5gES9Y41oXf7E2SsNPGQwH97CllaX9vgk4NMGd+hElZ X-Received: by 2002:a05:6a00:10cf:b0:563:34ce:4138 with SMTP id d15-20020a056a0010cf00b0056334ce4138mr8322205pfu.6.1666179341594; Wed, 19 Oct 2022 04:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666179341; cv=none; d=google.com; s=arc-20160816; b=U8cUa30bOh2iddRrxLyx7WD+4fPMAlW6HacRCcmUUE7vx95qP7DBPYdDU1m332hNlG 4H1AxQ0/GS2ZQepuUFNElfFil9L5gLLt9ojNq1M4u/w50C0OZBmjG7Z5Fx6EAp6/y5qx 54CjR7KloWsieaOm25WasBqYw7m7dWtorJznD2XZF0r7hbYMQFoh/tDk1abBnR9GfRPH wIjoMRE7lkq1O2P+Mm7oYoE8I7tK5AyKN+ht++q6Oo3H+tLSmRNRBfp0FHiliNlwfiAV xvqGkNfNL8QMou7AikhZ6pu+MTO3IvFdai9sNisXh5brRcWhIiV84bUKUeCKpBqyyeVM k5ew== 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=bS7GMCwTOsRT8Iyvlthz16Lg0wMkLiPypLN2pT9/fqk=; b=DG3zJfKlBlANILh/Y58E6hGpJ7QwC7NbKgW9jUY1gBXK/5oCCZeggjeJ6NqFrohY26 xKAK3p+rwq/APiRm1/cOszVrt0Oswn3ZW1GG+hNgnupNL/H4J88eyO+t9im7qUiXcq80 RT9n1/mFd0+9t8KVMLSjjB7EdlyIoOtbNstrljEDHKJC4cXfrtdZPVmlNT6o6VIn2P76 MV1DHIzWKkPYrAJgMxKhQYRyMm5Yr7K0LcpwNdy9BCi3cGMzAj4eBFwWXCQcgTgx8dkK MpOHODIeCGq4l2JYtTgDaQVV/syYX+gSXlSqCSoMrKtGrtOhR9cH0CX0PBI0vAnhgEgi pYyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UBsqIuz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q19-20020a170903205300b001728fede5c1si16095054pla.174.2022.10.19.04.35.29; Wed, 19 Oct 2022 04:35:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UBsqIuz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234695AbiJSK4P (ORCPT + 99 others); Wed, 19 Oct 2022 06:56:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235179AbiJSKzX (ORCPT ); Wed, 19 Oct 2022 06:55:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A16EAA484F; Wed, 19 Oct 2022 03:27:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 53C7CB824A9; Wed, 19 Oct 2022 09:08:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B56FFC433D7; Wed, 19 Oct 2022 09:08:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170510; bh=x0O9W2XoIIMXYnl74aXnnkx0BzJcyvrdEjk6w1tkkfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UBsqIuz/S+dGbp4ftv400cXJWGnasiSE/L07hqYH0g75AivSoDVFkFK2pV8C38vXN c2PmswNTaajqcMhHCXranir98jFSqi06PhNRGZwbXgrKLlNH3k7/Mg1/d7hD8xfX6D QH883SClFr61EW4e7UcT4wvLqRiDI2xRRxR3wGbA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Quentin Monnet , Daniel Borkmann , Sasha Levin Subject: [PATCH 6.0 683/862] bpftool: Clear errno after libcaps checks Date: Wed, 19 Oct 2022 10:32:50 +0200 Message-Id: <20221019083320.160230685@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quentin Monnet [ Upstream commit cea558855c39b7f1f02ff50dcf701ca6596bc964 ] When bpftool is linked against libcap, the library runs a "constructor" function to compute the number of capabilities of the running kernel [0], at the beginning of the execution of the program. As part of this, it performs multiple calls to prctl(). Some of these may fail, and set errno to a non-zero value: # strace -e prctl ./bpftool version prctl(PR_CAPBSET_READ, CAP_MAC_OVERRIDE) = 1 prctl(PR_CAPBSET_READ, 0x30 /* CAP_??? */) = -1 EINVAL (Invalid argument) prctl(PR_CAPBSET_READ, CAP_CHECKPOINT_RESTORE) = 1 prctl(PR_CAPBSET_READ, 0x2c /* CAP_??? */) = -1 EINVAL (Invalid argument) prctl(PR_CAPBSET_READ, 0x2a /* CAP_??? */) = -1 EINVAL (Invalid argument) prctl(PR_CAPBSET_READ, 0x29 /* CAP_??? */) = -1 EINVAL (Invalid argument) ** fprintf added at the top of main(): we have errno == 1 ./bpftool v7.0.0 using libbpf v1.0 features: libbfd, libbpf_strict, skeletons +++ exited with 0 +++ This has been addressed in libcap 2.63 [1], but until this version is available everywhere, we can fix it on bpftool side. Let's clean errno at the beginning of the main() function, to make sure that these checks do not interfere with the batch mode, where we error out if errno is set after a bpftool command. [0] https://git.kernel.org/pub/scm/libs/libcap/libcap.git/tree/libcap/cap_alloc.c?h=libcap-2.65#n20 [1] https://git.kernel.org/pub/scm/libs/libcap/libcap.git/commit/?id=f25a1b7e69f7b33e6afb58b3e38f3450b7d2d9a0 Signed-off-by: Quentin Monnet Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20220815162205.45043-1-quentin@isovalent.com Signed-off-by: Sasha Levin --- tools/bpf/bpftool/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c index 451cefc2d0da..ccd7457f92bf 100644 --- a/tools/bpf/bpftool/main.c +++ b/tools/bpf/bpftool/main.c @@ -435,6 +435,16 @@ int main(int argc, char **argv) setlinebuf(stdout); +#ifdef USE_LIBCAP + /* Libcap < 2.63 hooks before main() to compute the number of + * capabilities of the running kernel, and doing so it calls prctl() + * which may fail and set errno to non-zero. + * Let's reset errno to make sure this does not interfere with the + * batch mode. + */ + errno = 0; +#endif + last_do_help = do_help; pretty_output = false; json_output = false; -- 2.35.1