Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3956695rdb; Mon, 11 Dec 2023 05:10:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMwYeNt81Y8SLpW2LJcWXcHPGlsxPill30ZmwuJcmGuRDngvFocbyNpO5xjNx2Ls834P33 X-Received: by 2002:a05:6a21:a5a9:b0:18b:9287:eab9 with SMTP id gd41-20020a056a21a5a900b0018b9287eab9mr2029622pzc.52.1702300245173; Mon, 11 Dec 2023 05:10:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702300245; cv=none; d=google.com; s=arc-20160816; b=ah+8xtz4svY5gXun228bYEHbeYXPo/txhZ3q3dGyGtP1EIufvZMwRx50uQmigKI+RO Gpp0yuwmhtWAhSCl5ujjh134847v5t4k0447gQpfOwIqF7Ca4uc4Riktstvd+XtlCYiq qXc9MNtQw64BORIyMLeJV4IyfPwQCdEVdhY7vsg3r8H+C53ax6WAvBrSrB/pXrXHi70w 2umZKq1edH8T1iVYuWNc98YOYXz/raTVOi0WWrFLQJtfPLcqxlDRi6GH8qSN0EdSNxaJ ZTuPkhtwqvO4k8St8hT+SRfu1T3RZBJAYX2o9bq/QeG0RG709LKY7oJNV23/9v56cRy1 OW2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=rbS+Fdl+z7UfBNfDczneI0LZN6FfAI7j/y6l2PPib+Q=; fh=tehJSzsaG8ClO1aGbe9U8FBoBMdSR/myAvjRIOO/gII=; b=SCFBHJeME6JGIYFScc+64X0rVu6wWrvX3bRVgvTPiLLmAvp6lDfTMk0Csx5+H8kM8a I3TUuan22MmckBx3j2hmiYGNH1QV1vGoY6CtTyZVIMpyslFKjrJz7wgPTJyvo6BPFetx LEzl4Wis0XegZNXL/SqYk+2PrUS4q5EUV++Z8ILJuct2FPWfgUtfza0ZsUgCCSVO9ygB elGaVR5rMniRw2HvyIbGBa5dpjmUMJMqlhu6Zt/9JksnatOxUEk1J+nYYZv/3uH6khUf 2GQuKh/0/Fqo27H6uU341YD3cUsCLbudL5XVlWeBZmweeV7RQApEspXyZoGjIXpTS2/H VfoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GnwrpM9N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id b2-20020a63eb42000000b005c278e32054si5893441pgk.677.2023.12.11.05.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 05:10:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GnwrpM9N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B7722807C5E9; Mon, 11 Dec 2023 05:10:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234927AbjLKNKO (ORCPT + 99 others); Mon, 11 Dec 2023 08:10:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234876AbjLKNKM (ORCPT ); Mon, 11 Dec 2023 08:10:12 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55907C3 for ; Mon, 11 Dec 2023 05:10:18 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C0A1C433C8; Mon, 11 Dec 2023 13:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702300218; bh=eN+xX6DmUW4iySUtNTiONSvtkTg9S6O6PBUBb147Eow=; h=From:Date:Subject:To:Cc:From; b=GnwrpM9N1KHskL0ItU5RfVm6tiiamVasCF5XI3q2oqOCYLQQsdeyEAELevJZReSEt 1sG0pLtmb6hXzqCxqVpevH375oT26qR6f++eQ/c01GrKzYh3BEVNWccCk1zNFvUJhP IxpUkrJVeSE6T0D3oQzsFsvCrVV7RV8ZlbP4+ZW98RHzaWTJTUg/gdN3z7JYXliwY8 Smi676PBEx5wEYAZZzsSVruBCi3LUf3SA0e0TPnqvKhsYiYp97YI1uAfW+ruJgP7dI XEfAPaQAmH3bbYofYJnmkvk7peaQ7oMlrwy7Ms1i3Et7FLBiMwWAzVeyWL09r9hZ0l ywHMyLdVPn6zw== From: Mark Brown Date: Mon, 11 Dec 2023 13:08:55 +0000 Subject: [PATCH RESEND v3] KVM: selftests: Initialise dynamically allocated configuration names MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20231211-kvm-get-reg-list-str-init-v3-1-6554c71c77b1@kernel.org> To: Paolo Bonzini , Shuah Khan , Haibo Xu , Andrew Jones , Anup Patel Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-5c066 X-Developer-Signature: v=1; a=openpgp-sha256; l=1754; i=broonie@kernel.org; h=from:subject:message-id; bh=eN+xX6DmUW4iySUtNTiONSvtkTg9S6O6PBUBb147Eow=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBldwo35IUcY6oNTJ2v6bW/nJJU3aNtV6hPHyuPoXmM jPdqsNCJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZXcKNwAKCRAk1otyXVSH0IF/B/ 0c7d7J486YSDJ+Oc8P2P4naqawpIeasFieXQgYjUPg9+qbMhD+8uicOI6zb+yfZu4r1g5Vln7DxbBT ZWGKK9OseW5cEGQwReDbJJxilNJ7IbG/mSdEhcPS/bd70N+504CuCHzw+Tk+F91kA1+hIniVchID9Z o2pz9kM6OAYVGfnChlqKblwrnBM+43eroWz+YGd3WCWVO92NrulsrbRR0NG+fzRXk/sdwJQwFNMRvl evQcp1xUfIrtBCI2uYrwmjE283O1pZA/rcZFbN55/JkWqO9F0eTgEeKaRSRqws4ckEn74L8C7Wbr4r 2+azED66yUak8FbJi2v6luHBgrNdlo X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 11 Dec 2023 05:10:42 -0800 (PST) When we dynamically generate a name for a configuration in get-reg-list we use strcat() to append to a buffer allocated using malloc() but we never initialise that buffer. Since malloc() offers no guarantees regarding the contents of the memory it returns this can lead to us corrupting, and likely overflowing, the buffer: vregs: PASS vregs+pmu: PASS sve: PASS sve+pmu: PASS vregs+pauth_address+pauth_generic: PASS X�vr+gspauth_addre+spauth_generi+pmu: PASS Initialise the buffer to an empty string to avoid this. Fixes: 2f9ace5d4557 ("KVM: arm64: selftests: get-reg-list: Introduce vcpu configs") Reviewed-by: Andrew Jones Signed-off-by: Mark Brown --- Changes in v3: - Rebase this bugfix onto v6.7-rc1 - Link to v2: https://lore.kernel.org/r/20231017-kvm-get-reg-list-str-init-v2-1-ee30b1df3e50@kernel.org Changes in v2: - Update Fixes: tag. - Link to v1: https://lore.kernel.org/r/20231013-kvm-get-reg-list-str-init-v1-1-034f370ff8ab@kernel.org --- tools/testing/selftests/kvm/get-reg-list.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c index be7bf5224434..dd62a6976c0d 100644 --- a/tools/testing/selftests/kvm/get-reg-list.c +++ b/tools/testing/selftests/kvm/get-reg-list.c @@ -67,6 +67,7 @@ static const char *config_name(struct vcpu_reg_list *c) c->name = malloc(len); + c->name[0] = '\0'; len = 0; for_each_sublist(c, s) { if (!strcmp(s->name, "base")) --- base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86 change-id: 20231012-kvm-get-reg-list-str-init-76c8ed4e19d6 Best regards, -- Mark Brown