Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2312791rdg; Sun, 15 Oct 2023 23:25:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3uI58Z9a42qi5VEDHpFyHQCSMFTsx+EIoN67x9Eroa9TdBqjipMcMWI9dnRe/NINEQI1J X-Received: by 2002:a17:902:690b:b0:1c9:c97b:ebad with SMTP id j11-20020a170902690b00b001c9c97bebadmr12965668plk.34.1697437515023; Sun, 15 Oct 2023 23:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697437515; cv=none; d=google.com; s=arc-20160816; b=ceoHDndPp+670YCfpyrGbZJxWtwWufLt8EqUFHKHQCIdqQpZnHMSR0lDfG5Fok6Avv zJjH4aXejlYFDsNFvZ4iPtYtUHoqssJWwZcKv+8WvfiZcWDbw6X3AUBiF1rHB1I7oFTC dg1wqDKYgRy8zwjXEZouYOzs+AwVV98Nfttg3CTWfn+KhjAbyM3rfaGEtTlFHqot5M6q 64fFPlOJPAoFptve+5PgLEIk25neyjELeDfXtjwtJzlYHBII0p+ZSc9jxQMwONVYvaIz PD9uTAJWTDeZ5Ox50TadyXZoAh8zlTm5uQGxl9oXow4mSFAk8di8XLGwfYRDvPYAuSyd ddXA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=tkbE/zeBrVksOr3Yb9lwOmx9HUe1o/qZhbY62d+Iguc=; fh=oqR8OJ5pTeldnOnecML6h2DgBgsEaLPXnPdCHTlEKWU=; b=WDZOWquyYg6ZPKDPPxhJwzhs0+wP3tauaMYibPFfWH85YXAqCrU9eh2v8KIpPu1ZSH alH6VNTgfEtM6ErsMLsKICZaQ7I6dE7gUkAuk4sYHj9qJsM3w3iILm3LssFnbaK7GP28 Q1TFkYCI5d1P4/H5rF/1Tvgp2InVLAQRgn4IlYAqqvoRlDSrdSOWrn6v6Th/wR5f6/NI s1EsGcjT9RMN8xypfQdfdGnzhSs9Naihe6sAtP1g45RTj8bDOP+GJxrPtbjVF8tfg+5g OFABI6WE9h3csVjG+QMWRXAd0Pts4Jp+u6ti8lOBLiz0Gai8x8FfAZIzSD/hSIAt2DZu mgzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="c/Sjd4nc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id f3-20020a17090274c300b001c9d7d70d7bsi9329865plt.4.2023.10.15.23.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="c/Sjd4nc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4E3EB805904D; Sun, 15 Oct 2023 23:25:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbjJPGYz (ORCPT + 99 others); Mon, 16 Oct 2023 02:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbjJPGYy (ORCPT ); Mon, 16 Oct 2023 02:24:54 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A054295; Sun, 15 Oct 2023 23:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697437492; x=1728973492; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=C5NvzvYf1xpiz/5DJdtYT8poj0czhsYWbhIHm4WHrhU=; b=c/Sjd4nc8EXuUUO6FyTpjPDB773AFlh5Ly+kDyKnhQzJz3dRSQHi/7BZ h6egQaToshFfNxkLIK/ihSzK0H9u1vAXnErrnaRFHjMVJkGZ6Ngwr6O4B yDiHTJJ2Bkn/hfYoOmXPxdRh4aD/fK6oLrKpd30EDFJDSAnEVy0hUE2DG UnGAnyP499F7XXfLJ8Sst9JRN0wZNCdShJMOHvIogfU4A5PXa4ZtKr/vC xJl4GHotDRX1ZuspAP0VkRpKxRFUhjpTr73VPJ5gKxT06uBzZiJuoqIQV 3W3Z7PBl7LGKssOJmqBqoMjnCU20AsBBh0I/csAfJSG8PnEZ7HIgNbD8T Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="449661213" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="449661213" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2023 23:24:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="871968974" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="871968974" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO binbinwu-mobl.sh.intel.com) ([10.238.1.136]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2023 23:24:49 -0700 From: Binbin Wu To: dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, shuah@kernel.org Cc: linux-kselftest@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, binbin.wu@linux.intel.com Subject: [PATCH v2] selftests/x86/lam: Zero out buffer for readlink() Date: Mon, 16 Oct 2023 14:24:46 +0800 Message-Id: <20231016062446.695-1-binbin.wu@linux.intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Sun, 15 Oct 2023 23:25:09 -0700 (PDT) Zero out the buffer for readlink() since readlink() does not append a terminating null byte to the buffer. Also change the buffer length passed to readlink() to 'PATH_MAX - 1' to ensure the resulting string is always null terminated. Fixes: 833c12ce0f430 ("selftests/x86/lam: Add inherit test cases for linear-address masking") Signed-off-by: Binbin Wu --- v1->v2: - Change the buffer length passed to readlink() to 'PATH_MAX - 1' to ensure the resulting string is always null terminated. [Kirill] tools/testing/selftests/x86/lam.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c index eb0e46905bf9..8f9b06d9ce03 100644 --- a/tools/testing/selftests/x86/lam.c +++ b/tools/testing/selftests/x86/lam.c @@ -573,7 +573,7 @@ int do_uring(unsigned long lam) char path[PATH_MAX] = {0}; /* get current process path */ - if (readlink("/proc/self/exe", path, PATH_MAX) <= 0) + if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0) return 1; int file_fd = open(path, O_RDONLY); @@ -680,14 +680,14 @@ static int handle_execve(struct testcases *test) perror("Fork failed."); ret = 1; } else if (pid == 0) { - char path[PATH_MAX]; + char path[PATH_MAX] = {0}; /* Set LAM mode in parent process */ if (set_lam(lam) != 0) return 1; /* Get current binary's path and the binary was run by execve */ - if (readlink("/proc/self/exe", path, PATH_MAX) <= 0) + if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0) exit(-1); /* run binary to get LAM mode and return to parent process */ base-commit: 58720809f52779dc0f08e53e54b014209d13eebb -- 2.25.1