Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3016128rwb; Mon, 15 Aug 2022 16:12:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR5wP1frQGmjopvoTF2HXCa2+EP/Gx38Z5PLQ/Q63pKOWInw1FrcodX0ipjUJ/rE2G8BSv2L X-Received: by 2002:aa7:da4b:0:b0:43d:cc2e:c097 with SMTP id w11-20020aa7da4b000000b0043dcc2ec097mr16508246eds.188.1660605147812; Mon, 15 Aug 2022 16:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605147; cv=none; d=google.com; s=arc-20160816; b=ItWVpVje4yOuxxjurZO0NZz5FidyuPw/PTE5O57e5u/U0sTR1VuSggmuPuj24h6rKE sfs9lUIBJBgYd5qJ5UE2/75+VR4y/A6N3JYnnZu3RA3BDJ+sFZ5OPnXH2mHa4CVmZkxX tuVbXsk9MGU3z+JsNgMAbgxUJKPG/w2ZFEw97VTXj2Q3jzGR/INOpsqQsaR+IDMaqAKD 07YOJtXKvSUDB15l3Z2SNOFgWF90hvK3g91BrEj4BODZxF7Q9LVjXtj9kFQq1CQj5eqY Wx+tRf+3iA/UOJ0VsQc29fDcvxFBzKIpemME8aRRRkkrjrQdpSIfb5vgR0q756S1GHfu h9xg== 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=BsonqrHwgR0C6/3jsxwDHrbjZUinbyvr6gD5lpMFk/0BuoDjQEQqPvh0DrjYjfdplQ zMYTpixxwW/Ce5ZKHUjzFo0sMq3SybVVEyczBK8IpmtjtBHisgBGXBz12eYI/JZf+48n 7irPSmWdDWi9zOu6wk0lQ49KoZ+qknX15eWMShfj4MmfY9L8pgkyw4iUrGrJSVR/0I01 HffdMhq4R2wuZU42ed49fbGThBsHveyNtRNqfqZGrPg9WvAGfnZ45Q3mtXZFVKUk/5ZV wJQB4lpfFyXGf9cDAagRgQAoYw9djVihpwdg835vIYW53mjwkcWfe6ykI6kKeYrIq+d0 RbkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UJSuEFBT; 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 ga33-20020a1709070c2100b00732f83eb741si9256713ejc.985.2022.08.15.16.12.02; Mon, 15 Aug 2022 16:12:27 -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=UJSuEFBT; 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 S243585AbiHOVSl (ORCPT + 99 others); Mon, 15 Aug 2022 17:18:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244573AbiHOVK4 (ORCPT ); Mon, 15 Aug 2022 17:10:56 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A575C558C9; Mon, 15 Aug 2022 12:19:03 -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 sin.source.kernel.org (Postfix) with ESMTPS id 957AACE12C4; Mon, 15 Aug 2022 19:19:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A3A9C433C1; Mon, 15 Aug 2022 19:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591139; bh=JYVX+japmWo6QkvwKxE7PofA1DxPVMaWjvU8+Bwxme0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UJSuEFBTdB5P5usijTlDveuaO+xuFxqfYKp7MpPwT3u9ZUxi2OmKApn5WOwgF66Fr RtvE47vLF+Ojr5i/lqq6TrJjQB2sWyPJJT0rG9HXdBEiIL3lbR2Rh4tLllkDeijGKP c7Qr/YRs/O5khJ1vtYri6NmnN9gW6lhAs3d/7Qqk= 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.18 0484/1095] libbpf: fix an snprintf() overflow check Date: Mon, 15 Aug 2022 19:58:03 +0200 Message-Id: <20220815180449.583538580@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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