From patchwork Fri Jan 24 09:30:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233329 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 137A3C32771 for ; Fri, 24 Jan 2020 09:33:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CDE0D214AF for ; Fri, 24 Jan 2020 09:33:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579858424; bh=9wS7KhT7C1kZdFrhvuZqSsUzl4Qrz0XEJzPEAAHIGcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=JbppluSOOAQL7vABOkP6+PO+uvFtqNc/42vMReI0w2moB2T1N9Cxh3XhJuNf1GSNk m4NkgIzTuIcc8sLcc++1kkc9tc93SOv2Nwn77mnZtplnPIM8/gOsjzrCGO14exEhu9 heBXb3aYFD/Xq/h8WhDFSwSmL+kgjT7Q2NFRGe/0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730614AbgAXJdn (ORCPT ); Fri, 24 Jan 2020 04:33:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:60188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730652AbgAXJdn (ORCPT ); Fri, 24 Jan 2020 04:33:43 -0500 Received: from localhost (unknown [145.15.244.15]) (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 60BEF214DB; Fri, 24 Jan 2020 09:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579858422; bh=9wS7KhT7C1kZdFrhvuZqSsUzl4Qrz0XEJzPEAAHIGcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XGtei1Jwly9LHyT29ojaKH31R5ViLEPiSOvYiIICB0fyGGMKEYlD7OQVeooLDA37u RoReaOxuJuJrP3P3SPx4tP73qgxxgbhYTVp+G+918vLSSFduGk9Dm5yIBhrsjcyfQc jkd7yOzZdfBTlwU1YABsTya6PRkfgAQA1xsFQ2Vo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrii Nakryiko , Daniel Borkmann Subject: [PATCH 5.4 006/102] libbpf: Make btf__resolve_size logic always check size error condition Date: Fri, 24 Jan 2020 10:30:07 +0100 Message-Id: <20200124092807.027215215@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124092806.004582306@linuxfoundation.org> References: <20200124092806.004582306@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: Andrii Nakryiko commit 994021a7e08477f7e51285920aac99fc967fae8a upstream. Perform size check always in btf__resolve_size. Makes the logic a bit more robust against corrupted BTF and silences LGTM/Coverity complaining about always true (size < 0) check. Fixes: 69eaab04c675 ("btf: extract BTF type size calculation") Signed-off-by: Andrii Nakryiko Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20191107020855.3834758-5-andriin@fb.com Signed-off-by: Greg Kroah-Hartman --- tools/lib/bpf/btf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -269,10 +269,9 @@ __s64 btf__resolve_size(const struct btf t = btf__type_by_id(btf, type_id); } +done: if (size < 0) return -EINVAL; - -done: if (nelems && size > UINT32_MAX / nelems) return -E2BIG;