Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3088859rwb; Mon, 15 Aug 2022 17:51:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR61WSapiygpsIMEq0ze/dXO+c0+nivz2/fSWjStW/Xxym3Tvd9cjarHVacAsL4C2uRIQHBn X-Received: by 2002:a17:907:8b97:b0:730:9480:972a with SMTP id tb23-20020a1709078b9700b007309480972amr12148509ejc.648.1660611084405; Mon, 15 Aug 2022 17:51:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611084; cv=none; d=google.com; s=arc-20160816; b=qaJrvdITUAjpq/+Ge0/QgzFVsAWznQO3GA5u3ktaE7ZPNkSzdJ1aDnm4/zazOcapzL xvwqHhp9T7C/bHubWpPpNiI+uwxmrnrcdtkiY3Ts9mF1pkZXQPsnJzbcMAbAMt90HFU/ eIh+PaQ4va6KCM+OQyazhjVqtuuvyT+FSgQ7ADS/uV/4LJ1pounFg0ELYJJBvBrED2b/ SATuYJHmca8KtZPIQl+5tNvI+VuAo1/Ifd2Xt334M9i1JlZqAqjreoA4BQgxQ9TELAwg EMSJfS4PUIUvKRQUt6IOm8qep13jBcXE9Q8Qx7e5wAcMu2kRF1ePOtGBmumWn3PiG1H/ vaGQ== 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=5CbYTpDil5u+cEneKGpDKANB/S3mHXMhuu91DDJSM1k=; b=KWQjM7NCB6xN8s/NRa9lJJAD733K2ENqNeHbFvQ2M9xthB0qDMwXrtfVPaFyIGwOIZ u+b2BwbII55M8fWV8i43fBjrIGGYtg5FBAW8uUDjk8aTgsb4t8ztfIIXpfDpA3KAROrc Nzc89c71QIIUhDhRxwFIRLFM4Lbb6/5B4piRSsuSSu6pGbL1FLrI2PbodRDsnoUF/hZT vwsLflWPyDAVveDPBdGZ7YR9kpToqk4bnLUfc3q93kl9KT/UVMwdnC1jfapaWtNM8zrF pJzzrEem49LLaldBIks0x29xaLauNwckrJzM4SbLm1PaZWd47S4V3ZR5b0rRjwgpecDW u2SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qU09QDDb; 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 g3-20020a1709065d0300b007317274bb0dsi9530997ejt.979.2022.08.15.17.50.58; Mon, 15 Aug 2022 17:51:24 -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=qU09QDDb; 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 S1356191AbiHPACF (ORCPT + 99 others); Mon, 15 Aug 2022 20:02:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356367AbiHOXyO (ORCPT ); Mon, 15 Aug 2022 19:54:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74FEA160130; Mon, 15 Aug 2022 13:19:04 -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 ED70AB80EA8; Mon, 15 Aug 2022 20:18:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 416B7C433D6; Mon, 15 Aug 2022 20:18:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594736; bh=JYVX+japmWo6QkvwKxE7PofA1DxPVMaWjvU8+Bwxme0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qU09QDDbLYGmQUi4Iy+KfhX6AXG42VplkeDb+0Q27bXqaF6OM3zBhrIOARQ9ws2Dv aVWunW9B0pErfXCnOJ+6+/FDO2rPFqEHPYKnGBUETdVgDKUEZeQh7VLJNjRwI0LQnL Uo/fleJv0Ov7+oIcv/uF4GuwAl0G6GKdFeIK860M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Martin KaFai Lau , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.19 0515/1157] libbpf: fix an snprintf() overflow check Date: Mon, 15 Aug 2022 19:57:51 +0200 Message-Id: <20220815180500.290138001@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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.1 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,T_SCC_BODY_TEXT_LINE 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: Dan Carpenter [ Upstream commit b77ffb30cfc5f58e957571d8541c6a7e3da19221 ] The snprintf() function returns the number of bytes it *would* have copied if there were enough space. So it can return > the sizeof(gen->attach_target). Fixes: 67234743736a ("libbpf: Generate loader program out of BPF ELF file.") Signed-off-by: Dan Carpenter Acked-by: Martin KaFai Lau Link: https://lore.kernel.org/r/YtZ+oAySqIhFl6/J@kili Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- tools/lib/bpf/gen_loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c index 927745b08014..23f5c46708f8 100644 --- a/tools/lib/bpf/gen_loader.c +++ b/tools/lib/bpf/gen_loader.c @@ -533,7 +533,7 @@ void bpf_gen__record_attach_target(struct bpf_gen *gen, const char *attach_name, gen->attach_kind = kind; ret = snprintf(gen->attach_target, sizeof(gen->attach_target), "%s%s", prefix, attach_name); - if (ret == sizeof(gen->attach_target)) + if (ret >= sizeof(gen->attach_target)) gen->error = -ENOSPC; } -- 2.35.1