Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3081426rwb; Mon, 15 Aug 2022 17:40:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR7FewMky6JSSrKXT2U3c+ymR9sWM51a2BuRZ4bekIF2/VfKoPppXvJ/PSoQD74FKJuMGLIP X-Received: by 2002:aa7:dac4:0:b0:443:2ad7:717f with SMTP id x4-20020aa7dac4000000b004432ad7717fmr16873281eds.182.1660610407439; Mon, 15 Aug 2022 17:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610407; cv=none; d=google.com; s=arc-20160816; b=P7lnyAS0NfBHDOl6gV6gEJTy5QsI2HuNpnCYYDW2aFbZCUt5dQwg3lm8zYgfyF/TcV HI1jYcUlrFW2qh8GmNcT2zOcwnWRougKgofldKkpApBHk+rF4PMdznXSqrl2DDRpGQQJ UKnGJ8aVa2vtPRK6KPWmENeMSHuGNxuBbXhsIvNGQ9TeR2BtB2TVN+9j//2jg8tsM+vJ ACvqr6m69rmnUUdUNLywIFh7y5FqbkgVpoyO83n48y3z2Lf8qYqiiszprzgLidFhkPkW 6Y6ZDzfxQ4JL9fqJtEx+zVGhL+SwEzQ1aa5fzZCSIosyduOaiAxb+fHH0igvNr56YA1z 7Xbg== 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=Bg1vHHgb7AjItOgwS9dRomzqpehUhhxdsrMxW+Y0kDg=; b=bw1zP7gD/5YRNFaxhgOkw3d4W99YbGuWdLIahRwV150/KxJZw91MRi9A+skd91STr+ QKX8/FcouIDA0T4rpfd2QPO6jUZKE4jC34BcyPCHdFOJA/C1JxqVeymb5dUDvnPFJuab zyn1q4YG/llLKCFFO4JMswzCpME9NK9PPiUDelMcoPxpKKuE+A0U2eEJZ8lOys9xADP9 AxEhIF1OEOkLvZTwZH/YsPaqxu/1zd6+W9NWn6a6FwxY87fGbbpuNxuhtkc5rPUPqeVp Lc3lj3NmjlBwafjh3aTS+lT77lFS9y27UgCGP8wGx4pkcTfPVMiLMRBHqKQDkuZwm3jR vz3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vQFdJBX8; 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 u11-20020a50a40b000000b004408bac1e2fsi8678229edb.370.2022.08.15.17.39.42; Mon, 15 Aug 2022 17:40:07 -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=vQFdJBX8; 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 S1355688AbiHPABL (ORCPT + 99 others); Mon, 15 Aug 2022 20:01:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356021AbiHOXxc (ORCPT ); Mon, 15 Aug 2022 19:53:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44BCC15D884; Mon, 15 Aug 2022 13:18:24 -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 F345560FA3; Mon, 15 Aug 2022 20:18:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03BE1C433C1; Mon, 15 Aug 2022 20:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594702; bh=+WsUujaUX16uNZwXOFPHPQA32H5LpTszdrEHVfVb+Uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vQFdJBX81g9UjlGlIsovc3Td8C8XD7u9zWMSDbGKC4gAVl7CWmyjSWf1ooBFXOv6V mRlQPz+B6Yp+Ic/JNI9n3zbhfuKsatvqWw4rplE7IJ0P1mikxP5iRNYqgQYdZao2Oh H380IJzdUveSSte7aACq70SfRKkPzKiPKdnEJ2Tw= 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 0514/1157] selftests/bpf: fix a test for snprintf() overflow Date: Mon, 15 Aug 2022 19:57:50 +0200 Message-Id: <20220815180500.250630165@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 c5d22f4cfe8dfb93f1db0a1e7e2e7ebc41395d98 ] The snprintf() function returns the number of bytes which *would* have been copied if there were space. In other words, it can be > sizeof(pin_path). Fixes: c0fa1b6c3efc ("bpf: btf: Add BTF tests") Signed-off-by: Dan Carpenter Acked-by: Martin KaFai Lau Link: https://lore.kernel.org/r/YtZ+aD/tZMkgOUw+@kili Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- tools/testing/selftests/bpf/prog_tests/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c index ba5bde53d418..5af690063af5 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf.c +++ b/tools/testing/selftests/bpf/prog_tests/btf.c @@ -5324,7 +5324,7 @@ static void do_test_pprint(int test_num) ret = snprintf(pin_path, sizeof(pin_path), "%s/%s", "/sys/fs/bpf", test->map_name); - if (CHECK(ret == sizeof(pin_path), "pin_path %s/%s is too long", + if (CHECK(ret >= sizeof(pin_path), "pin_path %s/%s is too long", "/sys/fs/bpf", test->map_name)) { err = -1; goto done; -- 2.35.1