Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2306966rdb; Mon, 9 Oct 2023 22:46:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IET+PL/+KsI+Hv/BR6Hl8DXlx7y/ZxOJihGpROeDS17nOodQotrOvslphhO5F77ew2QjO55 X-Received: by 2002:a05:6830:157:b0:6b9:c5b5:6a96 with SMTP id j23-20020a056830015700b006b9c5b56a96mr16648360otp.6.1696916818594; Mon, 09 Oct 2023 22:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696916818; cv=none; d=google.com; s=arc-20160816; b=H4w8zdCw3iskvmr0RxJU3W+njHFn+Lz9hqA0SeOFwVfgNgQoD2yIdORXXVp9aczxXa KGWpbWbitsfWL4SQ9u1LLsKVE8SlRjOCn8L8dxSQc2zSfT/YpkoffUCz2woAcycMUyca gGaYiwDJtCwwclYwfXJ/osSUJydWcryT4xn6X+hfNC/NHiQzOveNAwDXS+qm6iIOgQ7a KDk6Yn/FR2BuKbYZWUiGcgZVwJPtDpFjEwtSMuSj12DSybuG8ljnS2xfJVS7ONEPZATT yFOH7aRT4lA/k/vdVZ2b5leiMo5FSLCcnaR/5n2b+W0l4YXXEjZY8in9aDt1gMQDH7sh weSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uT7Z0fIRFpYnqCgnquJICi+7pdJewmNIbRdipwsG6wE=; fh=N2UBR7OSoGI2pND7e2L/3kI9hFW/Gf/yVIVbKlSJM4Q=; b=Es12my2/kSSGGAk92+O9Tmg86hxxKluI4SBJv8kAuT2be9/hH+5C6xrqVe21M90jOA xFMNjySAWRMYLa80PhtiawU16u7QcSLoXS0SAdAuehfXOjopQTTPj8ITKL86xBSjCgqZ 1s5ZfhORET1Hm9/5OMIHlgeGMe51xvELKEeE/xlS8YDmTlhNxKOaNSKqF9QTuJBFWZnc 7mfTnxkyxv7r7hL712cLG1u2epwT2x9hW0+PvCb5hd+pYbQ8SopUv6HsEnuhoRHyBNeT Ukmg69NR03koVZGFIfdrD3Q1a9jLhKejC1hV/vQXcxw8T4ysdoME+L0Avjz0mtnCayVC Zf+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VROw0XHm; 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=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s198-20020a6377cf000000b0059c84b919adsi338962pgc.51.2023.10.09.22.46.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 22:46:58 -0700 (PDT) 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=@intel.com header.s=Intel header.b=VROw0XHm; 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=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 523828026446; Mon, 9 Oct 2023 22:46:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442138AbjJJFqp (ORCPT + 99 others); Tue, 10 Oct 2023 01:46:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442162AbjJJFql (ORCPT ); Tue, 10 Oct 2023 01:46:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23C6511A; Mon, 9 Oct 2023 22:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696916797; x=1728452797; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=ueFvf7JJaks5mJOm09moID6hWZ9bgKShkkmMs8XC9kA=; b=VROw0XHmop17NRiaefiA8M6kbbI7dvEEB08QWgNZJPNLvvAoOj1TmFJE U+7dAY3HQYSAhENS6EipftzB0XiQAe0fBLuZNxqB1nM57t02N62H91NTD b1/Z/a8HQa61Na7RTNYEns7IfUpWS8F1cdsAWUvZ1CLXSbpcsMyQyEGWx B4lhESJHkQHnwZF11M9Q5ZJSYc7h6DUdvOBr1An6BI0rV1fMESGqQkwfn VZGxpLkB6QVBa7pCWwxzLl0O3ozk469eRQJ8xHdU91x3WX3ausavh19qJ rNTcJyYtBgW70Lzh6tnsywNccn223oeQpOm86Rtl/x3q81aVVy3OwiQgf g==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="381574063" X-IronPort-AV: E=Sophos;i="6.03,211,1694761200"; d="scan'208";a="381574063" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 22:46:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="843990705" X-IronPort-AV: E=Sophos;i="6.03,211,1694761200"; d="scan'208";a="843990705" Received: from geigerri-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.41.165]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2023 22:46:34 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id A273310A196; Tue, 10 Oct 2023 08:46:31 +0300 (+03) Date: Tue, 10 Oct 2023 08:46:31 +0300 From: kirill.shutemov@linux.intel.com To: Binbin Wu Cc: dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, weihong.zhang@intel.com Subject: Re: [PATCH] selftests/x86/lam: Zero out buffer for readlink() Message-ID: <20231010054631.kud3zvv57je2buad@box.shutemov.name> References: <20230923233346.12726-1-binbin.wu@linux.intel.com> <20230927110219.b5n3fbbwrxtcwtzp@box.shutemov.name> <1793b780-cd15-b6a3-f951-c19a14a1310c@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1793b780-cd15-b6a3-f951-c19a14a1310c@linux.intel.com> X-Spam-Status: No, score=2.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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, 09 Oct 2023 22:46:56 -0700 (PDT) X-Spam-Level: ** On Tue, Oct 10, 2023 at 11:51:32AM +0800, Binbin Wu wrote: > > > On 9/27/2023 7:02 PM, kirill.shutemov@linux.intel.com wrote: > > On Sun, Sep 24, 2023 at 07:33:46AM +0800, Binbin Wu wrote: > > > Zero out the buffer for readlink() since readlink() does not append a > > > terminating null byte to the buffer. > > > > > > Fixes: 833c12ce0f430 ("selftests/x86/lam: Add inherit test cases for linear-address masking") > > > > > > Signed-off-by: Binbin Wu > > > --- > > > tools/testing/selftests/x86/lam.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c > > > index eb0e46905bf9..9f06942a8e25 100644 > > > --- a/tools/testing/selftests/x86/lam.c > > > +++ b/tools/testing/selftests/x86/lam.c > > > @@ -680,7 +680,7 @@ 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}; > > Shouldn't it be PATH_MAX+1 to handle the case when readlink(2) stores > > exactly PATH_MAX bytes into the buffer? > According to the definition of PATH_MAX in include/uapi/linux/limits.h > #define PATH_MAX??????? 4096??? /* # chars in a path name including nul */ > > IIUC, Linux limits the path length to 4095 and PATH_MAX includes the > terminating nul. Consider the case when kernel bump PATH_MAX to 8192. The binary that compiled from lam.c against the older kernel headers will get compromised. Increase the size of the buffer by one or pass PATH_MAX - 1 as buffer size to readlink(2). -- Kiryl Shutsemau / Kirill A. Shutemov