Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2823484rwb; Mon, 15 Aug 2022 12:04:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR6ewFTthlmJsT2TIlN7sB21X0RiAN5fGMkq7SMBtKJUckrda7NisdWuJhMvNP5iSNsvlKxU X-Received: by 2002:a17:907:75d8:b0:730:8bf1:9a1 with SMTP id jl24-20020a17090775d800b007308bf109a1mr11160416ejc.604.1660590248218; Mon, 15 Aug 2022 12:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660590248; cv=none; d=google.com; s=arc-20160816; b=vS4iugJHeYPaNUb5oXOpWER0PQWmHuOZD68ynKNptH3ybiIEzROXbTUcNLsGXaPh+N Xj2exO0iEFCwFVT1+tKwN2fuWAolqcSIsdEKfD6P9CM9rDX4sOtso2LFITgbKofjvx2D hOkIW3oJUICsRvzJMGce0p43SzWM0bzM9k2PT6YsNwwdkPCR4FlnP2woE9IIYRw5DIR5 Fu1UP/h9ECB+873djgn1i8Prd94KTp5dtSiZvrt5n/c+SaEjwDCKyj3sTNIzt/EEX9dS upzmSCcDeKLxpwfdC8uwSJG1lbF9H1AL5OtuxfMDRdZ73mTR4X9xpaHXbx8QnR6UJBjl M0rA== 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=JimfNdJjWN6NjDvzOG6jUJzZavxP9LoA+eXY+hk7N9w=; b=UGTxNFgXda9L+H8KHM4XxoBOFWV2yBXD/LCBijzvF/zxY+/9GkvMd9f3PTIX+J4SxU 6aHjPMM1zUNh+ifPIV7Kv+lTH+H2GKux3xNSg7wJMjX2+naH1k/Wj5rCwwpgNluIaZjJ 95fvvijQ8hiuhv3us0a3YSFBFHHtT4XG3+GFOhRxcm90FlQAy0pKLnqp8yv9KuE/4l14 LD/rFmqoNamqjHcq/PMOtx2+bLl+rfXQFyt0WjKXhaxgW9ABrEXP1DXKBMDDN5yG4ihv yRxDh9b38rkvq5gFzeK5AzADJV+kLiXwUJvu68bk1oNPIJTHAzaLjOdPzHr2wNLPSFFf 73/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GYdx9mzH; 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 z7-20020a056402274700b0043d552deb37si8929102edd.14.2022.08.15.12.03.41; Mon, 15 Aug 2022 12:04:08 -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=GYdx9mzH; 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 S244926AbiHOS76 (ORCPT + 99 others); Mon, 15 Aug 2022 14:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245042AbiHOS4f (ORCPT ); Mon, 15 Aug 2022 14:56:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A5AA2C67B; Mon, 15 Aug 2022 11:31:16 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7104B61043; Mon, 15 Aug 2022 18:31:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 486C8C433D6; Mon, 15 Aug 2022 18:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588274; bh=Am9f5DX2cRApJL2HJEP4OQCjdiP3VXL6uJRI/RttOyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GYdx9mzHNIAUoDsEWQsOSzUKkY+eoUtqiiAoI5rbg+Z0ycUeWhOAr2cy2KeMmh4cT I25bLQkzQ4BZjSkgbDQvgz4Xbw730FZoEhwYLa/R16ScGb1muJ/bhxtPFOsOp/IsW1 rQciFrgNVX/o2KEZAAfIWRSI2dpKyovyy6VJgC/Q= 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.15 350/779] libbpf: fix an snprintf() overflow check Date: Mon, 15 Aug 2022 19:59:54 +0200 Message-Id: <20220815180352.200320192@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 33c19590ee43..4435c09fe132 100644 --- a/tools/lib/bpf/gen_loader.c +++ b/tools/lib/bpf/gen_loader.c @@ -480,7 +480,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