From patchwork Tue Sep 1 15:09:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 310458 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=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT 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 50158C433E6 for ; Tue, 1 Sep 2020 15:41:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14E61206EF for ; Tue, 1 Sep 2020 15:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974895; bh=Pmg5zpPQHWOI7VlqDaiWtBOVI0kxWHZXzElobBjI++k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KbpDJbkIYk0T8J7K0Oe9b7CzqjkMcsnF7O4tUBYlayKdtnLFiGTdb/MruTwYFh0c5 hNH7L9JI3prD/M0MnMz/wb2NiB3takfEL+FfldzT6mVT8NuPva8C57N2NNBP/n2BLk 2NwVUQvTYAi7Oo5NWHYRaqyGAlBoL9Z/ck9gGrag= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730570AbgIAPld (ORCPT ); Tue, 1 Sep 2020 11:41:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:53664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731302AbgIAPl2 (ORCPT ); Tue, 1 Sep 2020 11:41:28 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 910DF20767; Tue, 1 Sep 2020 15:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974888; bh=Pmg5zpPQHWOI7VlqDaiWtBOVI0kxWHZXzElobBjI++k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GxWs52P2fldWNiDGJD50mN+x+tdBZwM7VK+NDRjh+cjkq00f+JWbGcyKX3joj74gS 0rYnjdDpBpdbXXJLRBauX6I8fhwukt6npX848tOAEPzemOqwCOzGG/54TG1TwDRbAk DdTlfZpf6INpW+98ks2eRU9t0zXyalq1nNDXaSNY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Daniel Borkmann , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.8 129/255] libbpf: Prevent overriding errno when logging errors Date: Tue, 1 Sep 2020 17:09:45 +0200 Message-Id: <20200901151006.898992433@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901151000.800754757@linuxfoundation.org> References: <20200901151000.800754757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Toke Høiland-Jørgensen [ Upstream commit 23ab656be263813acc3c20623757d3cd1496d9e1 ] Turns out there were a few more instances where libbpf didn't save the errno before writing an error message, causing errno to be overridden by the printf() return and the error disappearing if logging is enabled. Signed-off-by: Toke Høiland-Jørgensen Signed-off-by: Daniel Borkmann Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20200813142905.160381-1-toke@redhat.com Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index e7642a6e39f9e..e0b88f0013b74 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3319,10 +3319,11 @@ bpf_object__probe_global_data(struct bpf_object *obj) map = bpf_create_map_xattr(&map_attr); if (map < 0) { - cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); + ret = -errno; + cp = libbpf_strerror_r(ret, errmsg, sizeof(errmsg)); pr_warn("Error in %s():%s(%d). Couldn't create simple array map.\n", - __func__, cp, errno); - return -errno; + __func__, cp, -ret); + return ret; } insns[0].imm = map; @@ -5779,9 +5780,10 @@ int bpf_program__pin_instance(struct bpf_program *prog, const char *path, } if (bpf_obj_pin(prog->instances.fds[instance], path)) { - cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); + err = -errno; + cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg)); pr_warn("failed to pin program: %s\n", cp); - return -errno; + return err; } pr_debug("pinned program '%s'\n", path);